check second instances

This commit is contained in:
SrGooglo 2024-01-25 00:38:28 +01:00
parent 8129dcd980
commit bf30b88510

View File

@ -159,13 +159,7 @@ class ElectronApp {
}
}
async initialize() {
const gotTheLock = app.requestSingleInstanceLock()
if (!gotTheLock) {
app.quit()
} else {
app.on("second-instance", (event, commandLine, workingDirectory) => {
handleOnSecondInstance = async (event, commandLine, workingDirectory) => {
event.preventDefault()
// Someone tried to run a second instance, we should focus our window.
@ -177,10 +171,21 @@ class ElectronApp {
this.win.focus()
}
console.log(`Second instance >`, commandLine)
const url = commandLine.pop()
this.handleURLProtocol(url)
})
await this.handleURLProtocol(url)
}
async initialize() {
// Set app user model id for windows
electronApp.setAppUserModelId("com.electron")
const gotTheLock = await app.requestSingleInstanceLock()
if (!gotTheLock) {
return app.quit()
}
for (const key in this.handlers) {
@ -191,10 +196,7 @@ class ElectronApp {
ipcMain.on(key, this.events[key])
}
await app.whenReady()
// Set app user model id for windows
electronApp.setAppUserModelId("com.electron")
app.on("second-instance", this.handleOnSecondInstance)
app.on("open-url", (event, url) => {
event.preventDefault()
@ -206,19 +208,19 @@ class ElectronApp {
optimizer.watchWindowShortcuts(window)
})
autoUpdater.on("update-available", (ev, info) => {
console.log(info)
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) {
this.createWindow()
}
})
autoUpdater.on("error", (ev, err) => {
console.error(err)
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit()
}
})
autoUpdater.on("update-downloaded", (ev, info) => {
console.log(info)
sendToRender("update-available", info)
})
await app.whenReady()
if (isDev) {
if (app.isDefaultProtocolClient(protocolRegistryNamespace)) {
@ -240,23 +242,25 @@ class ElectronApp {
}
}
autoUpdater.on("update-available", (ev, info) => {
console.log(info)
})
autoUpdater.on("error", (ev, err) => {
console.error(err)
})
autoUpdater.on("update-downloaded", (ev, info) => {
console.log(info)
sendToRender("update-available", info)
})
await GoogleDriveAPI.init()
await this.createWindow()
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) {
this.createWindow()
}
})
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit()
}
})
autoUpdater.checkForUpdates()
await autoUpdater.checkForUpdates()
}
}