-
-
Notifications
You must be signed in to change notification settings - Fork 435
/
Copy pathnotification-service-server.ts
109 lines (91 loc) · 3.08 KB
/
notification-service-server.ts
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import { injectable } from '@theia/core/shared/inversify';
import type {
NotificationServiceServer,
NotificationServiceClient,
BoardsPackage,
LibraryPackage,
ConfigState,
Sketch,
ProgressMessage,
IndexUpdateWillStartParams,
IndexUpdateDidCompleteParams,
IndexUpdateDidFailParams,
DetectedPorts,
} from '../common/protocol';
@injectable()
export class NotificationServiceServerImpl
implements NotificationServiceServer
{
private readonly clients: NotificationServiceClient[] = [];
notifyDidReinitialize(): void {
this.clients.forEach((client) => client.notifyDidReinitialize());
}
notifyIndexUpdateWillStart(params: IndexUpdateWillStartParams): void {
this.clients.forEach((client) => client.notifyIndexUpdateWillStart(params));
}
notifyIndexUpdateDidProgress(progressMessage: ProgressMessage): void {
this.clients.forEach((client) =>
client.notifyIndexUpdateDidProgress(progressMessage)
);
}
notifyIndexUpdateDidComplete(params: IndexUpdateDidCompleteParams): void {
this.clients.forEach((client) =>
client.notifyIndexUpdateDidComplete(params)
);
}
notifyIndexUpdateDidFail(params: IndexUpdateDidFailParams): void {
this.clients.forEach((client) => client.notifyIndexUpdateDidFail(params));
}
notifyDaemonDidStart(port: number): void {
this.clients.forEach((client) => client.notifyDaemonDidStart(port));
}
notifyDaemonDidStop(): void {
this.clients.forEach((client) => client.notifyDaemonDidStop());
}
notifyPlatformDidInstall(event: { item: BoardsPackage }): void {
this.clients.forEach((client) => client.notifyPlatformDidInstall(event));
}
notifyPlatformDidUninstall(event: { item: BoardsPackage }): void {
this.clients.forEach((client) => client.notifyPlatformDidUninstall(event));
}
notifyLibraryDidInstall(event: {
item: LibraryPackage | 'zip-install';
}): void {
this.clients.forEach((client) => client.notifyLibraryDidInstall(event));
}
notifyLibraryDidUninstall(event: { item: LibraryPackage }): void {
this.clients.forEach((client) => client.notifyLibraryDidUninstall(event));
}
notifyDetectedPortsDidChange(event: { detectedPorts: DetectedPorts }): void {
this.clients.forEach((client) =>
client.notifyDetectedPortsDidChange(event)
);
}
notifyConfigDidChange(event: ConfigState): void {
this.clients.forEach((client) => client.notifyConfigDidChange(event));
}
notifyRecentSketchesDidChange(event: { sketches: Sketch[] }): void {
this.clients.forEach((client) =>
client.notifyRecentSketchesDidChange(event)
);
}
setClient(client: NotificationServiceClient): void {
this.clients.push(client);
}
disposeClient(client: NotificationServiceClient): void {
const index = this.clients.indexOf(client);
if (index === -1) {
console.warn(
'Could not dispose notification service client. It was not registered.'
);
return;
}
this.clients.splice(index, 1);
}
dispose(): void {
for (const client of this.clients) {
this.disposeClient(client);
}
this.clients.length = 0;
}
}