Skip to content

Commit

Permalink
Fix themer not opening
Browse files Browse the repository at this point in the history
  • Loading branch information
n1ckoates committed Oct 18, 2024
1 parent acda359 commit 7ff28fc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
6 changes: 3 additions & 3 deletions plugins/Themer/src/editor.native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
11 changes: 7 additions & 4 deletions plugins/Themer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};

0 comments on commit 7ff28fc

Please sign in to comment.