diff --git a/electron/src/main/app.js b/electron/src/main/app.js index 8f8cc81..5ae3bc7 100644 --- a/electron/src/main/app.js +++ b/electron/src/main/app.js @@ -48,7 +48,7 @@ export default class App { discord = new Discord(this.mainWindow) protocol = new Protocol(this.mainWindow) - updater = new Updater(this.mainWindow) + updater = new Updater(this.mainWindow, this.webtorrentWindow) dialog = new Dialog(this.webtorrentWindow) constructor () { @@ -134,11 +134,17 @@ export default class App { this.webtorrentWindow.webContents.postMessage('torrentPath', store.get('torrentPath')) sender.postMessage('port', null, [port2]) }) + + ipcMain.on('quit-and-install', () => { + if (this.updater.hasUpdate) { + this.destroy(true) + } + }) } destroyed = false - async destroy () { + async destroy (forceRunAfter = false) { if (this.destroyed) return this.webtorrentWindow.webContents.postMessage('destroy', null) await new Promise(resolve => { @@ -146,6 +152,6 @@ export default class App { setTimeout(resolve, 5000).unref?.() }) this.destroyed = true - if (!this.updater.install()) app.quit() + if (!this.updater.install(forceRunAfter)) app.quit() } } diff --git a/electron/src/main/updater.js b/electron/src/main/updater.js index 23fa7b4..429672d 100644 --- a/electron/src/main/updater.js +++ b/electron/src/main/updater.js @@ -12,10 +12,15 @@ ipcMain.on('update', () => { autoUpdater.checkForUpdatesAndNotify() export default class Updater { hasUpdate = false + window + torrentWindow /** * @param {import('electron').BrowserWindow} window + * @param {import('electron').BrowserWindow} torrentWindow */ - constructor (window) { + constructor (window, torrentWindow) { + this.window = window + this.torrentWindow = torrentWindow autoUpdater.on('update-available', () => { window.webContents.send('update-available', true) }) @@ -23,17 +28,15 @@ export default class Updater { this.hasUpdate = true window.webContents.send('update-downloaded', true) }) - ipcMain.on('quit-and-install', () => { - if (this.hasUpdate) { - autoUpdater.quitAndInstall() - this.hasUpdate = false - } - }) } - install () { + install (forceRunAfter = false) { if (this.hasUpdate) { - autoUpdater.quitAndInstall() + setImmediate(() => { + this.window.close() + this.torrentWindow.close() + autoUpdater.quitAndInstall(true, forceRunAfter) + }) this.hasUpdate = false return true }