Turn IpcEvents into a const enum
This commit is contained in:
parent
8f19d41d4c
commit
591d380160
4 changed files with 30 additions and 27 deletions
|
@ -3,39 +3,39 @@ import { readFileSync, watch } from "fs";
|
||||||
import { open, readFile } from "fs/promises";
|
import { open, readFile } from "fs/promises";
|
||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
import { debounce } from "shared/utils/debounce";
|
import { debounce } from "shared/utils/debounce";
|
||||||
import { FOCUS, GET_RENDERER_SCRIPT, GET_RENDERER_STYLES, GET_SETTINGS, GET_VENCORD_PRELOAD_FILE, RELAUNCH, SET_SETTINGS, SHOW_ITEM_IN_FOLDER } from "../shared/IpcEvents";
|
import { IpcEvents } from "../shared/IpcEvents";
|
||||||
import { VENCORD_FILES_DIR, VENCORD_QUICKCSS_FILE } from "./constants";
|
import { VENCORD_FILES_DIR, VENCORD_QUICKCSS_FILE } from "./constants";
|
||||||
import { mainWin } from "./mainWindow";
|
import { mainWin } from "./mainWindow";
|
||||||
import { PlainSettings, setSettings } from "./settings";
|
import { PlainSettings, setSettings } from "./settings";
|
||||||
|
|
||||||
ipcMain.on(GET_VENCORD_PRELOAD_FILE, e => {
|
ipcMain.on(IpcEvents.GET_VENCORD_PRELOAD_FILE, e => {
|
||||||
e.returnValue = join(VENCORD_FILES_DIR, "preload.js");
|
e.returnValue = join(VENCORD_FILES_DIR, "preload.js");
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on(GET_RENDERER_SCRIPT, e => {
|
ipcMain.on(IpcEvents.GET_RENDERER_SCRIPT, e => {
|
||||||
e.returnValue = readFileSync(join(__dirname, "renderer.js"), "utf-8");
|
e.returnValue = readFileSync(join(__dirname, "renderer.js"), "utf-8");
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle(GET_RENDERER_STYLES, () => readFile(join(__dirname, "renderer.css"), "utf-8"));
|
ipcMain.handle(IpcEvents.GET_RENDERER_STYLES, () => readFile(join(__dirname, "renderer.css"), "utf-8"));
|
||||||
|
|
||||||
ipcMain.on(GET_SETTINGS, e => {
|
ipcMain.on(IpcEvents.GET_SETTINGS, e => {
|
||||||
e.returnValue = PlainSettings;
|
e.returnValue = PlainSettings;
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle(SET_SETTINGS, (_, settings) => {
|
ipcMain.handle(IpcEvents.SET_SETTINGS, (_, settings) => {
|
||||||
setSettings(settings);
|
setSettings(settings);
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle(RELAUNCH, () => {
|
ipcMain.handle(IpcEvents.RELAUNCH, () => {
|
||||||
app.relaunch();
|
app.relaunch();
|
||||||
app.exit();
|
app.exit();
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle(SHOW_ITEM_IN_FOLDER, (_, path) => {
|
ipcMain.handle(IpcEvents.SHOW_ITEM_IN_FOLDER, (_, path) => {
|
||||||
shell.showItemInFolder(path);
|
shell.showItemInFolder(path);
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle(FOCUS, () => {
|
ipcMain.handle(IpcEvents.FOCUS, () => {
|
||||||
mainWin?.focus();
|
mainWin?.focus();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,21 +1,21 @@
|
||||||
import { app, ipcRenderer } from "electron";
|
import { app, ipcRenderer } from "electron";
|
||||||
import type { Settings } from "../main/settings";
|
import type { Settings } from "../main/settings";
|
||||||
import { FOCUS, GET_SETTINGS, RELAUNCH, SET_SETTINGS, SHOW_ITEM_IN_FOLDER } from "../shared/IpcEvents";
|
import { IpcEvents } from "../shared/IpcEvents";
|
||||||
|
|
||||||
export const VencordDesktopNative = {
|
export const VencordDesktopNative = {
|
||||||
app: {
|
app: {
|
||||||
relaunch: () => ipcRenderer.invoke(RELAUNCH),
|
relaunch: () => ipcRenderer.invoke(IpcEvents.RELAUNCH),
|
||||||
getVersion: () => app.getVersion()
|
getVersion: () => app.getVersion()
|
||||||
},
|
},
|
||||||
fileManager: {
|
fileManager: {
|
||||||
showItemInFolder: (path: string) => ipcRenderer.invoke(SHOW_ITEM_IN_FOLDER, path)
|
showItemInFolder: (path: string) => ipcRenderer.invoke(IpcEvents.SHOW_ITEM_IN_FOLDER, path)
|
||||||
},
|
},
|
||||||
settings: {
|
settings: {
|
||||||
get: () => ipcRenderer.sendSync(GET_SETTINGS),
|
get: () => ipcRenderer.sendSync(IpcEvents.GET_SETTINGS),
|
||||||
set: (settings: typeof Settings) => ipcRenderer.invoke(SET_SETTINGS, settings)
|
set: (settings: typeof Settings) => ipcRenderer.invoke(IpcEvents.SET_SETTINGS, settings)
|
||||||
},
|
},
|
||||||
win: {
|
win: {
|
||||||
focus: () => ipcRenderer.invoke(FOCUS)
|
focus: () => ipcRenderer.invoke(IpcEvents.FOCUS)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import { contextBridge, ipcRenderer, webFrame } from "electron";
|
import { contextBridge, ipcRenderer, webFrame } from "electron";
|
||||||
import { GET_RENDERER_SCRIPT, GET_RENDERER_STYLES, GET_VENCORD_PRELOAD_FILE } from "../shared/IpcEvents";
|
import { IpcEvents } from "../shared/IpcEvents";
|
||||||
import { VencordDesktopNative } from "./VencordDesktopNative";
|
import { VencordDesktopNative } from "./VencordDesktopNative";
|
||||||
|
|
||||||
contextBridge.exposeInMainWorld("VencordDesktopNative", VencordDesktopNative);
|
contextBridge.exposeInMainWorld("VencordDesktopNative", VencordDesktopNative);
|
||||||
|
|
||||||
require(ipcRenderer.sendSync(GET_VENCORD_PRELOAD_FILE));
|
require(ipcRenderer.sendSync(IpcEvents.GET_VENCORD_PRELOAD_FILE));
|
||||||
|
|
||||||
webFrame.executeJavaScript(ipcRenderer.sendSync(GET_RENDERER_SCRIPT));
|
webFrame.executeJavaScript(ipcRenderer.sendSync(IpcEvents.GET_RENDERER_SCRIPT));
|
||||||
ipcRenderer.invoke(GET_RENDERER_STYLES).then(s => webFrame.insertCSS(s));
|
ipcRenderer.invoke(IpcEvents.GET_RENDERER_STYLES).then(s => webFrame.insertCSS(s));
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
export const GET_VENCORD_PRELOAD_FILE = "VCD_GET_VC_PRELOAD_FILE";
|
export const enum IpcEvents {
|
||||||
export const GET_RENDERER_SCRIPT = "VCD_GET_RENDERER_SCRIPT";
|
GET_VENCORD_PRELOAD_FILE = "VCD_GET_VC_PRELOAD_FILE",
|
||||||
export const GET_RENDERER_STYLES = "VCD_GET_RENDERER_STYLES";
|
GET_RENDERER_SCRIPT = "VCD_GET_RENDERER_SCRIPT",
|
||||||
|
GET_RENDERER_STYLES = "VCD_GET_RENDERER_STYLES",
|
||||||
|
|
||||||
export const RELAUNCH = "VCD_RELAUNCH";
|
RELAUNCH = "VCD_RELAUNCH",
|
||||||
export const FOCUS = "VCD_FOCUS";
|
FOCUS = "VCD_FOCUS",
|
||||||
|
|
||||||
|
SHOW_ITEM_IN_FOLDER = "VCD_SHOW_ITEM_IN_FOLDER",
|
||||||
|
GET_SETTINGS = "VCD_GET_SETTINGS",
|
||||||
|
SET_SETTINGS = "VCD_SET_SETTINGS",
|
||||||
|
}
|
||||||
|
|
||||||
export const SHOW_ITEM_IN_FOLDER = "VCD_SHOW_ITEM_IN_FOLDER";
|
|
||||||
export const GET_SETTINGS = "VCD_GET_SETTINGS";
|
|
||||||
export const SET_SETTINGS = "VCD_SET_SETTINGS";
|
|
||||||
|
|
Loading…
Reference in a new issue