|
1 | 1 | const { autoUpdater } = require( 'electron-updater' ); |
2 | 2 | const log = require( 'electron-log' ); |
3 | 3 |
|
4 | | -const { BrowserWindow, app, Notification } = require( 'electron' ); |
| 4 | +const { BrowserWindow, app, Notification, dialog } = require( 'electron' ); |
5 | 5 | const { SerialPort } = require( 'serialport' ); |
6 | 6 | const { ReadlineParser } = require( '@serialport/parser-readline' ); |
7 | 7 | const path = require( 'path' ); |
@@ -118,7 +118,7 @@ async function initSerialPort(){ |
118 | 118 | } ) |
119 | 119 |
|
120 | 120 | if(!scalePort) { |
121 | | - closeWindow( "Couldn't find a scale." ); |
| 121 | + // closeWindow( "Couldn't find a scale." ); |
122 | 122 | log.error( "Couldn't find a scale." ); |
123 | 123 | return; |
124 | 124 | } |
@@ -200,10 +200,24 @@ function createWindow(){ |
200 | 200 | // initialization and is ready to create browser windows. |
201 | 201 | // Some APIs can only be used after this event occurs. |
202 | 202 | app.on( 'ready', function(){ |
203 | | - autoUpdater.checkForUpdatesAndNotify(); |
| 203 | + autoUpdater.checkForUpdates(); |
204 | 204 | createWindow(); |
205 | 205 | } ); |
206 | 206 |
|
| 207 | +autoUpdater.on('update-available', () => { |
| 208 | + dialog.showMessageBox({ |
| 209 | + type: 'info', |
| 210 | + title: 'New Update Available', |
| 211 | + message: 'A new version of the application is available.', |
| 212 | + buttons: ['Download Now'] |
| 213 | + }, (response) => { |
| 214 | + if (response === 0) { |
| 215 | + autoUpdater.downloadUpdate().then( r => autoUpdater.quitAndInstall() ); |
| 216 | + } |
| 217 | + }); |
| 218 | +}); |
| 219 | + |
| 220 | + |
207 | 221 | // Quit when all windows are closed. |
208 | 222 | app.on( 'window-all-closed', function(){ |
209 | 223 | // On OS X it is common for applications and their menu bar |
|
0 commit comments