diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2018-06-12 16:22:45 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2018-06-12 16:22:45 +0200 |
| commit | a7da96bc03b3705c4d99bbc55e9f1a04f2030c25 (patch) | |
| tree | 25f9e6012bad2efc917342450f4ae055deb6fe6e /app/lib | |
| parent | 55b5d390bc377b9ff6cdf5a0b1641ea2fae23719 (diff) | |
| parent | 247e9807b25ac5033ab5cfa55cc40a5201b21523 (diff) | |
| download | mullvadvpn-a7da96bc03b3705c4d99bbc55e9f1a04f2030c25.tar.xz mullvadvpn-a7da96bc03b3705c4d99bbc55e9f1a04f2030c25.zip | |
Merge branch 'refresh-expiry-time'
Diffstat (limited to 'app/lib')
| -rw-r--r-- | app/lib/app-visibility.js | 28 | ||||
| -rw-r--r-- | app/lib/backend.js | 19 |
2 files changed, 47 insertions, 0 deletions
diff --git a/app/lib/app-visibility.js b/app/lib/app-visibility.js new file mode 100644 index 0000000000..d599f6941b --- /dev/null +++ b/app/lib/app-visibility.js @@ -0,0 +1,28 @@ +// @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/lib/backend.js b/app/lib/backend.js index b043a9b10e..dfe4fdd2c3 100644 --- a/app/lib/backend.js +++ b/app/lib/backend.js @@ -365,6 +365,25 @@ export class Backend { } } + async updateAccountExpiry() { + const ipc = this._ipc; + const store = this._store; + + try { + await this._ensureAuthenticated(); + + const accountToken = await this._ipc.getAccount(); + if (!accountToken) { + throw new BackendError('NO_ACCOUNT'); + } + + const accountData = await ipc.getAccountData(accountToken); + store.dispatch(accountActions.updateAccountExpiry(accountData.expiry)); + } catch (e) { + log.error(`Failed to update account expiry: ${e.message}`); + } + } + async removeAccountFromHistory(accountToken: AccountToken) { try { await this._ensureAuthenticated(); |
