Skip to content

Commit c82e848

Browse files
committed
Don't auto close on missing scale. Show dialog window for new update.
1 parent 5165cf2 commit c82e848

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

main.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { autoUpdater } = require( 'electron-updater' );
22
const log = require( 'electron-log' );
33

4-
const { BrowserWindow, app, Notification } = require( 'electron' );
4+
const { BrowserWindow, app, Notification, dialog } = require( 'electron' );
55
const { SerialPort } = require( 'serialport' );
66
const { ReadlineParser } = require( '@serialport/parser-readline' );
77
const path = require( 'path' );
@@ -118,7 +118,7 @@ async function initSerialPort(){
118118
} )
119119

120120
if(!scalePort) {
121-
closeWindow( "Couldn't find a scale." );
121+
// closeWindow( "Couldn't find a scale." );
122122
log.error( "Couldn't find a scale." );
123123
return;
124124
}
@@ -200,10 +200,24 @@ function createWindow(){
200200
// initialization and is ready to create browser windows.
201201
// Some APIs can only be used after this event occurs.
202202
app.on( 'ready', function(){
203-
autoUpdater.checkForUpdatesAndNotify();
203+
autoUpdater.checkForUpdates();
204204
createWindow();
205205
} );
206206

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+
207221
// Quit when all windows are closed.
208222
app.on( 'window-all-closed', function(){
209223
// On OS X it is common for applications and their menu bar

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "scale-serialreader",
33
"productName": "ScaleSerialReader",
4-
"version": "1.0.4",
4+
"version": "1.0.5",
55
"description": "An Electron application with node serialport that streams data from a serial-usb to a website.",
66
"author": "Steven Hawley",
77
"main": "main.js",
@@ -14,7 +14,8 @@
1414
"pack": "electron-builder --dir",
1515
"dist": "electron-builder",
1616
"build-mac": "npm install && npm run postinstall-mac && npm run rebuild",
17-
"publish": "electron-builder -p always"
17+
"publish": "electron-builder -p always",
18+
"postinstall": "electron-builder install-app-deps"
1819
},
1920
"keywords": [
2021
"Electron",

0 commit comments

Comments
 (0)