summaryrefslogtreecommitdiffhomepage
path: root/gui/src/shared/notifications/blockWhenDisconnected.ts
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2020-06-04 13:45:06 +0200
committerOskar Nyberg <oskar@mullvad.net>2020-06-10 13:46:17 +0200
commitbfd3b02a3936451ae43867f8f3e2f986a2a2f9bc (patch)
tree3ab241e849f8f22f5bc0a8e5af226c8b30e4552e /gui/src/shared/notifications/blockWhenDisconnected.ts
parentd7fdccb58e8205ae26023629873922979644bfdd (diff)
downloadmullvadvpn-bfd3b02a3936451ae43867f8f3e2f986a2a2f9bc.tar.xz
mullvadvpn-bfd3b02a3936451ae43867f8f3e2f986a2a2f9bc.zip
Categorize notifications and their logic into notification definition
Diffstat (limited to 'gui/src/shared/notifications/blockWhenDisconnected.ts')
-rw-r--r--gui/src/shared/notifications/blockWhenDisconnected.ts40
1 files changed, 40 insertions, 0 deletions
diff --git a/gui/src/shared/notifications/blockWhenDisconnected.ts b/gui/src/shared/notifications/blockWhenDisconnected.ts
new file mode 100644
index 0000000000..16b65c0672
--- /dev/null
+++ b/gui/src/shared/notifications/blockWhenDisconnected.ts
@@ -0,0 +1,40 @@
+import { messages } from '../../shared/gettext';
+import { TunnelState } from '../daemon-rpc-types';
+import {
+ InAppNotification,
+ InAppNotificationProvider,
+ SystemNotificationProvider,
+} from './notification';
+
+interface BlockWhenDisconnectedNotificationContext {
+ tunnelState: TunnelState;
+ blockWhenDisconnected: boolean;
+}
+
+export class BlockWhenDisconnectedNotificationProvider
+ implements InAppNotificationProvider, SystemNotificationProvider {
+ public constructor(private context: BlockWhenDisconnectedNotificationContext) {}
+
+ public mayDisplay() {
+ return (
+ (this.context.tunnelState.state === 'disconnecting' ||
+ this.context.tunnelState.state === 'disconnected') &&
+ this.context.blockWhenDisconnected
+ );
+ }
+
+ public getSystemNotification() {
+ return {
+ message: messages.pgettext('notifications', 'Blocking internet'),
+ critical: false,
+ };
+ }
+
+ public getInAppNotification(): InAppNotification {
+ return {
+ indicator: 'error',
+ title: messages.pgettext('in-app-notifications', 'BLOCKING INTERNET'),
+ subtitle: messages.pgettext('in-app-notifications', '"Always require VPN" is enabled.'),
+ };
+ }
+}