hyper/app/auto-updater.js

51 lines
1.2 KiB
JavaScript
Raw Normal View History

const { autoUpdater } = require('electron');
2016-07-06 21:30:58 -08:00
const { version } = require('./package');
const notify = require('./notify'); // eslint-disable-line no-unused-vars
2016-07-07 15:19:39 -08:00
const ms = require('ms');
2016-07-06 06:58:39 -08:00
// accepted values: `osx`, `win32`
// https://nuts.gitbook.com/update-windows.html
const platform = 'darwin' === process.platform
? 'osx'
: process.platform;
const FEED_URL = `https://hyperterm-updates.now.sh/update/${platform}`;
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) => {
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('5m'));
isInit = true;
}
module.exports = function (win) {
if (!isInit) init();
const { rpc } = win;
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
};