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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
import { sprintf } from 'sprintf-js';
import { messages } from '../../shared/gettext';
import { TunnelState } from '../daemon-rpc-types';
import {
InAppNotification,
InAppNotificationProvider,
SystemNotification,
SystemNotificationCategory,
SystemNotificationProvider,
SystemNotificationSeverityType,
} from './notification';
interface ConnectingNotificationContext {
tunnelState: TunnelState;
reconnecting?: boolean;
}
export class ConnectingNotificationProvider
implements SystemNotificationProvider, InAppNotificationProvider {
public constructor(private context: ConnectingNotificationContext) {}
public mayDisplay() {
return this.context.tunnelState.state === 'connecting' && !this.context.reconnecting;
}
public getSystemNotification(): SystemNotification | undefined {
if (this.context.tunnelState.state === 'connecting') {
let message = messages.pgettext('notifications', 'Connecting');
const location = this.context.tunnelState.details?.location?.hostname;
if (location) {
message = sprintf(
// TRANSLATORS: The message showed when a server is being connected to.
// TRANSLATORS: Available placeholder:
// TRANSLATORS: %(location) - name of the server location we're connecting to (e.g. "se-got-003")
messages.pgettext('notifications', 'Connecting to %(location)s'),
{
location,
},
);
}
return {
message,
severity: SystemNotificationSeverityType.info,
category: SystemNotificationCategory.tunnelState,
throttle: true,
};
} else {
return undefined;
}
}
public getInAppNotification(): InAppNotification {
return {
title: messages.pgettext('in-app-notifications', 'BLOCKING INTERNET'),
};
}
}
|