summaryrefslogtreecommitdiffhomepage
path: root/desktop/packages/mullvad-vpn/src/shared/notifications/connected.ts
blob: c66339fe9e546c3ac8b765478fe30d58072cd7a3 (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
39
40
41
42
import { sprintf } from 'sprintf-js';

import { messages } from '../../shared/gettext';
import { TunnelState } from '../daemon-rpc-types';
import {
  SystemNotification,
  SystemNotificationCategory,
  SystemNotificationProvider,
  SystemNotificationSeverityType,
} from './notification';

export class ConnectedNotificationProvider implements SystemNotificationProvider {
  public constructor(private context: TunnelState) {}

  public mayDisplay = () => this.context.state === 'connected';

  public getSystemNotification(): SystemNotification | undefined {
    if (this.context.state === 'connected') {
      let message = messages.pgettext('notifications', 'Connected');
      const location = this.context.details.location?.hostname;
      if (location) {
        message = sprintf(
          // TRANSLATORS: The message showed when a server has been connected to.
          // TRANSLATORS: Available placeholder:
          // TRANSLATORS: %(location) - name of the server location we're connected to (e.g. "se-got-003")
          messages.pgettext('notifications', 'Connected to %(location)s'),
          {
            location,
          },
        );
      }

      return {
        message,
        severity: SystemNotificationSeverityType.info,
        category: SystemNotificationCategory.tunnelState,
      };
    } else {
      return undefined;
    }
  }
}