Turn IpcEvents into a const enum

This commit is contained in:
Vendicated
2023-04-09 01:22:31 +02:00
parent 8f19d41d4c
commit 591d380160
4 changed files with 30 additions and 27 deletions

View File

@@ -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)
}
}

View File

@@ -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));