haitop/src/preload/VencordDesktopNative.ts

38 lines
1.2 KiB
TypeScript
Raw Normal View History

2023-04-09 22:49:50 +02:00
/*
* SPDX-License-Identifier: GPL-3.0
* Vencord Desktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2023 Vendicated and Vencord contributors
*/
2023-04-09 03:06:19 +02:00
import { ipcRenderer } from "electron";
import type { Settings } from "shared/settings";
import type { LiteralUnion } from "type-fest";
2023-04-09 22:49:50 +02:00
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),
2023-04-09 03:06:19 +02:00
getVersion: () => sendSync<void>(IpcEvents.GET_VERSION)
},
fileManager: {
showItemInFolder: (path: string) => invoke<void>(IpcEvents.SHOW_ITEM_IN_FOLDER, path),
2023-04-09 22:49:50 +02:00
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
}
2023-04-09 22:49:50 +02:00
};