This repository was archived by the owner on Apr 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
50 lines (41 loc) · 1.25 KB
/
index.js
File metadata and controls
50 lines (41 loc) · 1.25 KB
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
const GhReleases = require('electron-gh-releases');
const { dialog, app, nativeImage } = require('electron');
const path = require('path');
const dialogOpts = {
type: 'info',
buttons: ['Restart', 'Later'],
title: 'Headset Update',
message: 'New Version is Available for Headset!',
detail: 'Restart the application to apply the updates.',
icon: nativeImage.createFromPath(path.join(__dirname, 'icon.png')),
};
class AutoUpdater {
constructor(options = {}) {
this.options = options;
this.updater = new GhReleases({
repo: 'headsetapp/headset-electron',
currentVersion: `v${app.getVersion()}`,
});
this.updater.on('update-downloaded', () => this.updateDownloaded());
this.checkForUpdates();
setInterval(() => {
this.checkForUpdates();
}, 3600000);
}
updateDownloaded() {
dialog.showMessageBox(dialogOpts, (response) => {
if (this.options.onBeforeQuit) this.options.onBeforeQuit();
// Restart the app and install the update
if (response === 0) this.updater.install();
});
}
checkForUpdates() {
this.updater.check((err, status) => {
if (!err && status) {
// Download the update
this.updater.download();
}
});
}
}
module.exports = AutoUpdater;