Skip to content

Commit 413ea2b

Browse files
sutartmelsonlidel
authored andcommitted
feat: Show discovered peer count
1 parent 6915417 commit 413ea2b

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/tray.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -290,19 +290,19 @@ module.exports = function (ctx) {
290290
tray.on('right-click', popupMenu)
291291
tray.on('double-click', () => ctx.launchWebUI('/'))
292292

293-
const pollPeers = () => {
293+
const fetchPeers = () => {
294294
// 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.
296296
if (state.status === STATUS.STARTING_FINISHED && ctx.getIpfsd) {
297297
ctx.getIpfsd().then((daemon) => {
298298
daemon.api.swarm.peers().then((value) => {
299299
if (value.length) {
300-
ipcMain.emit('peersPolled', value.length)
300+
ipcMain.emit('peerCountFetched', value.length)
301301
}
302302
})
303303
})
304304
} else {
305-
ipcMain.emit('peersPolled', 0)
305+
ipcMain.emit('peerCountFetched', 0)
306306
}
307307
}
308308

@@ -377,6 +377,12 @@ module.exports = function (ctx) {
377377
}
378378
}
379379

380+
ipcMain.on('menubar-will-open', () => {
381+
fetchPeers()
382+
setupMenu()
383+
updateMenu()
384+
})
385+
380386
ipcMain.on('ipfsd', status => {
381387
state.status = status
382388
updateMenu()
@@ -402,26 +408,21 @@ module.exports = function (ctx) {
402408
updateMenu()
403409
})
404410

405-
ipcMain.on('peersPolled', peerCount => {
411+
ipcMain.on('peerCountFetched', peerCount => {
406412
// When a new peer count is retrieved, rebuild the menu and update
407413
// the tray tooltip with the new number if necessary.
408414
if (peerCount !== state.peerCount) {
409415
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)
414416
tray.setToolTip(state.peerCount.toString() + ' ' + i18n.t('peerCount'))
415-
updateMenu()
416417
}
417418
})
418419

419420
ipcMain.on('configUpdated', () => { updateMenu() })
420421
ipcMain.on('languageUpdated', () => { setupMenu() })
421422

422423
setupMenu()
423-
setInterval(pollPeers, 60000)
424424

425+
tray.on('mouse-move', () => { fetchPeers() })
425426
ctx.tray = tray
426427
logger.info('[tray] started')
427428
}

0 commit comments

Comments
 (0)