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 { join } from "path";
|
||||
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 { mainWin } from "./mainWindow";
|
||||
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");
|
||||
});
|
||||
|
||||
ipcMain.on(GET_RENDERER_SCRIPT, e => {
|
||||
ipcMain.on(IpcEvents.GET_RENDERER_SCRIPT, e => {
|
||||
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;
|
||||
});
|
||||
|
||||
ipcMain.handle(SET_SETTINGS, (_, settings) => {
|
||||
ipcMain.handle(IpcEvents.SET_SETTINGS, (_, settings) => {
|
||||
setSettings(settings);
|
||||
});
|
||||
|
||||
ipcMain.handle(RELAUNCH, () => {
|
||||
ipcMain.handle(IpcEvents.RELAUNCH, () => {
|
||||
app.relaunch();
|
||||
app.exit();
|
||||
});
|
||||
|
||||
ipcMain.handle(SHOW_ITEM_IN_FOLDER, (_, path) => {
|
||||
ipcMain.handle(IpcEvents.SHOW_ITEM_IN_FOLDER, (_, path) => {
|
||||
shell.showItemInFolder(path);
|
||||
});
|
||||
|
||||
ipcMain.handle(FOCUS, () => {
|
||||
ipcMain.handle(IpcEvents.FOCUS, () => {
|
||||
mainWin?.focus();
|
||||
});
|
||||
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
import { app, ipcRenderer } from "electron";
|
||||
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 = {
|
||||
app: {
|
||||
relaunch: () => ipcRenderer.invoke(RELAUNCH),
|
||||
relaunch: () => ipcRenderer.invoke(IpcEvents.RELAUNCH),
|
||||
getVersion: () => app.getVersion()
|
||||
},
|
||||
fileManager: {
|
||||
showItemInFolder: (path: string) => ipcRenderer.invoke(SHOW_ITEM_IN_FOLDER, path)
|
||||
showItemInFolder: (path: string) => ipcRenderer.invoke(IpcEvents.SHOW_ITEM_IN_FOLDER, path)
|
||||
},
|
||||
settings: {
|
||||
get: () => ipcRenderer.sendSync(GET_SETTINGS),
|
||||
set: (settings: typeof Settings) => ipcRenderer.invoke(SET_SETTINGS, settings)
|
||||
get: () => ipcRenderer.sendSync(IpcEvents.GET_SETTINGS),
|
||||
set: (settings: typeof Settings) => ipcRenderer.invoke(IpcEvents.SET_SETTINGS, settings)
|
||||
},
|
||||
win: {
|
||||
focus: () => ipcRenderer.invoke(FOCUS)
|
||||
focus: () => ipcRenderer.invoke(IpcEvents.FOCUS)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
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";
|
||||
|
||||
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));
|
||||
ipcRenderer.invoke(GET_RENDERER_STYLES).then(s => webFrame.insertCSS(s));
|
||||
webFrame.executeJavaScript(ipcRenderer.sendSync(IpcEvents.GET_RENDERER_SCRIPT));
|
||||
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 GET_RENDERER_SCRIPT = "VCD_GET_RENDERER_SCRIPT";
|
||||
export const GET_RENDERER_STYLES = "VCD_GET_RENDERER_STYLES";
|
||||
export const enum IpcEvents {
|
||||
GET_VENCORD_PRELOAD_FILE = "VCD_GET_VC_PRELOAD_FILE",
|
||||
GET_RENDERER_SCRIPT = "VCD_GET_RENDERER_SCRIPT",
|
||||
GET_RENDERER_STYLES = "VCD_GET_RENDERER_STYLES",
|
||||
|
||||
export const RELAUNCH = "VCD_RELAUNCH";
|
||||
export const FOCUS = "VCD_FOCUS";
|
||||
RELAUNCH = "VCD_RELAUNCH",
|
||||
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