From 781151101f55d3bf998c37c2c3dc59ba1c275a8a Mon Sep 17 00:00:00 2001 From: Alexey Vasyukov Date: Thu, 8 Dec 2022 00:24:41 +0300 Subject: [PATCH] fix: exceptions for handlers already defined --- src/app/pages/side-bar/collections-tree.tsx | 4 ++-- src/main/index.ts | 10 ++++++++-- .../subscribers/bidirectional-streaming.subscriber.ts | 7 +++++++ .../subscribers/client-streaming.subscriber.ts | 7 +++++++ src/main/ipc/clients/grpc-client/subscribers/index.ts | 7 +++++++ .../subscribers/server-streaming.subscriber.ts | 5 +++++ .../grpc-client/subscribers/unary.subscriber.ts | 4 ++++ .../ipc/clients/grpc-web-client/subscribers/index.ts | 5 +++++ .../subscribers/server-streaming.subscriber.ts | 5 +++++ .../grpc-web-client/subscribers/unary.subscriber.ts | 4 ++++ 10 files changed, 54 insertions(+), 4 deletions(-) diff --git a/src/app/pages/side-bar/collections-tree.tsx b/src/app/pages/side-bar/collections-tree.tsx index 7591e73..e495e5a 100644 --- a/src/app/pages/side-bar/collections-tree.tsx +++ b/src/app/pages/side-bar/collections-tree.tsx @@ -1,7 +1,7 @@ -import { FormElement, Input, styled, Text } from '@nextui-org/react'; +import { Container, FormElement, Input, Spacer, styled, Text } from '@nextui-org/react'; import React from 'react'; -import { Tree } from '@components'; +import { Kbd, Tree } from '@components'; import { Collection, CollectionType, useCollectionsStore } from '@storage'; import { StyledCollectionsTree } from './collections-tree.styled'; diff --git a/src/main/index.ts b/src/main/index.ts index acb278c..81e0140 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -8,6 +8,8 @@ import { registerOSSubscribers, registerProtobufSubscribers, unregisterDialogSubscribers, + unregisterGrpcClientSubscribers, + unregisterGrpcWebClientSubscribers, } from './ipc'; // This allows TypeScript to pick up the magic constant that's auto-generated by Forge's Webpack @@ -50,6 +52,12 @@ const createWindow = (): void => { registerDialogSubscribers(mainWindow); registerGrpcClientSubscribers(mainWindow); registerGrpcWebClientSubscribers(mainWindow); + + mainWindow.on('close', () => { + unregisterDialogSubscribers(); + unregisterGrpcClientSubscribers(); + unregisterGrpcWebClientSubscribers(); + }); }; // This method will be called when Electron has finished @@ -61,8 +69,6 @@ app.on('ready', createWindow); // for applications and their menu bar to stay active until the user quits // explicitly with Cmd + Q. app.on('window-all-closed', () => { - unregisterDialogSubscribers(); - if (process.platform !== 'darwin') { app.quit(); } diff --git a/src/main/ipc/clients/grpc-client/subscribers/bidirectional-streaming.subscriber.ts b/src/main/ipc/clients/grpc-client/subscribers/bidirectional-streaming.subscriber.ts index d0277a6..06933a5 100644 --- a/src/main/ipc/clients/grpc-client/subscribers/bidirectional-streaming.subscriber.ts +++ b/src/main/ipc/clients/grpc-client/subscribers/bidirectional-streaming.subscriber.ts @@ -14,6 +14,13 @@ export class GrpcClientBidirectionalSubscriber { constructor(private readonly mainWindow: BrowserWindow, private readonly ipcMain: IpcMain) {} + public static unregisterBidirectionalStreamingHandlers(ipcMain: IpcMain) { + ipcMain.removeHandler(GrpcClientChannel.INVOKE_BIDIRECTIONAL_STREAMING_REQUEST); + ipcMain.removeHandler(GrpcClientChannel.SEND_BIDIRECTIONAL_STREAMING_REQUEST); + ipcMain.removeHandler(GrpcClientChannel.END_BIDIRECTIONAL_STREAMING_REQUEST); + ipcMain.removeHandler(GrpcClientChannel.CANCEL_BIDIRECTIONAL_STREAMING_REQUEST); + } + public registerBidirectionalStreamingHandlers() { this.ipcMain.handle( GrpcClientChannel.INVOKE_BIDIRECTIONAL_STREAMING_REQUEST, diff --git a/src/main/ipc/clients/grpc-client/subscribers/client-streaming.subscriber.ts b/src/main/ipc/clients/grpc-client/subscribers/client-streaming.subscriber.ts index a4653b7..19486a1 100644 --- a/src/main/ipc/clients/grpc-client/subscribers/client-streaming.subscriber.ts +++ b/src/main/ipc/clients/grpc-client/subscribers/client-streaming.subscriber.ts @@ -11,6 +11,13 @@ export class GrpcClientClientStreamingSubscriber { constructor(private readonly mainWindow: BrowserWindow, private readonly ipcMain: IpcMain) {} + public static unregisterClientStreamingHandlers(ipcMain: IpcMain) { + ipcMain.removeHandler(GrpcClientChannel.INVOKE_CLIENT_STREAMING_REQUEST); + ipcMain.removeHandler(GrpcClientChannel.SEND_CLIENT_STREAMING_REQUEST); + ipcMain.removeHandler(GrpcClientChannel.END_CLIENT_STREAMING_REQUEST); + ipcMain.removeHandler(GrpcClientChannel.CANCEL_CLIENT_STREAMING_REQUEST); + } + public registerClientStreamingHandlers() { this.ipcMain.handle( GrpcClientChannel.INVOKE_CLIENT_STREAMING_REQUEST, diff --git a/src/main/ipc/clients/grpc-client/subscribers/index.ts b/src/main/ipc/clients/grpc-client/subscribers/index.ts index 13f3501..79801a9 100644 --- a/src/main/ipc/clients/grpc-client/subscribers/index.ts +++ b/src/main/ipc/clients/grpc-client/subscribers/index.ts @@ -16,3 +16,10 @@ export const registerGrpcClientSubscribers = (mainWindow: BrowserWindow) => { server.registerServerStreamingHandlers(); unary.registerUnaryCallHandlers(); }; + +export const unregisterGrpcClientSubscribers = () => { + GrpcClientBidirectionalSubscriber.unregisterBidirectionalStreamingHandlers(ipcMain); + GrpcClientClientStreamingSubscriber.unregisterClientStreamingHandlers(ipcMain); + GrpcClientServerStreamingSubscriber.unregisterServerStreamingHandlers(ipcMain); + GrpcClientUnarySubscriber.unregisterUnaryCallHandlers(ipcMain); +}; diff --git a/src/main/ipc/clients/grpc-client/subscribers/server-streaming.subscriber.ts b/src/main/ipc/clients/grpc-client/subscribers/server-streaming.subscriber.ts index 4729fc1..9b53ca0 100644 --- a/src/main/ipc/clients/grpc-client/subscribers/server-streaming.subscriber.ts +++ b/src/main/ipc/clients/grpc-client/subscribers/server-streaming.subscriber.ts @@ -11,6 +11,11 @@ export class GrpcClientServerStreamingSubscriber { constructor(private readonly mainWindow: BrowserWindow, private readonly ipcMain: IpcMain) {} + public static unregisterServerStreamingHandlers(ipcMain: IpcMain) { + ipcMain.removeHandler(GrpcClientChannel.INVOKE_SERVER_STREAMING_REQUEST); + ipcMain.removeHandler(GrpcClientChannel.CANCEL_SERVER_STREAMING_REQUEST); + } + public registerServerStreamingHandlers() { this.ipcMain.handle( GrpcClientChannel.INVOKE_SERVER_STREAMING_REQUEST, diff --git a/src/main/ipc/clients/grpc-client/subscribers/unary.subscriber.ts b/src/main/ipc/clients/grpc-client/subscribers/unary.subscriber.ts index 860475a..e846a2c 100644 --- a/src/main/ipc/clients/grpc-client/subscribers/unary.subscriber.ts +++ b/src/main/ipc/clients/grpc-client/subscribers/unary.subscriber.ts @@ -8,6 +8,10 @@ import { GrpcClientChannel } from '../constants'; export class GrpcClientUnarySubscriber { constructor(private readonly mainWindow: BrowserWindow, private readonly ipcMain: IpcMain) {} + public static unregisterUnaryCallHandlers(ipcMain: IpcMain) { + ipcMain.removeHandler(GrpcClientChannel.INVOKE_UNARY_REQUEST); + } + public registerUnaryCallHandlers() { this.ipcMain.handle( GrpcClientChannel.INVOKE_UNARY_REQUEST, diff --git a/src/main/ipc/clients/grpc-web-client/subscribers/index.ts b/src/main/ipc/clients/grpc-web-client/subscribers/index.ts index 12d80f0..7193909 100644 --- a/src/main/ipc/clients/grpc-web-client/subscribers/index.ts +++ b/src/main/ipc/clients/grpc-web-client/subscribers/index.ts @@ -10,3 +10,8 @@ export const registerGrpcWebClientSubscribers = (mainWindow: BrowserWindow) => { server.registerServerStreamingHandlers(); unary.registerUnaryCallHandlers(); }; + +export const unregisterGrpcWebClientSubscribers = () => { + GrpcWebClientServerStreamingSubscriber.unregisterServerStreamingHandlers(ipcMain); + GrpcWebClientUnarySubscriber.unregisterUnaryCallHandlers(ipcMain); +}; diff --git a/src/main/ipc/clients/grpc-web-client/subscribers/server-streaming.subscriber.ts b/src/main/ipc/clients/grpc-web-client/subscribers/server-streaming.subscriber.ts index f5dadc8..31d476d 100644 --- a/src/main/ipc/clients/grpc-web-client/subscribers/server-streaming.subscriber.ts +++ b/src/main/ipc/clients/grpc-web-client/subscribers/server-streaming.subscriber.ts @@ -17,6 +17,11 @@ export class GrpcWebClientServerStreamingSubscriber { constructor(private readonly mainWindow: BrowserWindow, private readonly ipcMain: IpcMain) {} + public static unregisterServerStreamingHandlers(ipcMain: IpcMain) { + ipcMain.removeHandler(GrpcWebClientChannel.INVOKE_SERVER_STREAMING_REQUEST); + ipcMain.removeHandler(GrpcWebClientChannel.CANCEL_SERVER_STREAMING_REQUEST); + } + public registerServerStreamingHandlers() { this.ipcMain.handle( GrpcWebClientChannel.INVOKE_SERVER_STREAMING_REQUEST, diff --git a/src/main/ipc/clients/grpc-web-client/subscribers/unary.subscriber.ts b/src/main/ipc/clients/grpc-web-client/subscribers/unary.subscriber.ts index 68aae44..1d71f50 100644 --- a/src/main/ipc/clients/grpc-web-client/subscribers/unary.subscriber.ts +++ b/src/main/ipc/clients/grpc-web-client/subscribers/unary.subscriber.ts @@ -13,6 +13,10 @@ import { GrpcWebClientChannel } from '../constants'; export class GrpcWebClientUnarySubscriber { constructor(private readonly mainWindow: BrowserWindow, private readonly ipcMain: IpcMain) {} + public static unregisterUnaryCallHandlers(ipcMain: IpcMain) { + ipcMain.removeHandler(GrpcWebClientChannel.INVOKE_UNARY_REQUEST); + } + public registerUnaryCallHandlers() { this.ipcMain.handle( GrpcWebClientChannel.INVOKE_UNARY_REQUEST,