-
-
Notifications
You must be signed in to change notification settings - Fork 438
/
Copy pathnotification-service-server.ts
69 lines (53 loc) · 2.32 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
import { injectable } from 'inversify';
import { NotificationServiceServer, NotificationServiceClient, AttachedBoardsChangeEvent, BoardsPackage, LibraryPackage, Config, Sketch } from '../common/protocol';
@injectable()
export class NotificationServiceServerImpl implements NotificationServiceServer {
protected readonly clients: NotificationServiceClient[] = [];
notifyIndexUpdated(): void {
this.clients.forEach(client => client.notifyIndexUpdated());
}
notifyDaemonStarted(): void {
this.clients.forEach(client => client.notifyDaemonStarted());
}
notifyDaemonStopped(): void {
this.clients.forEach(client => client.notifyDaemonStopped());
}
notifyPlatformInstalled(event: { item: BoardsPackage }): void {
this.clients.forEach(client => client.notifyPlatformInstalled(event));
}
notifyPlatformUninstalled(event: { item: BoardsPackage }): void {
this.clients.forEach(client => client.notifyPlatformUninstalled(event));
}
notifyLibraryInstalled(event: { item: LibraryPackage }): void {
this.clients.forEach(client => client.notifyLibraryInstalled(event));
}
notifyLibraryUninstalled(event: { item: LibraryPackage }): void {
this.clients.forEach(client => client.notifyLibraryUninstalled(event));
}
notifyAttachedBoardsChanged(event: AttachedBoardsChangeEvent): void {
this.clients.forEach(client => client.notifyAttachedBoardsChanged(event));
}
notifyConfigChanged(event: { config: Config | undefined }): void {
this.clients.forEach(client => client.notifyConfigChanged(event));
}
notifyRecentSketchesChanged(event: { sketches: Sketch[] }): void {
this.clients.forEach(client => client.notifyRecentSketchesChanged(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;
}
}