diff options
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(); |
