diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2018-06-11 15:38:27 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2018-06-12 15:58:20 +0200 |
| commit | 34219a223e87508817a5fd2fe93c1e013472a1ca (patch) | |
| tree | cdd88dbbdb5ffc42bc7202dba44b23020d855265 /app/lib | |
| parent | fe3e41f0b5c95e50736565f1faaa212460fb7051 (diff) | |
| download | mullvadvpn-34219a223e87508817a5fd2fe93c1e013472a1ca.tar.xz mullvadvpn-34219a223e87508817a5fd2fe93c1e013472a1ca.zip | |
Refresh account expiration when window becomes visible
Diffstat (limited to 'app/lib')
| -rw-r--r-- | app/lib/app-visibility.js | 28 |
1 files changed, 28 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); + }; +} |
