Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update peer stats only when profile window is open #283

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 8 additions & 15 deletions app/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,16 @@ let IPFS
let ipc
let mb
let logger
let shouldPoll = false
const statsCache = {}

function pollStats (ipfs) {
const next = () => {
setTimeout(() => {
pollStats(ipfs)
if (mb.window.isVisible()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please check for mb.window I have seen it being undefined in edge cases

pollStats(ipfs)
}
}, 1000)
}

if (!shouldPoll || !mb.window || !mb.window.isVisible()) {
return next()
}

ipfs.swarm.peers()
.then((res) => {
statsCache.peers = res.Strings.length
Expand Down Expand Up @@ -79,9 +75,6 @@ function onStartDaemon (node) {
if (err) throw err
ipc.send('node-status', 'running')

shouldPoll = true
pollStats(ipfsNode)

ipfsNode.version()
.then((res) => {
ipc.send('version', res)
Expand All @@ -98,11 +91,9 @@ function onStopDaemon (node, done = () => {}) {
logger.info('Stopping daemon')

ipc.send('node-status', 'stopping')
if (shouldPoll) {
delete statsCache.peers
ipc.send('stats', statsCache)
shouldPoll = false
}

delete statsCache.peers
ipc.send('stats', statsCache)

node.stopDaemon((err) => {
if (err) return logger.error(err.stack)
Expand Down Expand Up @@ -240,6 +231,8 @@ export function boot (lokker) {
// Ensure single instance
mb.app.makeSingleInstance(reboot)

mb.on('show', () => { pollStats(getIPFS()) })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be once to ensure it is only started once


mb.on('ready', () => {
logger.info('Application is ready')

Expand Down