|
1 | 1 | // @flow |
2 | 2 | const { app, dialog } = require('electron'); |
3 | 3 | const { autoUpdater } = require('electron-updater'); |
4 | | -const log = require('electron-log'); |
5 | 4 |
|
6 | | -// Setup logger |
7 | | -autoUpdater.logger = log; |
8 | | -autoUpdater.logger.transports.file.level = 'info'; |
9 | | - |
10 | | -log.info('App starting...'); |
11 | | - |
12 | | -// Setup update event |
13 | | -autoUpdater.on('checking-for-update', () => { |
14 | | - log.info('Checking for update... Please wait.'); |
15 | | -}); |
16 | | -autoUpdater.on('update-available', info => { |
17 | | - log.info('Update available.'); |
18 | | - log.info('Vesrion', info.version); |
19 | | - log.info('Release date', info.releaseDate); |
20 | | -}); |
21 | | -autoUpdater.on('update-not-available', info => { |
22 | | - log.info('Update not available.'); |
23 | | -}); |
24 | | -autoUpdater.on('download-progress', progress => { |
25 | | - log.info(`Download progress: ${Math.floor(progress.percent)}`); |
26 | | -}); |
27 | | -autoUpdater.on('update-downloaded', info => { |
28 | | - log.info('Update downloaded'); |
29 | | -}); |
30 | | -autoUpdater.on('error', error => { |
31 | | - log.info('Update error', error); |
32 | | -}); |
33 | | - |
34 | | -function updateDownloaded() { |
35 | | - // Ask user to update the app |
36 | | - dialog.showMessageBox( |
37 | | - { |
38 | | - type: 'question', |
39 | | - message: 'A new version of ' + app.getName() + ' has been downloaded', |
40 | | - buttons: ['Install and Relaunch', 'Later'], |
41 | | - defaultId: 0, |
42 | | - }, |
43 | | - response => { |
44 | | - if (response === 1) { |
45 | | - dialog.showMessageBox({ |
46 | | - title: 'Installing Later', |
47 | | - message: 'Update will be installed when you exit the app', |
48 | | - }); |
49 | | - } else { |
50 | | - autoUpdater.quitAndInstall(); |
51 | | - } |
52 | | - } |
53 | | - ); |
54 | | -} |
55 | | - |
56 | | -function checkForUpdates() { |
57 | | - autoUpdater.on('update-downloaded', updateDownloaded); |
58 | | - |
59 | | - // init for updates |
60 | | - autoUpdater.checkForUpdates(); |
61 | | -} |
62 | | - |
63 | | -module.exports = checkForUpdates; |
| 5 | +module.exports = function checkForUpdates() { |
| 6 | + return autoUpdater.checkForUpdatesAndNotify(); |
| 7 | +}; |
0 commit comments