Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

add network connection notifications #4038

Merged
merged 1 commit into from
Sep 15, 2016
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,14 @@ app.on('ready', () => {
}, appConfig.quitTimeout)
})

app.on('network-connected', () => {
appActions.networkConnected()
})

app.on('network-disconnected', () => {
appActions.networkDisconnected()
})

// User initiated exit using File->Quit
ipcMain.on(messages.RESPONSE_WINDOW_STATE, (wnd, data) => {
if (data) {
Expand Down
19 changes: 19 additions & 0 deletions app/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,13 @@ const doAction = (action) => {
if (action.key === settings.PAYMENTS_ENABLED) return initialize(action.value)
if (action.key === settings.PAYMENTS_CONTRIBUTION_AMOUNT) return setPaymentInfo(action.value)
break

case appConstants.APP_NETWORK_CONNECTED:
setTimeout(networkConnected, 1 * msecs.second)
break

default:
break
}
}

Expand Down Expand Up @@ -1167,6 +1173,19 @@ var cacheReturnValue = () => {
}
}

var networkConnected = underscore.debounce(() => {
if (!client) return

if (runTimeoutId) {
clearTimeout(runTimeoutId)
runTimeoutId = false
}
if (client.sync(callback) === true) run(random.randomInt({ min: msecs.minute, max: 10 * msecs.minute }))

if (balanceTimeoutId) clearTimeout(balanceTimeoutId)
balanceTimeoutId = setTimeout(getBalance, 5 * msecs.second)
}, 1 * msecs.minute, true)

/*
* low-level utilities
*/
Expand Down
13 changes: 13 additions & 0 deletions docs/appActions.md
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,19 @@ Dispatches a message when appWindowId loses focus



### networkConnected()

Dispatches a message when the network is re-connected
after being disconnected



### networkDisconnected()

Dispatches a message when the network is disconnected




* * *

Expand Down
19 changes: 19 additions & 0 deletions js/actions/appActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,25 @@ const appActions = {
actionType: AppConstants.APP_WINDOW_BLURRED,
appWindowId: appWindowId
})
},

/**
* Dispatches a message when the network is re-connected
* after being disconnected
*/
networkConnected: function () {
AppDispatcher.dispatch({
actionType: AppConstants.APP_NETWORK_CONNECTED
})
},

/**
* Dispatches a message when the network is disconnected
*/
networkDisconnected: function () {
AppDispatcher.dispatch({
actionType: AppConstants.APP_NETWORK_DISCONNECTED
})
}
}

Expand Down
2 changes: 2 additions & 0 deletions js/constants/appConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const AppConstants = {
APP_SET_LOGIN_RESPONSE_DETAIL: _,
APP_WINDOW_BLURRED: _,
APP_IDLE_STATE_CHANGED: _,
APP_NETWORK_CONNECTED: _,
APP_NETWORK_DISCONNECTED: _,
APP_CHANGE_NEW_TAB_DETAIL: _,
APP_TAB_CREATED: _,
APP_TAB_DESTROYED: _
Expand Down