summaryrefslogtreecommitdiffhomepage
path: root/gui/src/shared/notifications/no-valid-key.ts
blob: 6de28ab8dff31067dd8530c27864848d6b94f309 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { WgKeyState } from '../../renderer/redux/settings/reducers';
import { messages } from '../../shared/gettext';
import { LiftedConstraint, TunnelProtocol } from '../daemon-rpc-types';
import { InAppNotification, InAppNotificationProvider } from './notification';

interface NoValidKeyNotificationContext {
  tunnelProtocol?: LiftedConstraint<TunnelProtocol>;
  wireGuardKey: WgKeyState;
}

export class NoValidKeyNotificationProvider implements InAppNotificationProvider {
  public constructor(private context: NoValidKeyNotificationContext) {}

  public mayDisplay() {
    const usingWireGuard =
      this.context.tunnelProtocol === 'wireguard' ||
      (this.context.tunnelProtocol === 'any' &&
        (process.platform ?? window.env.platform) !== 'win32');
    const keyInvalid =
      this.context.wireGuardKey.type === 'key-not-set' ||
      this.context.wireGuardKey.type === 'too-many-keys' ||
      this.context.wireGuardKey.type === 'generation-failure' ||
      (this.context.wireGuardKey.type === 'key-set' &&
        this.context.wireGuardKey.key.valid === false) ||
      (this.context.wireGuardKey.type === 'key-set' &&
        this.context.wireGuardKey.key.replacementFailure === 'too_many_keys');

    return usingWireGuard && keyInvalid;
  }

  public getInAppNotification(): InAppNotification {
    return {
      indicator: 'warning',
      title: messages.pgettext('in-app-notifications', 'VALID WIREGUARD KEY IS MISSING'),
      subtitle: messages.pgettext('in-app-notifications', 'Manage keys under Advanced settings.'),
    };
  }
}