-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathautoupdater.js
53 lines (47 loc) · 1.58 KB
/
autoupdater.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
const os = require('os');
const { app, autoUpdater, dialog } = require('electron');
const version = app.getVersion();
const platform = `${os.platform()}_${os.arch()}`;
const updaterFeedURL = `https://package-gui.herokuapp.com/update/${platform}/${version}`;
function appUpdater() {
autoUpdater.setFeedURL(updaterFeedURL);
autoUpdater.on('error', err => console.log(err));
autoUpdater.on('checking-for-update', () =>
console.log('checking-for-update')
);
autoUpdater.on('update-available', () => console.log('update-available'));
autoUpdater.on('update-not-available', () =>
console.log('update-not-available')
);
// Ask the user if update is available
autoUpdater.on('update-downloaded', (event, releaseNotes, releaseName) => {
let message = `${app.getName()} ${releaseName} is now available. It will be installed the next time you restart the application`;
if (releaseNotes) {
const splitNotes = releaseNotes.split(/[^\r]\n/);
message += '\n\nRelease notes:\n';
splitNotes.forEach(notes => {
message += `${notes}\n\n`;
});
}
// Ask user to update the app
dialog.showMessageBox(
{
type: 'question',
buttons: ['Install and Relaunch', 'Later'],
defaultId: 0,
message: `A new version of ${app.getName()} has been downloaded`,
detail: message
},
response => {
if (response === 0) {
setImmediate(() => autoUpdater.quitAndInstall());
}
}
);
});
// init for updates
autoUpdater.checkForUpdates();
}
exports = module.exports = {
appUpdater
};