-
-
Notifications
You must be signed in to change notification settings - Fork 427
/
Copy pathnotification-service-server.ts
109 lines (92 loc) · 2.93 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,
AttachedBoardsChangeEvent,
BoardsPackage,
LibraryPackage,
Config,
Sketch,
ProgressMessage,
ExampleRef,
} from '../common/protocol';
@injectable()
export class NotificationServiceServerImpl
implements NotificationServiceServer
{
private readonly clients: NotificationServiceClient[] = [];
notifyIndexWillUpdate(progressId: string): void {
this.clients.forEach((client) => client.notifyIndexWillUpdate(progressId));
}
notifyIndexUpdateDidProgress(progressMessage: ProgressMessage): void {
this.clients.forEach((client) =>
client.notifyIndexUpdateDidProgress(progressMessage)
);
}
notifyIndexDidUpdate(progressId: string): void {
this.clients.forEach((client) => client.notifyIndexDidUpdate(progressId));
}
notifyIndexUpdateDidFail({
progressId,
message,
}: {
progressId: string;
message: string;
}): void {
this.clients.forEach((client) =>
client.notifyIndexUpdateDidFail({ progressId, message })
);
}
notifyDaemonDidStart(port: string): 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 }): void {
this.clients.forEach((client) => client.notifyLibraryDidInstall(event));
}
notifyLibraryDidUninstall(event: { item: LibraryPackage }): void {
this.clients.forEach((client) => client.notifyLibraryDidUninstall(event));
}
notifyAttachedBoardsDidChange(event: AttachedBoardsChangeEvent): void {
this.clients.forEach((client) =>
client.notifyAttachedBoardsDidChange(event)
);
}
notifyConfigDidChange(event: { config: Config | undefined }): void {
this.clients.forEach((client) => client.notifyConfigDidChange(event));
}
notifyRecentSketchesDidChange(event: {
sketches: (Sketch | ExampleRef)[];
}): 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;
}
}