summaryrefslogtreecommitdiffhomepage
path: root/app
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2018-06-26 17:53:25 +0200
committerAndrej Mihajlov <and@mullvad.net>2018-06-27 17:38:40 +0200
commit729dc6a3b9dd9fca84c355ef4b0c321cd344745b (patch)
treefaa5a55631a3fc727df37586f6834a1d5d01cbc5 /app
parentf41f3bbfda0abd6db1ef0ee0eeddd155f41cdb3a (diff)
downloadmullvadvpn-729dc6a3b9dd9fca84c355ef4b0c321cd344745b.tar.xz
mullvadvpn-729dc6a3b9dd9fca84c355ef4b0c321cd344745b.zip
Migrate back to AppActivationState observer from RX
See https://github.com/Microsoft/reactxp/issues/661
Diffstat (limited to 'app')
-rw-r--r--app/components/Account.js15
-rw-r--r--app/lib/app-visibility.js28
-rw-r--r--app/main.js7
3 files changed, 8 insertions, 42 deletions
diff --git a/app/components/Account.js b/app/components/Account.js
index 8639d0fe42..fc72ff5b30 100644
--- a/app/components/Account.js
+++ b/app/components/Account.js
@@ -1,13 +1,12 @@
// @flow
import moment from 'moment';
import * as React from 'react';
-import { Component, Text, View } from 'reactxp';
+import { Component, Text, View, App, Types } from 'reactxp';
import { Button, RedButton, GreenButton, Label } from './styled';
import { Layout, Container } from './Layout';
import styles from './AccountStyles';
import Img from './Img';
import { formatAccount } from '../lib/formatters';
-import AppVisiblityObserver from '../lib/app-visibility';
import type { AccountToken } from '../lib/ipc-facade';
@@ -29,7 +28,7 @@ export default class Account extends Component<AccountProps, AccountState> {
isRefreshingExpiry: false,
};
- _appVisibilityObserver: ?AppVisiblityObserver;
+ _activationStateToken: ?Types.SubscriptionToken;
_isMounted = false;
@@ -37,8 +36,8 @@ export default class Account extends Component<AccountProps, AccountState> {
this._isMounted = true;
this._refreshAccountExpiry();
- this._appVisibilityObserver = new AppVisiblityObserver((isVisible) => {
- if (isVisible) {
+ this._activationStateToken = App.activationStateChangedEvent.subscribe((activationState) => {
+ if (activationState === Types.AppActivationState.Active) {
this._refreshAccountExpiry();
}
});
@@ -47,8 +46,10 @@ export default class Account extends Component<AccountProps, AccountState> {
componentWillUnmount() {
this._isMounted = false;
- if (this._appVisibilityObserver) {
- this._appVisibilityObserver.dispose();
+ const activationStateToken = this._activationStateToken;
+ if (activationStateToken) {
+ activationStateToken.unsubscribe();
+ this._activationStateToken = null;
}
}
diff --git a/app/lib/app-visibility.js b/app/lib/app-visibility.js
deleted file mode 100644
index d599f6941b..0000000000
--- a/app/lib/app-visibility.js
+++ /dev/null
@@ -1,28 +0,0 @@
-// @flow
-import { ipcRenderer } from 'electron';
-
-type EventHandler = (boolean) => any;
-
-export default class AppVisiblityObserver {
- _handler: EventHandler;
-
- constructor(handler: EventHandler) {
- this._handler = handler;
-
- ipcRenderer.on('show-window', this._handleShowEvent).on('hide-window', this._handleHideEvent);
- }
-
- dispose() {
- ipcRenderer
- .removeListener('show-window', this._handleShowEvent)
- .removeListener('hide-window', this._handleHideEvent);
- }
-
- _handleShowEvent = (_event) => {
- this._handler(true);
- };
-
- _handleHideEvent = (_event) => {
- this._handler(false);
- };
-}
diff --git a/app/main.js b/app/main.js
index 313c0f7cde..548605e6a1 100644
--- a/app/main.js
+++ b/app/main.js
@@ -112,7 +112,6 @@ const ApplicationMain = {
tray.on('click', () => windowController.toggle());
- this._registerWindowIpcEvents(window);
this._registerIpcListeners();
this._setAppMenu();
this._addContextMenu(window);
@@ -136,12 +135,6 @@ const ApplicationMain = {
window.loadFile('build/index.html');
},
- _registerWindowIpcEvents(window: BrowserWindow) {
- // Notify renderer when window visibility changes.
- window.on('show', () => window.webContents.send('show-window'));
- window.on('hide', () => window.webContents.send('hide-window'));
- },
-
_registerIpcListeners() {
ipcMain.on('on-browser-window-ready', () => {
this._pollConnectionInfoFile();