@@ -28,6 +28,17 @@ export class IpcController {
28
28
this . dispatch = options . dispatch ;
29
29
this . accountService = options . accountService ;
30
30
this . ipcHandlerRegistry = this . createIpcHandlerRegistry ( ) ;
31
+ this . registerHandlers ( this . ipcHandlerRegistry ) ;
32
+ }
33
+
34
+ /**
35
+ * Unregisters all ipc handlers and disconnects from the game server.
36
+ */
37
+ public async destroy ( ) : Promise < void > {
38
+ Object . keys ( this . ipcHandlerRegistry ) . forEach ( ( channel ) => {
39
+ ipcMain . removeHandler ( channel ) ;
40
+ } ) ;
41
+ await Game . getInstance ( ) ?. disconnect ( ) ;
31
42
}
32
43
33
44
private createIpcHandlerRegistry ( ) : IpcHandlerRegistry {
@@ -43,9 +54,9 @@ export class IpcController {
43
54
} ;
44
55
}
45
56
46
- public registerHandlers ( ) : void {
47
- Object . keys ( this . ipcHandlerRegistry ) . forEach ( ( channel ) => {
48
- const handler = this . ipcHandlerRegistry [ channel as IpcInvokableEvent ] ;
57
+ private registerHandlers ( registry : IpcHandlerRegistry ) : void {
58
+ Object . keys ( registry ) . forEach ( ( channel ) => {
59
+ const handler = registry [ channel as IpcInvokableEvent ] ;
49
60
50
61
if ( ! handler ) {
51
62
logger . error ( 'no handler registered for channel' , { channel } ) ;
@@ -68,13 +79,6 @@ export class IpcController {
68
79
} ) ;
69
80
}
70
81
71
- public deregisterHandlers ( ) : void {
72
- Object . keys ( this . ipcHandlerRegistry ) . forEach ( ( channel ) => {
73
- ipcMain . removeHandler ( channel ) ;
74
- ipcMain . removeAllListeners ( channel ) ;
75
- } ) ;
76
- }
77
-
78
82
private pingHandler : IpcInvokeHandler < 'ping' > = async ( ) : Promise < string > => {
79
83
return 'pong' ;
80
84
} ;
0 commit comments