@@ -204,52 +204,44 @@ app.whenReady().then(async () => {
204204 ] ) ;
205205 tray . setToolTip ( 'Pinokio' ) ;
206206 tray . setContextMenu ( contextMenu ) ;
207- const announceTray = ( ) => {
208- if ( process . platform === 'darwin' ) {
209- try {
210- tray . setHighlightMode ( 'always' )
211- tray . setTitle ( 'Pinokio running' )
212- setTimeout ( ( ) => tray . setHighlightMode ( 'selection' ) , 4000 )
213- setTimeout ( ( ) => tray . popUpContextMenu ( contextMenu ) , 150 )
214- } catch ( err ) {
215- console . warn ( 'Failed to set tray highlight/title' , err )
216- }
217- return
207+ const showNotification = ( options = { } ) => {
208+ try {
209+ new Notification ( {
210+ title : 'Pinokio' ,
211+ body : 'Running in background' ,
212+ ...options
213+ } ) . show ( )
214+ } catch ( err ) {
215+ console . warn ( 'Failed to show background notification' , err )
218216 }
219-
220- if ( process . platform === 'win32' ) {
221- try {
222- app . setAppUserModelId ( 'Pinokio' )
223- } catch ( err ) {
224- console . warn ( 'Failed to set AppUserModelID' , err )
225- }
226-
227- let notified = false
228- if ( Notification && typeof Notification . isSupported === 'function' && Notification . isSupported ( ) ) {
217+ }
218+ const announceTray = ( ) => {
219+ const platformHandlers = {
220+ darwin : ( ) => {
229221 try {
230- new Notification ( {
231- title : 'Pinokio' ,
232- body : 'Running in background' ,
233- icon : iconPath
234- } ) . show ( )
235- notified = true
222+ tray . setHighlightMode ( 'always' )
223+ tray . setTitle ( 'Pinokio running' )
224+ setTimeout ( ( ) => tray . setHighlightMode ( 'selection' ) , 4000 )
225+ setTimeout ( ( ) => tray . popUpContextMenu ( contextMenu ) , 150 )
236226 } catch ( err ) {
237- console . warn ( 'Failed to show background notification (toast) ' , err )
227+ console . warn ( 'Failed to signal tray/ notification on macOS ' , err )
238228 }
239- }
240- if ( ! notified && typeof tray . displayBalloon === 'function' ) {
241- tray . displayBalloon ( { title : 'Pinokio' , content : 'Running in background' , icon : iconPath } )
242- }
243- return
244- }
245-
246- if ( Notification && typeof Notification . isSupported === 'function' && Notification . isSupported ( ) ) {
247- try {
248- new Notification ( { title : 'Pinokio' , body : 'Running in background' } ) . show ( )
249- } catch ( err ) {
250- console . warn ( 'Failed to show background notification' , err )
229+ showNotification ( )
230+ } ,
231+ win32 : ( ) => {
232+ try {
233+ app . setAppUserModelId ( 'Pinokio' )
234+ } catch ( err ) {
235+ console . warn ( 'Failed to set AppUserModelID' , err )
236+ }
237+ showNotification ( { icon : iconPath } )
238+ } ,
239+ default : ( ) => {
240+ showNotification ( )
251241 }
252242 }
243+ const handler = platformHandlers [ process . platform ] || platformHandlers . default
244+ handler ( )
253245 }
254246 announceTray ( )
255247 tray . on ( 'click' , ( ) => {
0 commit comments