Skip to content

Commit 84aac88

Browse files
committed
Make auto-update configureable
Otherwise everyone that builds electron vector will end up with their apps auto-updatin to our version when we release an update. Coming next: A way to manage our electron release process to make sure we never ship a build with auto-update disabled.
1 parent 0441fcf commit 84aac88

1 file changed

Lines changed: 38 additions & 15 deletions

File tree

‎electron/src/electron-main.js‎

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ const url = require('url');
2828

2929
const VectorMenu = require('./vectormenu');
3030

31+
let vectorConfig = {};
32+
try {
33+
vectorConfig = require('../../vector/config.json');
34+
} catch (e) {
35+
console.log(`file://${__dirname}/../../vector/config.json`, e);
36+
// it would be nice to check the error code here and bail if the config
37+
// is unparseable, but we get MODULE_NOT_FOUND in the case of a missing
38+
// file or invalid json, so node is just very unhelpful.
39+
// Continue with the defaults (ie. an empty config)
40+
}
41+
3142
const PERMITTED_URL_SCHEMES = [
3243
'http:',
3344
'https:',
@@ -91,29 +102,20 @@ function pollForUpdates() {
91102
}
92103
}
93104

94-
// handle uncaught errors otherwise it displays
95-
// stack traces in popup dialogs, which is terrible (which
96-
// it will do any time the auto update poke fails, and there's
97-
// no other way to catch this error).
98-
// Assuming we generally run from the console when developing,
99-
// this is far preferable.
100-
process.on('uncaughtException', function (error) {
101-
console.log("Unhandled exception", error);
102-
});
103-
104-
electron.ipcMain.on('install_update', installUpdate);
105-
106-
electron.app.on('ready', () => {
105+
function startAutoUpdate(update_url) {
106+
if (update_url.slice(-1) !== '/') {
107+
update_url = update_url + '/';
108+
}
107109
try {
108110
// For reasons best known to Squirrel, the way it checks for updates
109111
// is completely different between macOS and windows. On macOS, it
110112
// hits a URL that either gives it a 200 with some json or
111113
// 204 No Content. On windows it takes a base path and looks for
112114
// files under that path.
113115
if (process.platform == 'darwin') {
114-
electron.autoUpdater.setFeedURL("https://riot.im/autoupdate/desktop/");
116+
electron.autoUpdater.setFeedURL(update_url);
115117
} else if (process.platform == 'win32') {
116-
electron.autoUpdater.setFeedURL("https://riot.im/download/desktop/win32/");
118+
electron.autoUpdater.setFeedURL(update_url + 'win32/');
117119
} else {
118120
// Squirrel / electron only supports auto-update on these two platforms.
119121
// I'm not even going to try to guess which feed style they'd use if they
@@ -133,6 +135,27 @@ electron.app.on('ready', () => {
133135
// will fail if running in debug mode
134136
console.log("Couldn't enable update checking", err);
135137
}
138+
}
139+
140+
// handle uncaught errors otherwise it displays
141+
// stack traces in popup dialogs, which is terrible (which
142+
// it will do any time the auto update poke fails, and there's
143+
// no other way to catch this error).
144+
// Assuming we generally run from the console when developing,
145+
// this is far preferable.
146+
process.on('uncaughtException', function (error) {
147+
console.log("Unhandled exception", error);
148+
});
149+
150+
electron.ipcMain.on('install_update', installUpdate);
151+
152+
electron.app.on('ready', () => {
153+
if (vectorConfig.update_url) {
154+
console.log("Starting auto update with URL: " + vectorConfig.update_url);
155+
startAutoUpdate(vectorConfig.update_url);
156+
} else {
157+
console.log("No update_url is defined: auto update is disabled");
158+
}
136159

137160
mainWindow = new electron.BrowserWindow({
138161
icon: `${__dirname}/../img/riot.ico`,

0 commit comments

Comments
 (0)