-
-
Notifications
You must be signed in to change notification settings - Fork 310
/
updates.js
131 lines (111 loc) · 3.43 KB
/
updates.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
const fs = require('fs');
const { app, dialog } = require('electron');
const { autoUpdater } = require('electron-updater');
const log = require("electron-log");
const server = 'https://hazel-server-gufzwmrois.now.sh';
const feed = `${server}/update/${process.platform}/${app.getVersion()}`;
const CHECK_UPDATE_INTERVAL = 1000 * 60 * 15; // every 15 mins
let updater;
let isSilentCheck = true;
autoUpdater.autoDownload = false;
autoUpdater.on('error', (error) => {
dialog.showErrorBox('Error: ', error == null ? 'unknown' : (error.stack || error).toString());
});
autoUpdater.on('update-available', () => {
dialog.showMessageBox({
type: 'info',
title: 'Found Updates',
message: 'Found updates, do you want update now?',
buttons: ['Sure', 'No']
}, (buttonIndex) => {
if (buttonIndex === 0) {
autoUpdater.downloadUpdate();
}
else {
if (updater) {
updater.enabled = true;
updater = null;
}
}
});
});
autoUpdater.on('update-not-available', () => {
if (!isSilentCheck) {
dialog.showMessageBox({
title: 'No Updates',
message: 'Current version is up-to-date.'
});
}
if (updater) {
updater.enabled = true;
updater = null;
}
});
autoUpdater.on('update-downloaded', () => {
dialog.showMessageBox({
title: 'Install Updates',
message: 'Updates downloaded, application will now exit to update.'
}, () => {
setImmediate(() => autoUpdater.quitAndInstall());
});
});
const setupAutoUpdates = () => {
// autoUpdater.setFeedURL(feed);
// setInterval(() => {
// autoUpdater.checkForUpdates();
// }, CHECK_UPDATE_INTERVAL);
// autoUpdater.on('update-downloaded', (event, releaseNotes, releaseName) => {
// const dialogOpts = {
// type: 'info',
// buttons: ['Restart', 'Later'],
// title: 'Application Update',
// message: process.platform === 'win32' ? releaseNotes : releaseName,
// detail: 'A new version has been downloaded. Restart the application to apply the updates.'
// };
// dialog.showMessageBox(dialogOpts, (response) => {
// if (response === 0) {
// autoUpdater.quitAndInstall();
// }
// });
// });
// autoUpdater.on('error', message => {
// console.error('There was a problem updating the application');
// console.error(message);
// });
log.transports.file.level = 'info';
autoUpdater.logger = log;
// autoUpdater.checkForUpdatesAndNotify();
autoUpdater.checkForUpdates();
};
// autoUpdater.on('update-downloaded', (event, releaseNotes, releaseName) => {
// const dialogOpts = {
// type: 'info',
// buttons: ['Restart', 'Later'],
// title: 'Install Updates',
// message: process.platform === 'win32' ? releaseNotes : releaseName,
// detail: 'A new version has been downloaded. Restart the application to apply the updates.'
// };
// dialog.showMessageBox(dialogOpts, (response) => {
// if (response === 0) {
// autoUpdater.quitAndInstall();
// }
// });
// });
const checkForUpdates = (menuItem) => {
if (
autoUpdater.app
&& autoUpdater.app.appUpdateConfigPath
&& !fs.existsSync(autoUpdater.app.appUpdateConfigPath)
) {
// Don't check for updates if update config is not found (auto-update via electron is not supported)
return;
}
updater = menuItem;
updater.enabled = false;
isSilentCheck = false;
autoUpdater.checkForUpdates();
};
module.exports = {
setupAutoUpdates,
checkForUpdates
};