From 11cf57ce92aff4dcdb504194ea5c381ac400c5c5 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Mon, 27 Dec 2021 02:24:22 +0100 Subject: refactor: Simplify IpcRendererService and its spec --- .../preload/src/services/IpcRendererService.ts | 42 ++++++++++++++++++++++ .../src/services/RendererToMainIpcService.ts | 42 ---------------------- 2 files changed, 42 insertions(+), 42 deletions(-) create mode 100644 packages/preload/src/services/IpcRendererService.ts delete mode 100644 packages/preload/src/services/RendererToMainIpcService.ts (limited to 'packages/preload/src/services') diff --git a/packages/preload/src/services/IpcRendererService.ts b/packages/preload/src/services/IpcRendererService.ts new file mode 100644 index 0000000..7f51351 --- /dev/null +++ b/packages/preload/src/services/IpcRendererService.ts @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2021-2022 Kristóf Marussy + * + * This file is part of Sophie. + * + * Sophie is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * SPDX-License-Identifier: AGPL-3.0-only + */ + +import { ipcRenderer } from 'electron'; +import { + Action, + MainToRendererIpcMessage, + RendererToMainIpcMessage, +} from '@sophie/shared'; + +export class IpcRendererService { + getSharedStoreSnapshot(): Promise { + return ipcRenderer.invoke(RendererToMainIpcMessage.GetSharedStoreSnapshot); + } + + dispatchAction(actionToDispatch: Action): void { + ipcRenderer.send(RendererToMainIpcMessage.DispatchAction, actionToDispatch); + } + + onSharedStorePatch(callback: (patch: unknown) => void): void { + ipcRenderer.on(MainToRendererIpcMessage.SharedStorePatch, (_event, patch) => { + callback(patch); + }) + } +} diff --git a/packages/preload/src/services/RendererToMainIpcService.ts b/packages/preload/src/services/RendererToMainIpcService.ts deleted file mode 100644 index 40f1339..0000000 --- a/packages/preload/src/services/RendererToMainIpcService.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2021-2022 Kristóf Marussy - * - * This file is part of Sophie. - * - * Sophie is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - * SPDX-License-Identifier: AGPL-3.0-only - */ - -import { ipcRenderer } from 'electron'; -import { - Action, - MainToRendererIpcMessage, - RendererToMainIpcMessage, -} from '@sophie/shared'; - -export class RendererToMainIpcService { - getSharedStoreSnapshot(): Promise { - return ipcRenderer.invoke(RendererToMainIpcMessage.GetSharedStoreSnapshot); - } - - dispatchAction(actionToDispatch: Action): void { - ipcRenderer.send(RendererToMainIpcMessage.DispatchAction, actionToDispatch); - } - - onSharedStorePatch(callback: (patch: unknown) => void): void { - ipcRenderer.on(MainToRendererIpcMessage.SharedStorePatch, (_event, patch) => { - callback(patch); - }) - } -} -- cgit v1.2.3-54-g00ecf