@@ -5,6 +5,8 @@ const http = require('http');
55const xml = require ( "xml2js" ) ;
66const net = require ( 'net' ) ;
77
8+ const gotTheLock = app . requestSingleInstanceLock ( ) ;
9+
810let powerSaveBlockerId ;
911let tray ;
1012let s_mainWindow ;
@@ -196,17 +198,25 @@ process.on('SIGINT', () => {
196198} ) ;
197199
198200app . on ( 'will-quit' , ( ) => {
199- powerSaveBlocker . stop ( powerSaveBlockerId ) ;
201+ try {
202+ powerSaveBlocker . stop ( powerSaveBlockerId ) ;
203+ } catch ( e ) {
204+ console . log ( e ) ;
205+ }
200206} ) ;
201207
202- app . whenReady ( ) . then ( ( ) => {
203- powerSaveBlockerId = powerSaveBlocker . start ( 'prevent-app-suspension' ) ;
204- s_mainWindow = createWindow ( ) ;
205- createAdvancedWindow ( s_mainWindow ) ;
206- globalShortcut . register ( 'Control+Shift+I' , ( ) => { return false ; } ) ;
207- app . on ( 'activate' , function ( ) {
208- if ( BrowserWindow . getAllWindows ( ) . length === 0 ) createWindow ( )
209- } ) ;
208+ if ( ! gotTheLock ) {
209+ app . quit ( ) ;
210+ } else {
211+ startserver ( ) ;
212+ app . whenReady ( ) . then ( ( ) => {
213+ powerSaveBlockerId = powerSaveBlocker . start ( 'prevent-app-suspension' ) ;
214+ s_mainWindow = createWindow ( ) ;
215+ createAdvancedWindow ( s_mainWindow ) ;
216+ globalShortcut . register ( 'Control+Shift+I' , ( ) => { return false ; } ) ;
217+ app . on ( 'activate' , function ( ) {
218+ if ( BrowserWindow . getAllWindows ( ) . length === 0 ) createWindow ( )
219+ } ) ;
210220 s_mainWindow . webContents . once ( 'dom-ready' , function ( ) {
211221 if ( msgbacklog . length > 0 ) {
212222 s_mainWindow . webContents . send ( 'updateMsg' , msgbacklog . pop ( ) ) ;
@@ -216,36 +226,37 @@ app.whenReady().then(() => {
216226 // Create the tray icon
217227 const path = require ( 'path' ) ;
218228 const iconPath = path . join ( __dirname , 'icon1616.png' ) ;
219- tray = new Tray ( iconPath ) ;
229+ tray = new Tray ( iconPath ) ;
220230
221231 const contextMenu = Menu . buildFromTemplate ( [
222232 { label : 'Show App' , click : ( ) => s_mainWindow . show ( ) } ,
223- { label : 'Quit' , click : ( ) => {
233+ { label : 'Quit' , click : ( ) => {
224234 console . log ( "Exiting" ) ;
225235 app . isQuitting = true ;
226236 app . quit ( ) ;
227237 }
228238 } ,
229239 ] ) ;
230240
231- tray . setContextMenu ( contextMenu ) ;
232- tray . setToolTip ( require ( './package.json' ) . name + " V" + require ( './package.json' ) . version ) ;
241+ tray . setContextMenu ( contextMenu ) ;
242+ tray . setToolTip ( require ( './package.json' ) . name + " V" + require ( './package.json' ) . version ) ;
233243
234- s_mainWindow . on ( 'minimize' , ( event ) => {
235- event . preventDefault ( ) ;
236- s_mainWindow . hide ( ) ; // Hides the window instead of minimizing it to the taskbar
237- } ) ;
244+ s_mainWindow . on ( 'minimize' , ( event ) => {
245+ event . preventDefault ( ) ;
246+ s_mainWindow . hide ( ) ; // Hides the window instead of minimizing it to the taskbar
247+ } ) ;
238248
239- s_mainWindow . on ( 'close' , ( event ) => {
240- if ( ! app . isQuitting ) {
241- event . preventDefault ( ) ;
242- s_mainWindow . hide ( ) ;
243- }
244- } ) ;
245- if ( process . platform === 'darwin' ) {
246- app . dock . hide ( ) ;
249+ s_mainWindow . on ( 'close' , ( event ) => {
250+ if ( ! app . isQuitting ) {
251+ event . preventDefault ( ) ;
252+ s_mainWindow . hide ( ) ;
247253 }
248- } )
254+ } ) ;
255+ if ( process . platform === 'darwin' ) {
256+ app . dock . hide ( ) ;
257+ }
258+ } )
259+ }
249260
250261app . on ( 'window-all-closed' , function ( ) {
251262 if ( process . platform !== 'darwin' ) app . quit ( ) ;
@@ -604,5 +615,3 @@ function fmt(spotDate) {
604615 retstr . t = h . padStart ( 2 , '0' ) + i . padStart ( 2 , '0' ) + s . padStart ( 2 , '0' ) ;
605616 return retstr ;
606617}
607-
608- startserver ( ) ;
0 commit comments