hyper/app/auto-updater.js
Leo Lamprecht 6b886afc36 Use a string for setting the update channel (#2127)
* Adjusted config option

* Accept new config value
2017-08-30 14:12:59 +02:00

65 lines
1.5 KiB
JavaScript

// Packages
const {autoUpdater} = require('electron');
const ms = require('ms');
// Utilities
const notify = require('./notify'); // eslint-disable-line no-unused-vars
const {version} = require('./package');
const {getConfig} = require('./config');
const {platform} = process;
let isInit = false;
function init() {
autoUpdater.on('error', (err, msg) => {
console.error('Error fetching updates', msg + ' (' + err.stack + ')');
});
const config = getConfig();
// Default to the "stable" update channel
let canaryUpdates = false;
// If defined in the config, switch to the "canary" channel
if (config.updateChannel && config.updateChannel === 'canary') {
canaryUpdates = true;
}
const updatePrefix = canaryUpdates ? 'releases-canary' : 'releases';
const feedURL = `https://${updatePrefix}.hyper.is/update/${platform}`;
autoUpdater.setFeedURL(`${feedURL}/${version}`);
setTimeout(() => {
autoUpdater.checkForUpdates();
}, ms('10s'));
setInterval(() => {
autoUpdater.checkForUpdates();
}, ms('30m'));
isInit = true;
}
module.exports = function (win) {
if (!isInit) {
init();
}
const {rpc} = win;
const onupdate = (ev, releaseNotes, releaseName) => {
rpc.emit('update available', {releaseNotes, releaseName});
};
autoUpdater.on('update-downloaded', onupdate);
rpc.once('quit and install', () => {
autoUpdater.quitAndInstall();
});
win.on('close', () => {
autoUpdater.removeListener('update-downloaded', onupdate);
});
};