mirror of
https://github.com/ragestudio/relic.git
synced 2025-06-09 10:34:18 +00:00
check second instances
This commit is contained in:
parent
8129dcd980
commit
bf30b88510
@ -159,28 +159,33 @@ class ElectronApp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleOnSecondInstance = async (event, commandLine, workingDirectory) => {
|
||||||
|
event.preventDefault()
|
||||||
|
|
||||||
|
// Someone tried to run a second instance, we should focus our window.
|
||||||
|
if (this.win) {
|
||||||
|
if (this.win.isMinimized()) {
|
||||||
|
this.win.restore()
|
||||||
|
}
|
||||||
|
|
||||||
|
this.win.focus()
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`Second instance >`, commandLine)
|
||||||
|
|
||||||
|
const url = commandLine.pop()
|
||||||
|
|
||||||
|
await this.handleURLProtocol(url)
|
||||||
|
}
|
||||||
|
|
||||||
async initialize() {
|
async initialize() {
|
||||||
const gotTheLock = app.requestSingleInstanceLock()
|
// Set app user model id for windows
|
||||||
|
electronApp.setAppUserModelId("com.electron")
|
||||||
|
|
||||||
|
const gotTheLock = await app.requestSingleInstanceLock()
|
||||||
|
|
||||||
if (!gotTheLock) {
|
if (!gotTheLock) {
|
||||||
app.quit()
|
return app.quit()
|
||||||
} else {
|
|
||||||
app.on("second-instance", (event, commandLine, workingDirectory) => {
|
|
||||||
event.preventDefault()
|
|
||||||
|
|
||||||
// Someone tried to run a second instance, we should focus our window.
|
|
||||||
if (this.win) {
|
|
||||||
if (this.win.isMinimized()) {
|
|
||||||
this.win.restore()
|
|
||||||
}
|
|
||||||
|
|
||||||
this.win.focus()
|
|
||||||
}
|
|
||||||
|
|
||||||
const url = commandLine.pop()
|
|
||||||
|
|
||||||
this.handleURLProtocol(url)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const key in this.handlers) {
|
for (const key in this.handlers) {
|
||||||
@ -190,11 +195,8 @@ class ElectronApp {
|
|||||||
for (const key in this.events) {
|
for (const key in this.events) {
|
||||||
ipcMain.on(key, this.events[key])
|
ipcMain.on(key, this.events[key])
|
||||||
}
|
}
|
||||||
|
|
||||||
await app.whenReady()
|
app.on("second-instance", this.handleOnSecondInstance)
|
||||||
|
|
||||||
// Set app user model id for windows
|
|
||||||
electronApp.setAppUserModelId("com.electron")
|
|
||||||
|
|
||||||
app.on("open-url", (event, url) => {
|
app.on("open-url", (event, url) => {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
@ -206,19 +208,19 @@ class ElectronApp {
|
|||||||
optimizer.watchWindowShortcuts(window)
|
optimizer.watchWindowShortcuts(window)
|
||||||
})
|
})
|
||||||
|
|
||||||
autoUpdater.on("update-available", (ev, info) => {
|
app.on("activate", () => {
|
||||||
console.log(info)
|
if (BrowserWindow.getAllWindows().length === 0) {
|
||||||
|
this.createWindow()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
autoUpdater.on("error", (ev, err) => {
|
app.on("window-all-closed", () => {
|
||||||
console.error(err)
|
if (process.platform !== "darwin") {
|
||||||
|
app.quit()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
autoUpdater.on("update-downloaded", (ev, info) => {
|
await app.whenReady()
|
||||||
console.log(info)
|
|
||||||
|
|
||||||
sendToRender("update-available", info)
|
|
||||||
})
|
|
||||||
|
|
||||||
if (isDev) {
|
if (isDev) {
|
||||||
if (app.isDefaultProtocolClient(protocolRegistryNamespace)) {
|
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 GoogleDriveAPI.init()
|
||||||
|
|
||||||
await this.createWindow()
|
await this.createWindow()
|
||||||
|
|
||||||
app.on("activate", () => {
|
await autoUpdater.checkForUpdates()
|
||||||
if (BrowserWindow.getAllWindows().length === 0) {
|
|
||||||
this.createWindow()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
app.on("window-all-closed", () => {
|
|
||||||
if (process.platform !== "darwin") {
|
|
||||||
app.quit()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
autoUpdater.checkForUpdates()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user