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";
|
2023-04-09 02:26:31 +02:00
|
|
|
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
|
|
|
|
2023-04-09 02:26:31 +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;
|
|
|
|
}
|
|
|
|
|
2023-04-09 01:20:00 +02:00
|
|
|
export const VencordDesktopNative = {
|
2023-04-04 01:35:37 +02:00
|
|
|
app: {
|
2023-04-09 02:26:31 +02:00
|
|
|
relaunch: () => invoke<void>(IpcEvents.RELAUNCH),
|
2023-04-09 03:06:19 +02:00
|
|
|
getVersion: () => sendSync<void>(IpcEvents.GET_VERSION)
|
2023-04-04 04:40:03 +02:00
|
|
|
},
|
2023-04-05 05:19:48 +02:00
|
|
|
fileManager: {
|
2023-04-09 02:26:31 +02:00
|
|
|
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)
|
2023-04-04 04:40:03 +02:00
|
|
|
},
|
|
|
|
settings: {
|
2023-04-09 02:26:31 +02:00
|
|
|
get: () => sendSync<Settings>(IpcEvents.GET_SETTINGS),
|
|
|
|
set: (settings: Settings) => invoke<void>(IpcEvents.SET_SETTINGS, settings)
|
2023-04-05 05:19:48 +02:00
|
|
|
},
|
|
|
|
win: {
|
2023-04-09 02:26:31 +02:00
|
|
|
focus: () => invoke<void>(IpcEvents.FOCUS)
|
2023-04-04 01:35:37 +02:00
|
|
|
}
|
2023-04-09 22:49:50 +02:00
|
|
|
};
|