From 2a625e25c7fca5c9321c4d87c1ff87fdaf6f2efa Mon Sep 17 00:00:00 2001 From: Sean Beyer Date: Thu, 31 Oct 2024 14:10:48 -0700 Subject: [PATCH 1/3] Move updater to trigger on app close --- main.js | 54 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/main.js b/main.js index c08874290270..70e6efc0f839 100644 --- a/main.js +++ b/main.js @@ -458,7 +458,33 @@ async function startApp() { workerWindow.on('closed', () => { session.defaultSession.flushStorageData(); - session.defaultSession.cookies.flushStore().then(() => app.quit()); + session.defaultSession.cookies.flushStore().then(() => { + // Run updater if update available + if ( + !process.argv.includes('--skip-update') && + (process.env.NODE_ENV === 'production' || process.env.SLOBS_FORCE_AUTO_UPDATE) + ) { + // Windows uses our custom update, Mac uses electron-updater + if (process.platform === 'win32') { + const updateInfo = { + baseUrl: 'https://slobs-cdn.streamlabs.com', + version: pjson.version, + exec: process.argv, + cwd: process.cwd(), + waitPids: [process.pid], + appDir: path.dirname(app.getPath('exe')), + tempDir: path.join(app.getPath('temp'), 'slobs-updater'), + cacheDir: app.getPath('userData'), + versionFileName: `${releaseChannel}.json`, + }; + bootstrap(updateInfo, startApp, app.exit); + } else { + new Updater(startApp, releaseChannel).run(); + } + } else { + app.quit(); + } + }); }); // Pre-initialize the child window @@ -620,31 +646,7 @@ ipcMain.on('protocolLinkReady', () => { }); app.on('ready', () => { - if ( - !process.argv.includes('--skip-update') && - (process.env.NODE_ENV === 'production' || process.env.SLOBS_FORCE_AUTO_UPDATE) - ) { - // Windows uses our custom update, Mac uses electron-updater - if (process.platform === 'win32') { - const updateInfo = { - baseUrl: 'https://slobs-cdn.streamlabs.com', - version: pjson.version, - exec: process.argv, - cwd: process.cwd(), - waitPids: [process.pid], - appDir: path.dirname(app.getPath('exe')), - tempDir: path.join(app.getPath('temp'), 'slobs-updater'), - cacheDir: app.getPath('userData'), - versionFileName: `${releaseChannel}.json`, - }; - - bootstrap(updateInfo, startApp, app.exit); - } else { - new Updater(startApp, releaseChannel).run(); - } - } else { - startApp(); - } + startApp(); }); ipcMain.on('openDevTools', () => { From b9073401f375fe8c7ea64827013dd5f33c5c56ac Mon Sep 17 00:00:00 2001 From: Sean Beyer Date: Fri, 1 Nov 2024 14:22:58 -0700 Subject: [PATCH 2/3] Remove deprecated windows UpdaterWindow --- updater/UpdaterWindow.vue | 59 --------------------------------------- updater/index.html | 12 -------- updater/ui.js | 15 ---------- 3 files changed, 86 deletions(-) delete mode 100644 updater/UpdaterWindow.vue delete mode 100644 updater/index.html delete mode 100644 updater/ui.js diff --git a/updater/UpdaterWindow.vue b/updater/UpdaterWindow.vue deleted file mode 100644 index 3153d96cbdd1..000000000000 --- a/updater/UpdaterWindow.vue +++ /dev/null @@ -1,59 +0,0 @@ - - - - - diff --git a/updater/index.html b/updater/index.html deleted file mode 100644 index 4086118f2f25..000000000000 --- a/updater/index.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - -
- - diff --git a/updater/ui.js b/updater/ui.js deleted file mode 100644 index be95e3997383..000000000000 --- a/updater/ui.js +++ /dev/null @@ -1,15 +0,0 @@ -// This is the entry point into the updater app - -import Vue from 'vue'; -import UpdaterWindow from './UpdaterWindow.vue'; - -document.addEventListener('DOMContentLoaded', () => { - - new Vue({ - el: '#app', - render: createEl => { - return createEl(UpdaterWindow); - } - }); - -}); From a8d5dc049338a1e5e38e5b8edee1060257a9e8d6 Mon Sep 17 00:00:00 2001 From: Sean Beyer Date: Tue, 5 Nov 2024 13:59:57 -0800 Subject: [PATCH 3/3] Add inputs to postpone update --- updater/mac/Updater.js | 24 ++++++++++++++++++++++- updater/mac/UpdaterWindow.vue | 37 +++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/updater/mac/Updater.js b/updater/mac/Updater.js index 56363bb880a5..297deb898742 100644 --- a/updater/mac/Updater.js +++ b/updater/mac/Updater.js @@ -2,6 +2,7 @@ // be required by the main electron process. const { autoUpdater } = require('electron-updater'); +const path = require('path'); const { app, BrowserWindow, ipcMain, dialog } = require('electron'); class Updater { @@ -13,6 +14,7 @@ class Updater { // good option either, since then closing the auto updater will // orphan the main process in the background. constructor(startApp, channel) { + autoUpdater.autoDownload = false; this.startApp = startApp; if (process.arch === 'arm64') { this.channel = 'arm64-' + channel; @@ -57,6 +59,13 @@ class Updater { this.browserWindow = this.initWindow(); this.updateState.version = info.version; this.updateState.percent = 0; + this.updateState.updating = false; + + if (info.releaseNotes === 'force-update') { + autoUpdater.downloadUpdate(); + this.updateState.updating = true; + } + this.pushState(); }); @@ -94,6 +103,19 @@ class Updater { ipcMain.on('autoUpdate-getState', () => { this.pushState(); }); + + ipcMain.on('autoUpdate-postpone', () => { + console.log('Updater: Update postponed'); + this.startApp(); + this.finished = true; + if (this.browserWindow) this.browserWindow.close(); + }); + + ipcMain.on('autoUpdate-confirm', () => { + console.log('Updater: Update beginning'); + this.updateState.updating = true; + autoUpdater.downloadUpdate(); + }); } initWindow() { @@ -116,7 +138,7 @@ class Updater { if (!this.finished) app.quit(); }); - browserWindow.loadURL('file://' + __dirname + '/index.html'); + browserWindow.loadURL(path.join('file://', __dirname, '/index.html')); return browserWindow; } diff --git a/updater/mac/UpdaterWindow.vue b/updater/mac/UpdaterWindow.vue index 97558ce010f9..c4701470e2fa 100644 --- a/updater/mac/UpdaterWindow.vue +++ b/updater/mac/UpdaterWindow.vue @@ -5,6 +5,11 @@ {{ message }} +
+ + +
+
{{ percentComplete }}% complete
@@ -37,6 +42,12 @@ export default { }, mounted() { ipcRenderer.on('autoUpdate-pushState', (event, data) => { + // New update available, return early to allow user agency + if (data.updating === false) { + this.message = `New version ${data.version} available. Update now?`; + return; + } + // Accepted download if (data.version) { this.message = `Downloading version ${data.version}`; } @@ -59,6 +70,12 @@ export default { remote.shell.openExternal('https://streamlabs.com/streamlabs-obs'); remote.app.quit(); }, + confirmUpdate() { + ipcRenderer.send('autoUpdate-confirm'); + }, + postponeUpdate() { + ipcRenderer.send('autoUpdate-postpone'); + }, }, }; @@ -110,4 +127,24 @@ export default { color: #eee; } } +.UpdaterWindow-actions { + display: flex; + width: 100%; + justify-content: space-around; + button { + border: 1px solid transparent; + margin: 0; + font-family: 'Roboto', sans-serif; + min-height: 32px; + line-height: 30px; + cursor: pointer; + background-color: #4f5e65; + padding-left: 8px; + padding-right: 8px; + &:hover { + color: #fff; + background-color: lighten(#4f5e65, 8%); + } + } +}