hyper/app/auto-updater.js

51 lines
1.1 KiB
JavaScript
Raw Normal View History

const {autoUpdater} = require('electron');
2016-07-07 15:19:39 -08:00
const ms = require('ms');
2016-07-06 06:58:39 -08:00
const notify = require('./notify'); // eslint-disable-line no-unused-vars
const {version} = require('./package');
2017-08-04 13:52:38 -08:00
const {platform} = process;
const FEED_URL = `https://releases.hyper.is/update/${platform}`;
2016-07-07 15:19:39 -08:00
let isInit = false;
2016-07-06 06:58:39 -08:00
function init() {
2016-07-06 06:58:39 -08:00
autoUpdater.on('error', (err, msg) => {
console.error('Error fetching updates', msg + ' (' + err.stack + ')');
2016-07-06 06:58:39 -08:00
});
autoUpdater.setFeedURL(`${FEED_URL}/${version}`);
2016-07-07 15:19:39 -08:00
setTimeout(() => {
autoUpdater.checkForUpdates();
}, ms('10s'));
setInterval(() => {
autoUpdater.checkForUpdates();
}, ms('30m'));
2016-07-07 15:19:39 -08:00
isInit = true;
}
module.exports = function (win) {
if (!isInit) {
init();
}
2016-07-07 15:19:39 -08:00
const {rpc} = win;
2016-07-07 15:19:39 -08:00
const onupdate = (ev, releaseNotes, releaseName) => {
rpc.emit('update available', {releaseNotes, releaseName});
2016-07-07 15:19:39 -08:00
};
2016-07-06 06:58:39 -08:00
2016-07-07 15:19:39 -08:00
autoUpdater.on('update-downloaded', onupdate);
rpc.once('quit and install', () => {
2016-07-06 06:58:39 -08:00
autoUpdater.quitAndInstall();
});
2016-07-07 15:19:39 -08:00
win.on('close', () => {
autoUpdater.removeListener('update-downloaded', onupdate);
});
2016-07-06 06:58:39 -08:00
};