forked from 1000ch/whale
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.js
64 lines (50 loc) · 1.45 KB
/
update.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
'use strict';
const electron = require('electron');
const pkg = require('./package');
const autoUpdater = electron.autoUpdater;
module.exports.init = appMenu => {
if (process.platform !== 'darwin') {
return;
}
const items = appMenu.items[0].submenu.items;
const checkUpdate = items.find(menu => menu.id === 'check-update');
const applyUpdate = items.find(menu => menu.id === 'apply-update');
if (!checkUpdate || !applyUpdate) {
return;
}
autoUpdater.on('error', error => {
console.error(error);
checkUpdate.enabled = true;
applyUpdate.enabled = false;
});
autoUpdater.on('checking-for-update', () => {
console.log('checking-for-update');
checkUpdate.enabled = false;
applyUpdate.enabled = false;
});
autoUpdater.on('update-available', () => {
console.log('update-available');
});
autoUpdater.on('update-not-available', () => {
console.log('update-not-available');
checkUpdate.enabled = true;
});
autoUpdater.on('update-downloaded', () => {
console.log('update-downloaded');
checkUpdate.enabled = false;
applyUpdate.enabled = true;
});
autoUpdater.setFeedURL(`https://1000ch.github.io/whale/latest.json?v=v${pkg.version}`);
};
module.exports.checkUpdate = () => {
if (process.platform !== 'darwin') {
return;
}
autoUpdater.checkForUpdates();
};
module.exports.applyUpdate = () => {
if (process.platform !== 'darwin') {
return;
}
autoUpdater.quitAndInstall();
};