@@ -290,19 +290,19 @@ module.exports = function (ctx) {
290
290
tray . on ( 'right-click' , popupMenu )
291
291
tray . on ( 'double-click' , ( ) => ctx . launchWebUI ( '/' ) )
292
292
293
- const pollPeers = ( ) => {
293
+ const fetchPeers = ( ) => {
294
294
// If the daemon is running, send a request to retrieve the number
295
- // of connected peers. Emit 'peersPolled ' event upon retrieval.
295
+ // of connected peers. Emit 'peerCountFetched ' event upon retrieval.
296
296
if ( state . status === STATUS . STARTING_FINISHED && ctx . getIpfsd ) {
297
297
ctx . getIpfsd ( ) . then ( ( daemon ) => {
298
298
daemon . api . swarm . peers ( ) . then ( ( value ) => {
299
299
if ( value . length ) {
300
- ipcMain . emit ( 'peersPolled ' , value . length )
300
+ ipcMain . emit ( 'peerCountFetched ' , value . length )
301
301
}
302
302
} )
303
303
} )
304
304
} else {
305
- ipcMain . emit ( 'peersPolled ' , 0 )
305
+ ipcMain . emit ( 'peerCountFetched ' , 0 )
306
306
}
307
307
}
308
308
@@ -377,6 +377,12 @@ module.exports = function (ctx) {
377
377
}
378
378
}
379
379
380
+ ipcMain . on ( 'menubar-will-open' , ( ) => {
381
+ fetchPeers ( )
382
+ setupMenu ( )
383
+ updateMenu ( )
384
+ } )
385
+
380
386
ipcMain . on ( 'ipfsd' , status => {
381
387
state . status = status
382
388
updateMenu ( )
@@ -402,26 +408,21 @@ module.exports = function (ctx) {
402
408
updateMenu ( )
403
409
} )
404
410
405
- ipcMain . on ( 'peersPolled ' , peerCount => {
411
+ ipcMain . on ( 'peerCountFetched ' , peerCount => {
406
412
// When a new peer count is retrieved, rebuild the menu and update
407
413
// the tray tooltip with the new number if necessary.
408
414
if ( peerCount !== state . peerCount ) {
409
415
state . peerCount = peerCount
410
- menu = buildMenu ( ctx , state . peerCount )
411
- menu . on ( 'menu-will-show' , ( ) => { ipcMain . emit ( 'menubar-will-open' ) } )
412
- menu . on ( 'menu-will-close' , ( ) => { ipcMain . emit ( 'menubar-will-close' ) } )
413
- tray . setContextMenu ( menu )
414
416
tray . setToolTip ( state . peerCount . toString ( ) + ' ' + i18n . t ( 'peerCount' ) )
415
- updateMenu ( )
416
417
}
417
418
} )
418
419
419
420
ipcMain . on ( 'configUpdated' , ( ) => { updateMenu ( ) } )
420
421
ipcMain . on ( 'languageUpdated' , ( ) => { setupMenu ( ) } )
421
422
422
423
setupMenu ( )
423
- setInterval ( pollPeers , 60000 )
424
424
425
+ tray . on ( 'mouse-move' , ( ) => { fetchPeers ( ) } )
425
426
ctx . tray = tray
426
427
logger . info ( '[tray] started' )
427
428
}
0 commit comments