diff --git a/plugins/Themer/src/editor.native.ts b/plugins/Themer/src/editor.native.ts index 9744ad09..d429b1aa 100644 --- a/plugins/Themer/src/editor.native.ts +++ b/plugins/Themer/src/editor.native.ts @@ -2,9 +2,6 @@ import { BrowserWindow, shell, ipcMain } from "electron"; import editor from "file://editor.html?base64&minify"; import path from "path"; -ipcMain.removeHandler("THEMER_SET_CSS"); -ipcMain.handle("THEMER_SET_CSS", setCSS); - let win: BrowserWindow | null = null; export const openEditor = async (css: string) => { if (win && !win.isDestroyed()) return win.focus(); @@ -38,4 +35,7 @@ const setCSS = async (event: any, css: string) => { }); }; +ipcMain.removeHandler("THEMER_SET_CSS"); +ipcMain.handle("THEMER_SET_CSS", setCSS); + export const closeEditor = async () => win && !win.isDestroyed() && win.close(); diff --git a/plugins/Themer/src/index.ts b/plugins/Themer/src/index.ts index 9709ee76..3670c294 100644 --- a/plugins/Themer/src/index.ts +++ b/plugins/Themer/src/index.ts @@ -4,20 +4,23 @@ import { getStorage } from "@inrixia/lib/storage"; import { setStyle } from "@inrixia/lib/css/setStyle"; import { closeEditor, openEditor as openEditorNative } from "./editor.native"; +const setCSS = (_, css: string) => { + storage.css = css; + style.css = css; +} + const storage = getStorage({ css: "" }); export const openEditor = () => openEditorNative(storage.css); const style = setStyle(storage.css); -window.electron.ipcRenderer.on("THEMER_SET_CSS", (_, css: string) => { - storage.css = css; - style.css = css; -}); +window.electron.ipcRenderer.on("THEMER_SET_CSS", setCSS); const onKeyDown = (event: KeyboardEvent) => event.ctrlKey && event.key === "e" && openEditor(); document.addEventListener("keydown", onKeyDown); export const onUnload = () => { closeEditor(); + window.electron.ipcRenderer.removeAllListeners("THEMER_SET_CSS"); document.removeEventListener("keydown", onKeyDown); style.remove(); };