-
Notifications
You must be signed in to change notification settings - Fork 107
/
Copy pathauto-update.ts
48 lines (42 loc) · 1.16 KB
/
auto-update.ts
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
import { dialog } from 'electron';
import { autoUpdater } from 'electron-updater';
import { join } from 'path';
import { isDev } from './utils';
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'],
})
.then((update) => {
if (update) {
autoUpdater.downloadUpdate();
}
});
});
autoUpdater.on('update-not-available', () => {
console.info('Current version is up to date');
});
autoUpdater.on('update-downloaded', () => {
dialog
.showMessageBox({
title: 'Install Updates',
message: 'Updates downloaded, application will be quit for update...',
})
.then(() => setImmediate(() => autoUpdater.quitAndInstall()));
});
export const checkForUpdates = (): void => {
if (isDev) {
autoUpdater.updateConfigPath = join(__dirname, 'dev-app-update.yml');
}
autoUpdater.checkForUpdates();
};