mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-12 20:18:41 -09:00
auto-updater: prevent memory leaks :D
This commit is contained in:
parent
6bba2c6ded
commit
c3f8e81a5c
1 changed files with 28 additions and 6 deletions
|
|
@ -1,9 +1,11 @@
|
||||||
const { autoUpdater, dialog } = require('electron');
|
const { autoUpdater, dialog } = require('electron');
|
||||||
const { version } = require('./package');
|
const { version } = require('./package');
|
||||||
|
const ms = require('ms');
|
||||||
|
|
||||||
const FEED_URL = 'https://hyperterm-updates.now.sh/update/osx';
|
const FEED_URL = 'https://hyperterm-updates.now.sh/update/osx';
|
||||||
|
let isInit = false;
|
||||||
|
|
||||||
module.exports = function AutoUpdater (rpc) {
|
function init () {
|
||||||
autoUpdater.on('error', (err, msg) => {
|
autoUpdater.on('error', (err, msg) => {
|
||||||
dialog.showMessageBox({
|
dialog.showMessageBox({
|
||||||
title: 'title',
|
title: 'title',
|
||||||
|
|
@ -14,13 +16,33 @@ module.exports = function AutoUpdater (rpc) {
|
||||||
|
|
||||||
autoUpdater.setFeedURL(`${FEED_URL}/${version}`);
|
autoUpdater.setFeedURL(`${FEED_URL}/${version}`);
|
||||||
|
|
||||||
autoUpdater.once('update-downloaded', (ev, releaseNotes, releaseName) => {
|
setTimeout(() => {
|
||||||
rpc.emit('update available', { releaseNotes, releaseName });
|
autoUpdater.checkForUpdates();
|
||||||
});
|
}, ms('10s'));
|
||||||
|
|
||||||
rpc.once('quit-and-install', () => {
|
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 });
|
||||||
|
};
|
||||||
|
|
||||||
|
autoUpdater.on('update-downloaded', onupdate);
|
||||||
|
|
||||||
|
rpc.once('quit and install', () => {
|
||||||
autoUpdater.quitAndInstall();
|
autoUpdater.quitAndInstall();
|
||||||
});
|
});
|
||||||
|
|
||||||
autoUpdater.checkForUpdates();
|
win.on('close', () => {
|
||||||
|
autoUpdater.removeListener('update-downloaded', onupdate);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue