summaryrefslogtreecommitdiffhomepage
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/lib/backend.js10
-rw-r--r--app/redux/connection/actions.js42
-rw-r--r--app/redux/connection/reducers.js6
3 files changed, 38 insertions, 20 deletions
diff --git a/app/lib/backend.js b/app/lib/backend.js
index e8c8cbd464..2d39d4b7cd 100644
--- a/app/lib/backend.js
+++ b/app/lib/backend.js
@@ -257,17 +257,21 @@ export class Backend {
*/
_startReachability() {
window.addEventListener('online', () => {
- this._store.dispatch(connectionActions.connectionChange({ isOnline: true }));
+ this._store.dispatch(connectionActions.online());
});
window.addEventListener('offline', () => {
// force disconnect since there is no real connection anyway.
this.disconnect();
- this._store.dispatch(connectionActions.connectionChange({ isOnline: false }));
+ this._store.dispatch(connectionActions.offline());
});
// update online status in background
setTimeout(() => {
- this._store.dispatch(connectionActions.connectionChange({ isOnline: navigator.onLine }));
+ const action = navigator.onLine
+ ? connectionActions.online()
+ : connectionActions.offline();
+
+ this._store.dispatch(action);
}, 0);
}
diff --git a/app/redux/connection/actions.js b/app/redux/connection/actions.js
index e7fd03bc77..eebc503a18 100644
--- a/app/redux/connection/actions.js
+++ b/app/redux/connection/actions.js
@@ -3,7 +3,6 @@
import { clipboard } from 'electron';
import type { Backend } from '../../lib/backend';
-import type { ConnectionReduxState } from './reducers.js';
import type { ReduxGetState, ReduxDispatch } from '../store';
import type { Coordinate2d } from '../../types';
@@ -31,11 +30,6 @@ type DisconnectedAction = {
type: 'DISCONNECTED',
};
-type ConnectionChangeAction = {
- type: 'CONNECTION_CHANGE',
- newData: $Shape<ConnectionReduxState>,
-};
-
type NewPublicIpAction = {
type: 'NEW_PUBLIC_IP',
ip: string,
@@ -52,12 +46,21 @@ type NewLocationAction = {
newLocation: Location,
};
-export type ConnectionAction = ConnectionChangeAction
- | NewPublicIpAction
+type OnlineAction = {
+ type: 'ONLINE',
+};
+
+type OfflineAction = {
+ type: 'OFFLINE',
+};
+
+export type ConnectionAction = NewPublicIpAction
| NewLocationAction
| ConnectingAction
| ConnectedAction
- | DisconnectedAction;
+ | DisconnectedAction
+ | OnlineAction
+ | OfflineAction;
function connectingTo(serverAddress: string): ConnectingAction {
return {
@@ -84,13 +87,6 @@ function disconnected(): DisconnectedAction {
};
}
-function connectionChange(newData: $Shape<ConnectionReduxState>): ConnectionChangeAction {
- return {
- type: 'CONNECTION_CHANGE',
- newData: newData,
- };
-}
-
function newPublicIp(ip: string): NewPublicIpAction {
return {
type: 'NEW_PUBLIC_IP',
@@ -105,6 +101,18 @@ function newLocation(newLoc: Location): NewLocationAction {
};
}
+function online(): OnlineAction {
+ return {
+ type: 'ONLINE',
+ };
+}
+
+function offline(): OfflineAction {
+ return {
+ type: 'OFFLINE',
+ };
+}
+
-export default { connect, disconnect, copyIPAddress, connectionChange, newPublicIp, newLocation, connectingTo, connecting, connected, disconnected };
+export default { connect, disconnect, copyIPAddress, newPublicIp, newLocation, connectingTo, connecting, connected, disconnected, online, offline };
diff --git a/app/redux/connection/reducers.js b/app/redux/connection/reducers.js
index 457a6c1bd6..8f389df159 100644
--- a/app/redux/connection/reducers.js
+++ b/app/redux/connection/reducers.js
@@ -46,6 +46,12 @@ export default function(state: ConnectionReduxState = initialState, action: Redu
case 'DISCONNECTED':
return { ...state, ...{ status: 'disconnected' }};
+ case 'ONLINE':
+ return { ...state, ...{ isOnline: true }};
+
+ case 'OFFLINE':
+ return { ...state, ...{ isOnline: false }};
+
default:
return state;
}