1- const { app, BrowserWindow, globalShortcut } = require ( 'electron/main' ) ;
1+ const { app, BrowserWindow, Tray , Notification , Menu , globalShortcut } = require ( 'electron/main' ) ;
22const path = require ( 'node:path' ) ;
33const { ipcMain} = require ( 'electron' )
44const http = require ( 'http' ) ;
55const xml = require ( "xml2js" ) ;
66const net = require ( 'net' ) ;
77
8+ let tray ;
89let s_mainWindow ;
910let msgbacklog = [ ] ;
1011var WServer ;
@@ -50,7 +51,7 @@ function createWindow () {
5051 }
5152 } ) ;
5253 if ( app . isPackaged ) {
53- mainWindow . setMenu ( null ) ;
54+ mainWindow . setMenu ( null ) ;
5455 }
5556
5657
@@ -133,11 +134,25 @@ ipcMain.on("setCAT", async (event,arg) => {
133134} ) ;
134135
135136ipcMain . on ( "quit" , async ( event , arg ) => {
137+ app . isQuitting = true ;
136138 app . quit ( ) ;
137139 event . returnValue = true ;
138140} ) ;
139141
142+ function show_noti ( arg ) {
143+ try {
144+ const notification = new Notification ( {
145+ title : 'Waevlog' ,
146+ body : arg
147+ } ) ;
148+ notification . show ( ) ;
149+ } catch ( e ) {
150+ console . log ( "No notification possible on this system / ignoring" ) ;
151+ }
152+ }
153+
140154ipcMain . on ( "test" , async ( event , arg ) => {
155+
141156 let result = { } ;
142157 let plain ;
143158 try {
@@ -157,6 +172,12 @@ ipcMain.on("test", async (event,arg) => {
157172 }
158173} ) ;
159174
175+ app . on ( 'before-quit' , ( ) => {
176+ if ( tray ) {
177+ tray . destroy ( ) ;
178+ }
179+ } ) ;
180+
160181app . whenReady ( ) . then ( ( ) => {
161182 s_mainWindow = createWindow ( ) ;
162183 createAdvancedWindow ( s_mainWindow ) ;
@@ -169,10 +190,43 @@ app.whenReady().then(() => {
169190 s_mainWindow . webContents . send ( 'updateMsg' , msgbacklog . pop ( ) ) ;
170191 }
171192 } ) ;
193+
194+ // Create the tray icon
195+ const path = require ( 'path' ) ;
196+ const iconPath = path . join ( __dirname , 'icon1616.png' ) ;
197+ tray = new Tray ( iconPath ) ;
198+
199+ const contextMenu = Menu . buildFromTemplate ( [
200+ { label : 'Show App' , click : ( ) => s_mainWindow . show ( ) } ,
201+ { label : 'Quit' , click : ( ) => {
202+ console . log ( "Exiting" ) ;
203+ app . isQuitting = true ;
204+ app . quit ( ) ;
205+ }
206+ } ,
207+ ] ) ;
208+
209+ tray . setContextMenu ( contextMenu ) ;
210+ tray . setToolTip ( require ( './package.json' ) . name + " V" + require ( './package.json' ) . version ) ;
211+
212+ s_mainWindow . on ( 'minimize' , ( event ) => {
213+ event . preventDefault ( ) ;
214+ s_mainWindow . hide ( ) ; // Hides the window instead of minimizing it to the taskbar
215+ } ) ;
216+
217+ s_mainWindow . on ( 'close' , ( event ) => {
218+ if ( ! app . isQuitting ) {
219+ event . preventDefault ( ) ;
220+ s_mainWindow . hide ( ) ;
221+ }
222+ } ) ;
223+ if ( process . platform === 'darwin' ) {
224+ app . dock . hide ( ) ;
225+ }
172226} )
173227
174228app . on ( 'window-all-closed' , function ( ) {
175- if ( process . platform !== 'darwin' ) app . quit ( )
229+ if ( process . platform !== 'darwin' ) app . quit ( ) ;
176230 app . quit ( ) ;
177231} )
178232
@@ -333,13 +387,15 @@ ports.forEach(port => {
333387 }
334388 if ( x . payload . status == 'created' ) {
335389 adobject . created = true ;
390+ show_noti ( "QSO added: " + adobject . qsos [ 0 ] . CALL ) ;
336391 } else {
337392 adobject . created = false ;
338393 console . log ( x ) ;
339394 adobject . fail = x ;
340395 if ( x . payload . messages ) {
341396 adobject . fail . payload . reason = x . payload . messages . join ( ) ;
342397 }
398+ show_noti ( "QSO NOT added: " + adobject . qsos [ 0 ] . CALL ) ;
343399 }
344400 s_mainWindow . webContents . send ( 'updateTX' , adobject ) ;
345401 tomsg ( '' ) ;
0 commit comments