Switch to new auto-update & add linux build

* Remove squirrel hooks (the installing & uninstalling is now
   done by the, er, installer)
 * Switch to electron-auto-update
 * Shorten initial update delay because we no longer need to wait
   for squirrel to release a lock file
 * Change update URLs because windows is now one installer for
   both 32 & 64 bit.
 * Update electron-builder to 10 where NSIS is now the default
   target for Windows.
 * Add linux to the target list, building a deb.
 * Remove sqirrel-specific installation spinner
 * Remove redundant !**/*  from files
This commit is contained in:
David Baker 2016-12-01 11:35:26 +00:00
parent 4988f0603f
commit e3290c1117
4 changed files with 21 additions and 62 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

View file

@ -17,13 +17,11 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
// Squirrel on windows starts the app with various flags
// as hooks to tell us when we've been installed/uninstalled
// etc.
const check_squirrel_hooks = require('./squirrelhooks');
if (check_squirrel_hooks()) return;
const electron = require('electron');
// Auto updater from the 'electron-auto-updater' package for NSIS
// auto-update support (not the one that comes with electron).
const autoUpdater = require('electron-auto-updater').autoUpdater;
const url = require('url');
const VectorMenu = require('./vectormenu');
@ -45,7 +43,7 @@ const PERMITTED_URL_SCHEMES = [
];
const UPDATE_POLL_INTERVAL_MS = 60 * 60 * 1000;
const INITIAL_UPDATE_DELAY_MS = 30 * 1000;
const INITIAL_UPDATE_DELAY_MS = 5 * 1000;
let mainWindow = null;
let appQuitting = false;
@ -90,12 +88,12 @@ function installUpdate() {
// for some reason, quitAndInstall does not fire the
// before-quit event, so we need to set the flag here.
appQuitting = true;
electron.autoUpdater.quitAndInstall();
autoUpdater.quitAndInstall();
}
function pollForUpdates() {
try {
electron.autoUpdater.checkForUpdates();
autoUpdater.checkForUpdates();
} catch (e) {
console.log("Couldn't check for update", e);
}
@ -106,30 +104,19 @@ function startAutoUpdate(update_url) {
update_url = update_url + '/';
}
try {
// For reasons best known to Squirrel, the way it checks for updates
// is completely different between macOS and windows. On macOS, it
// hits a URL that either gives it a 200 with some json or
// 204 No Content. On windows it takes a base path and looks for
// files under that path.
// Since writing, the electron auto update process has changed from being
// completely different between platforms to being differently completely
// different. On Mac, we set the feed URL here. On Windows, it uses a
// yaml file bundled at build time from the 'publish' entry in the
// package.json. There is no autoupdate for Linux: it's expected that
// the distro will provide it.
if (process.platform == 'darwin') {
// macos only has 64 bit
electron.autoUpdater.setFeedURL(update_url + 'macos/');
} else if (process.platform == 'win32') {
// We split by 32/64 bit too: the builds are different and entirely separate
electron.autoUpdater.setFeedURL(update_url + 'win32/' + process.arch + '/');
} else {
// Squirrel / electron only supports auto-update on these two platforms.
// I'm not even going to try to guess which feed style they'd use if they
// implemented it on Linux, or if it would be different again.
console.log("Auto update not supported on this platform");
autoUpdater.setFeedURL(update_url + 'macos/');
}
// We check for updates ourselves rather than using 'updater' because we need to
// do it in the main process (and we don't really need to check every 10 minutes:
// every hour should be just fine for a desktop app)
// However, we still let the main window listen for the update events.
// We also wait a short time before checking for updates the first time because
// of squirrel on windows and it taking a small amount of time to release a
// lock file.
setTimeout(pollForUpdates, INITIAL_UPDATE_DELAY_MS);
setInterval(pollForUpdates, UPDATE_POLL_INTERVAL_MS);
} catch (err) {

View file

@ -1,30 +0,0 @@
const path = require('path');
const spawn = require('child_process').spawn;
const app = require('electron').app;
function run_update_exe(args, done) {
const updateExe = path.resolve(path.dirname(process.execPath), '..', 'Update.exe');
spawn(updateExe, args, {
detached: true
}).on('close', done);
};
function check_squirrel_hooks() {
if (process.platform != 'win32') return false;
const cmd = process.argv[1];
const target = path.basename(process.execPath);
if (cmd === '--squirrel-install' || cmd === '--squirrel-updated') {
run_update_exe(['--createShortcut=' + target + ''], app.quit);
return true;
} else if (cmd === '--squirrel-uninstall') {
run_update_exe(['--removeShortcut=' + target + ''], app.quit);
return true;
} else if (cmd === '--squirrel-obsolete') {
app.quit();
return true;
}
return false;
}
module.exports = check_squirrel_hooks;

View file

@ -35,7 +35,7 @@
"build:compile": "babel --source-maps -d lib src",
"build:bundle": "NODE_ENV=production webpack -p --progress",
"build:bundle:dev": "webpack --optimize-occurence-order --progress",
"build:electron": "rimraf electron/dist && npm run clean && npm run build && build -wm --ia32 --x64 && scripts/check-electron.sh",
"build:electron": "rimraf electron/dist && npm run clean && npm run build && build -wml --ia32 --x64 && scripts/check-electron.sh",
"build": "node scripts/babelcheck.js && npm run build:res && npm run build:config && npm run build:emojione && npm run build:css && npm run build:bundle",
"build:dev": "node scripts/babelcheck.js && npm run build:res && npm run build:config && npm run build:emojione && npm run build:css && npm run build:bundle:dev",
"dist": "scripts/package.sh",
@ -58,6 +58,7 @@
"browser-request": "^0.3.3",
"classnames": "^2.1.2",
"draft-js": "^0.8.1",
"electron-auto-updater": "^0.6.2",
"extract-text-webpack-plugin": "^0.9.1",
"favico.js": "^0.3.10",
"filesize": "^3.1.2",
@ -97,7 +98,7 @@
"catw": "^1.0.1",
"cpx": "^1.3.2",
"css-raw-loader": "^0.1.1",
"electron-builder": "^7.23.2",
"electron-builder": "^10.4.1",
"emojione": "^2.2.3",
"expect": "^1.16.0",
"fs-extra": "^0.30.0",
@ -134,14 +135,15 @@
"dereference": true,
"//files": "We bundle everything, so we only need to include webapp/",
"files": [
"!**/*",
"electron/src/**",
"electron/img/**",
"node_modules/electron-auto-updater/**",
"webapp/**",
"package.json"
],
"squirrelWindows": {
"iconUrl": "https://riot.im/favicon.ico"
"linux": {
"target": "deb",
"maintainer": "support@riot.im"
}
},
"directories": {