haitop/src/preload/VencordDesktopNative.ts

32 lines
1 KiB
TypeScript
Raw Normal View History

import { app, ipcRenderer } from "electron";
import type { Settings } from "shared/settings";
import type { LiteralUnion } from "type-fest";
2023-04-09 01:22:31 +02:00
import { IpcEvents } from "../shared/IpcEvents";
2023-04-04 01:35:37 +02:00
function invoke<T = any>(event: IpcEvents, ...args: any[]) {
return ipcRenderer.invoke(event, ...args) as Promise<T>;
}
function sendSync<T = any>(event: IpcEvents, ...args: any[]) {
return ipcRenderer.sendSync(event, ...args) as T;
}
export const VencordDesktopNative = {
2023-04-04 01:35:37 +02:00
app: {
relaunch: () => invoke<void>(IpcEvents.RELAUNCH),
getVersion: () => app.getVersion()
},
fileManager: {
showItemInFolder: (path: string) => invoke<void>(IpcEvents.SHOW_ITEM_IN_FOLDER, path),
selectVencordDir: () => invoke<LiteralUnion<"cancelled" | "invalid", string>>(IpcEvents.SELECT_VENCORD_DIR),
},
settings: {
get: () => sendSync<Settings>(IpcEvents.GET_SETTINGS),
set: (settings: Settings) => invoke<void>(IpcEvents.SET_SETTINGS, settings)
},
win: {
focus: () => invoke<void>(IpcEvents.FOCUS)
2023-04-04 01:35:37 +02:00
}
}