Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow optional updates on macos #5207

Draft
wants to merge 3 commits into
base: staging
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 28 additions & 26 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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', () => {
Expand Down
59 changes: 0 additions & 59 deletions updater/UpdaterWindow.vue

This file was deleted.

12 changes: 0 additions & 12 deletions updater/index.html

This file was deleted.

24 changes: 23 additions & 1 deletion updater/mac/Updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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();
});

Expand Down Expand Up @@ -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() {
Expand All @@ -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;
}
Expand Down
37 changes: 37 additions & 0 deletions updater/mac/UpdaterWindow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
{{ message }}
</div>

<div class="UpdaterWindow-actions" v-if="/New version/.test(message)">
<button @click="confirmUpdate">Update</button>
<button @click="postponeUpdate">Postpone</button>
</div>

<div v-if="percentComplete !== null && !installing && !error">
<div class="UpdaterWindow-progressPercent">{{ percentComplete }}% complete</div>
<div class="UpdaterWindow-progressBarContainer">
Expand Down Expand Up @@ -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}`;
}
Expand All @@ -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');
},
},
};
</script>
Expand Down Expand Up @@ -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%);
}
}
}
</style>
15 changes: 0 additions & 15 deletions updater/ui.js

This file was deleted.

Loading