Skip to content

Commit

Permalink
fix: exceptions for handlers already defined
Browse files Browse the repository at this point in the history
  • Loading branch information
notmedia committed Dec 7, 2022
1 parent a7e6e4f commit 7811511
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/app/pages/side-bar/collections-tree.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
10 changes: 8 additions & 2 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions src/main/ipc/clients/grpc-client/subscribers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions src/main/ipc/clients/grpc-web-client/subscribers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ export const registerGrpcWebClientSubscribers = (mainWindow: BrowserWindow) => {
server.registerServerStreamingHandlers();
unary.registerUnaryCallHandlers();
};

export const unregisterGrpcWebClientSubscribers = () => {
GrpcWebClientServerStreamingSubscriber.unregisterServerStreamingHandlers(ipcMain);
GrpcWebClientUnarySubscriber.unregisterUnaryCallHandlers(ipcMain);
};
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 7811511

Please sign in to comment.