summaryrefslogtreecommitdiffhomepage
path: root/gui/src/shared/notifications/connected.ts
blob: 0ce1dceeb5ef83865c8de4563acb02f3e4a98921 (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
import { sprintf } from 'sprintf-js';
import { messages } from '../../shared/gettext';
import { TunnelState } from '../daemon-rpc-types';
import { SystemNotificationProvider } from './notification';

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

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

  public getSystemNotification() {
    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,
        critical: false,
      };
    } else {
      return undefined;
    }
  }
}