Skip to content

Commit 72de35a

Browse files
committed
Switch back to Squirrel installer
which it turns out is by far the lesser of two evils. * Auto-update works with a proxy * The update process is reasonably atomic & faster, rather than running the uninstaller then the installer, leaving you with a broken install if you shut down your machine at the wrong time * Gets the update URL the same way as on mac, rather than baking it into the app at build time from package.json. We don't want it in package.json because only our builds want our update URL.
1 parent 970a029 commit 72de35a

3 files changed

Lines changed: 50 additions & 47 deletions

File tree

‎electron/src/electron-main.js‎

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ See the License for the specific language governing permissions and
1717
limitations under the License.
1818
*/
1919

20-
const electron = require('electron');
20+
// Squirrel on windows starts the app with various flags
21+
// as hooks to tell us when we've been installed/uninstalled
22+
// etc.
23+
const check_squirrel_hooks = require('./squirrelhooks');
24+
if (check_squirrel_hooks()) return;
2125

22-
// Auto updater from the 'electron-auto-updater' package for NSIS
23-
// auto-update support (not the one that comes with electron).
24-
const autoUpdater = require('electron-auto-updater').autoUpdater;
26+
const electron = require('electron');
2527
const url = require('url');
2628

2729
const VectorMenu = require('./vectormenu');
@@ -43,7 +45,7 @@ const PERMITTED_URL_SCHEMES = [
4345
];
4446

4547
const UPDATE_POLL_INTERVAL_MS = 60 * 60 * 1000;
46-
const INITIAL_UPDATE_DELAY_MS = 5 * 1000;
48+
const INITIAL_UPDATE_DELAY_MS = 30 * 1000;
4749

4850
let mainWindow = null;
4951
let appQuitting = false;
@@ -88,47 +90,44 @@ function installUpdate() {
8890
// for some reason, quitAndInstall does not fire the
8991
// before-quit event, so we need to set the flag here.
9092
appQuitting = true;
91-
autoUpdater.quitAndInstall();
93+
electron.autoUpdater.quitAndInstall();
9294
}
9395

9496
function pollForUpdates() {
9597
try {
96-
autoUpdater.checkForUpdates();
98+
electron.autoUpdater.checkForUpdates();
9799
} catch (e) {
98100
console.log("Couldn't check for update", e);
99101
}
100102
}
101103

102-
function startAutoUpdate() {
103-
if (process.platform != 'darwin' && process.platform != 'win32') {
104-
return;
104+
function startAutoUpdate(update_base_url) {
105+
if (update_base_url.slice(-1) !== '/') {
106+
update_base_url = update_base_url + '/';
105107
}
106108
try {
107-
// Since writing, the electron auto update process has changed from being
108-
// completely different between platforms to being differently completely
109-
// different. On Mac, we set the feed URL here. On Windows, it uses a
110-
// yaml file bundled at build time from the 'publish' entry in the
111-
// package.json. There is no autoupdate for Linux: it's expected that
112-
// the distro will provide it.
109+
// For reasons best known to Squirrel, the way it checks for updates
110+
// is completely different between macOS and windows. On macOS, it
111+
// hits a URL that either gives it a 200 with some json or
112+
// 204 No Content. On windows it takes a base path and looks for
113+
// files under that path.
113114
if (process.platform == 'darwin') {
114-
const update_base_url = vectorConfig.update_base_url;
115-
if (!update_base_url) {
116-
console.log("No update_base_url: disabling auto-update");
117-
return;
118-
}
119-
if (update_base_url.slice(-1) !== '/') {
120-
update_base_url = update_url + '/';
121-
}
122-
const update_url = update_base_url + 'update/macos/tmp/';
123-
console.log("Starting auto update with URL: " + update_url);
124-
autoUpdater.setFeedURL(update_url);
115+
electron.autoUpdater.setFeedURL(update_base_url + 'macos/');
116+
} else if (process.platform == 'win32') {
117+
electron.autoUpdater.setFeedURL(update_base_url + 'win32/' + process.arch + '/');
125118
} else {
126-
console.log("Starting auto update with baked-in URL");
119+
// Squirrel / electron only supports auto-update on these two platforms.
120+
// I'm not even going to try to guess which feed style they'd use if they
121+
// implemented it on Linux, or if it would be different again.
122+
console.log("Auto update not supported on this platform");
127123
}
128124
// We check for updates ourselves rather than using 'updater' because we need to
129125
// do it in the main process (and we don't really need to check every 10 minutes:
130126
// every hour should be just fine for a desktop app)
131127
// However, we still let the main window listen for the update events.
128+
// We also wait a short time before checking for updates the first time because
129+
// of squirrel on windows and it taking a small amount of time to release a
130+
// lock file.
132131
setTimeout(pollForUpdates, INITIAL_UPDATE_DELAY_MS);
133132
setInterval(pollForUpdates, UPDATE_POLL_INTERVAL_MS);
134133
} catch (err) {
@@ -150,7 +149,12 @@ process.on('uncaughtException', function (error) {
150149
electron.ipcMain.on('install_update', installUpdate);
151150

152151
electron.app.on('ready', () => {
153-
startAutoUpdate();
152+
if (vectorConfig.update_base_url) {
153+
console.log("Starting auto update with base URL: " + vectorConfig.update_base_url);
154+
startAutoUpdate(vectorConfig.update_base_url);
155+
} else {
156+
console.log("No update_base_url is defined: auto update is disabled");
157+
}
154158

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

‎package.json‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
"browser-request": "^0.3.3",
5959
"classnames": "^2.1.2",
6060
"draft-js": "^0.8.1",
61-
"electron-auto-updater": "^0.6.2",
6261
"extract-text-webpack-plugin": "^0.9.1",
6362
"favico.js": "^0.3.10",
6463
"filesize": "^3.1.2",
@@ -137,13 +136,15 @@
137136
"files": [
138137
"electron/src/**",
139138
"electron/img/**",
140-
"node_modules/electron-auto-updater/**",
141139
"webapp/**",
142140
"package.json"
143141
],
144142
"linux": {
145143
"target": "deb",
146144
"maintainer": "support@riot.im"
145+
},
146+
"win": {
147+
"target": "squirrel"
147148
}
148149
},
149150
"directories": {

‎scripts/electron-package.sh‎

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,6 @@ if [ -n "$conffile" ]; then
8181
pushd "$builddir"
8282
fi
8383

84-
if [ "$update_base_url" != "null" ]; then
85-
# Inject a 'publish' configuration into the package.json. This is what
86-
# electron-builder needs for auto-update on windows but we don't want to
87-
# keep it in the package.json as we don't want everyone cloning the source
88-
# and building it for themselves to get our auto-update URL.
89-
update_url=$update_base_url/install/win32/
90-
jq '.build.publish.provider="generic"' package.json \
91-
| jq '.build.publish.url="$update_url"' \
92-
> package.json.tmp
93-
mv package.json.tmp package.json
94-
fi
95-
9684
npm install
9785
npm run build:electron
9886

@@ -113,15 +101,25 @@ vername=`python -c 'import yaml; import sys; print yaml.load(sys.stdin)["version
113101
mkdir -p "$pubdir/install/macos"
114102
cp $distdir/mac/*.dmg "$pubdir/install/macos/"
115103

116-
mkdir -p "$pubdir/install/win32/"
117-
cp $distdir/*.exe "$pubdir/install/win32/"
118-
cp $distdir/latest.yml "$pubdir/install/win32/"
104+
mkdir -p "$pubdir/install/win32/ia32/"
105+
cp $distdir/win-ia32/*.exe "$pubdir/install/win32/ia32/"
106+
107+
mkdir -p "$pubdir/install/win32/x64/"
108+
cp $distdir/win/*.exe "$pubdir/install/win32/x64/"
119109

120-
# Packages for auto-update on mac (Windows (NSIS) uses the installer exe)
110+
# Packages for auto-update
121111
mkdir -p "$pubdir/update/macos"
122112
cp $distdir/mac/*.zip "$pubdir/update/macos/"
123113
echo "$ver" > "$pubdir/update/macos/latest"
124114

115+
mkdir -p "$pubdir/update/win32/ia32/"
116+
cp $distdir/win-ia32/*.nupkg "$pubdir/update/win32/ia32/"
117+
cp $distdir/win-ia32/RELEASES "$pubdir/install/win32/ia32/"
118+
119+
mkdir -p "$pubdir/update/win32/x64/"
120+
cp $distdir/win/*.nupkg "$pubdir/update/win32/x64/"
121+
cp $distdir/win/RELEASES "$pubdir/update/win32x64ia32/"
122+
125123
# Move the debs to the main project dir's dist folder
126124
rm -r "$projdir/electron/dist" || true
127125
mkdir -p "$projdir/electron/dist"

0 commit comments

Comments
 (0)