|
1 | 1 | // Modules to control application life and create native browser window
|
2 | 2 | require('update-electron-app')();
|
3 |
| -const { app, BrowserWindow, globalShortcut, ipcMain} = require('electron'); |
| 3 | +const { app, BrowserWindow, autoUpdater ,globalShortcut, ipcMain} = require('electron'); |
4 | 4 | const path = require('path');
|
5 | 5 | const ipc = ipcMain;
|
6 | 6 |
|
| 7 | +autoUpdater.on('update-downloaded', (event, releaseNotes, releaseName) => { |
| 8 | + const dialogOpts = { |
| 9 | + type: 'info', |
| 10 | + buttons: ['Restart', 'Later'], |
| 11 | + title: 'Application Update', |
| 12 | + message: process.platform === 'win32' ? releaseNotes : releaseName, |
| 13 | + detail: 'A new version has been downloaded. Restart the application to apply the updates.' |
| 14 | + } |
| 15 | + |
| 16 | + dialog.showMessageBox(dialogOpts).then((returnValue) => { |
| 17 | + if (returnValue.response === 0) autoUpdater.quitAndInstall() |
| 18 | + }) |
| 19 | + }) |
| 20 | + |
| 21 | + autoUpdater.on('error', message => { |
| 22 | + console.error('There was a problem updating the application') |
| 23 | + console.error(message) |
| 24 | + }) |
| 25 | + |
7 | 26 | // Keep a global reference of the window object, if you don't, the window will
|
8 | 27 | // be closed automatically when the JavaScript object is garbage collected.
|
9 | 28 | let mainWindow;
|
@@ -103,7 +122,9 @@ function createWindow() {
|
103 | 122 | // This method will be called when Electron has finished
|
104 | 123 | // initialization and is ready to create browser windows.
|
105 | 124 | // Some APIs can only be used after this event occurs.
|
106 |
| -app.on('ready', createWindow); |
| 125 | +app.on('ready', createWindow, () => { |
| 126 | + autoUpdater.checkForUpdates(); |
| 127 | +}); |
107 | 128 |
|
108 | 129 | // Quit when all windows are closed.
|
109 | 130 | app.on('window-all-closed', function() {
|
|
0 commit comments