2016-07-08 04:48:42 -08:00
|
|
|
const { autoUpdater } = require('electron');
|
2016-07-06 21:30:58 -08:00
|
|
|
const { version } = require('./package');
|
2016-07-08 04:48:42 -08:00
|
|
|
const notify = require('./notify');
|
2016-07-07 15:19:39 -08:00
|
|
|
const ms = require('ms');
|
2016-07-06 06:58:39 -08:00
|
|
|
|
2016-07-06 21:30:58 -08:00
|
|
|
const FEED_URL = 'https://hyperterm-updates.now.sh/update/osx';
|
2016-07-07 15:19:39 -08:00
|
|
|
let isInit = false;
|
2016-07-06 06:58:39 -08:00
|
|
|
|
2016-07-07 15:19:39 -08:00
|
|
|
function init () {
|
2016-07-06 06:58:39 -08:00
|
|
|
autoUpdater.on('error', (err, msg) => {
|
2016-07-08 04:48:42 -08:00
|
|
|
notify('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('5m'));
|
|
|
|
|
|
|
|
|
|
isInit = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = function (win) {
|
|
|
|
|
if (!isInit) init();
|
|
|
|
|
|
|
|
|
|
const { rpc } = win;
|
|
|
|
|
|
|
|
|
|
const onupdate = (ev, releaseNotes, releaseName) => {
|
2016-07-06 23:20:07 -08:00
|
|
|
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
|
|
|
};
|