diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-08-08 08:28:30 -0300 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-08-08 08:28:30 -0300 |
| commit | d53fda746465c0bb6525371b9d780cbfac90f942 (patch) | |
| tree | beacf7c53402be23fcb77db0c539e65fa6254ef3 /app | |
| parent | 3221c88864426691153f2441b4b42fa282cac667 (diff) | |
| parent | de0a655e05b0c4c4cd9173ab41a3d8e1c2d0842b (diff) | |
| download | mullvadvpn-d53fda746465c0bb6525371b9d780cbfac90f942.tar.xz mullvadvpn-d53fda746465c0bb6525371b9d780cbfac90f942.zip | |
Merge branch 'notifications'
Diffstat (limited to 'app')
| -rw-r--r-- | app/app.js | 20 | ||||
| -rw-r--r-- | app/main.js | 6 | ||||
| -rw-r--r-- | app/notification-controller.js | 25 |
3 files changed, 50 insertions, 1 deletions
diff --git a/app/app.js b/app/app.js index 501bfac780..3171d69b76 100644 --- a/app/app.js +++ b/app/app.js @@ -11,6 +11,7 @@ import makeRoutes from './routes'; import { log } from './lib/platform'; import ReconnectionBackoff from './lib/reconnection-backoff'; import { DaemonRpc } from './lib/daemon-rpc'; +import NotificationController from './notification-controller'; import { setShutdownHandler } from './shutdown-handler'; import { NoAccountError } from './errors'; @@ -30,6 +31,7 @@ import type { ConnectionState } from './redux/connection/reducers'; import type { TrayIconType } from './tray-icon-controller'; export default class AppRenderer { + _notificationController = new NotificationController(); _daemonRpc: DaemonRpcProtocol = new DaemonRpc(); _reconnectBackoff = new ReconnectionBackoff(); _credentials: ?RpcCredentials; @@ -523,6 +525,24 @@ export default class AppRenderer { } this._updateTrayIcon(connectionState); + this._showNotification(connectionState); + } + + _showNotification(connectionState: ConnectionState) { + switch (connectionState) { + case 'connecting': + this._notificationController.show('Connecting'); + break; + case 'connected': + this._notificationController.show('Secured'); + break; + case 'disconnected': + this._notificationController.show('Unsecured'); + break; + default: + log.error(`Unexpected ConnectionState: ${(connectionState: empty)}`); + return; + } } async _authenticate(sharedSecret: string) { diff --git a/app/main.js b/app/main.js index c498e3bee4..ef4e2e9e24 100644 --- a/app/main.js +++ b/app/main.js @@ -33,6 +33,10 @@ const ApplicationMain = { log.info(`Running version ${app.getVersion()}`); + if (process.platform === 'win32') { + app.setAppUserModelId('net.mullvad.vpn'); + } + app.on('activate', () => this._onActivate()); app.on('ready', () => this._onReady()); app.on('window-all-closed', () => app.quit()); @@ -61,7 +65,7 @@ const ApplicationMain = { _overrideAppPaths() { // This ensures that on Windows the %LOCALAPPDATA% directory is used instead of the %ADDDATA% // directory that has roaming contents - if (process.platform == 'win32') { + if (process.platform === 'win32') { const appDataDir = process.env.LOCALAPPDATA; if (appDataDir) { app.setPath('appData', appDataDir); diff --git a/app/notification-controller.js b/app/notification-controller.js new file mode 100644 index 0000000000..62d6381e72 --- /dev/null +++ b/app/notification-controller.js @@ -0,0 +1,25 @@ +// @flow +import { remote } from 'electron'; + +export default class NotificationController { + _activeNotification: ?Notification; + + show(message: string) { + const lastNotification = this._activeNotification; + const newNotification = new Notification(remote.app.getName(), { body: message, silent: true }); + + this._activeNotification = newNotification; + + newNotification.addEventListener('show', () => { + // If the notification is closed too soon, it might still get shown. If that happens, close() + // should be called again so that it is closed immediately. + if (this._activeNotification !== newNotification) { + newNotification.close(); + } + }); + + if (lastNotification) { + lastNotification.close(); + } + } +} |
