2022-10-21 23:17:06 +00:00
|
|
|
/*
|
2023-08-10 00:17:49 +00:00
|
|
|
* Vencord, a Discord client mod
|
|
|
|
* Copyright (c) 2023 Vendicated and contributors
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*/
|
2022-10-21 23:17:06 +00:00
|
|
|
|
2023-05-02 00:50:51 +00:00
|
|
|
import { IpcEvents } from "@utils/IpcEvents";
|
|
|
|
import { IpcRes } from "@utils/types";
|
|
|
|
import { ipcRenderer } from "electron";
|
2023-08-04 17:52:20 +00:00
|
|
|
import type { UserThemeHeader } from "main/themes";
|
2022-08-29 16:11:44 +00:00
|
|
|
|
2023-05-02 00:50:51 +00:00
|
|
|
function invoke<T = any>(event: IpcEvents, ...args: any[]) {
|
|
|
|
return ipcRenderer.invoke(event, ...args) as Promise<T>;
|
2022-08-31 20:08:05 +00:00
|
|
|
}
|
2023-05-02 00:50:51 +00:00
|
|
|
|
|
|
|
export function sendSync<T = any>(event: IpcEvents, ...args: any[]) {
|
|
|
|
return ipcRenderer.sendSync(event, ...args) as T;
|
|
|
|
}
|
|
|
|
|
2022-08-29 16:11:44 +00:00
|
|
|
export default {
|
2023-08-04 17:52:20 +00:00
|
|
|
themes: {
|
|
|
|
uploadTheme: (fileName: string, fileData: string) => invoke<void>(IpcEvents.UPLOAD_THEME, fileName, fileData),
|
|
|
|
deleteTheme: (fileName: string) => invoke<void>(IpcEvents.DELETE_THEME, fileName),
|
|
|
|
getThemesDir: () => invoke<string>(IpcEvents.GET_THEMES_DIR),
|
|
|
|
getThemesList: () => invoke<Array<UserThemeHeader>>(IpcEvents.GET_THEMES_LIST),
|
2023-09-25 16:53:10 +00:00
|
|
|
getThemeData: (fileName: string) => invoke<string | undefined>(IpcEvents.GET_THEME_DATA, fileName),
|
|
|
|
getSystemValues: () => invoke<Record<string, string>>(IpcEvents.GET_THEME_SYSTEM_VALUES),
|
2023-08-04 17:52:20 +00:00
|
|
|
},
|
|
|
|
|
2023-05-02 00:50:51 +00:00
|
|
|
updater: {
|
|
|
|
getUpdates: () => invoke<IpcRes<Record<"hash" | "author" | "message", string>[]>>(IpcEvents.GET_UPDATES),
|
|
|
|
update: () => invoke<IpcRes<boolean>>(IpcEvents.UPDATE),
|
|
|
|
rebuild: () => invoke<IpcRes<boolean>>(IpcEvents.BUILD),
|
|
|
|
getRepo: () => invoke<IpcRes<string>>(IpcEvents.GET_REPO),
|
|
|
|
},
|
|
|
|
|
|
|
|
settings: {
|
|
|
|
get: () => sendSync<string>(IpcEvents.GET_SETTINGS),
|
|
|
|
set: (settings: string) => invoke<void>(IpcEvents.SET_SETTINGS, settings),
|
|
|
|
getSettingsDir: () => invoke<string>(IpcEvents.GET_SETTINGS_DIR),
|
|
|
|
},
|
|
|
|
|
|
|
|
quickCss: {
|
|
|
|
get: () => invoke<string>(IpcEvents.GET_QUICK_CSS),
|
|
|
|
set: (css: string) => invoke<void>(IpcEvents.SET_QUICK_CSS, css),
|
|
|
|
|
|
|
|
addChangeListener(cb: (newCss: string) => void) {
|
|
|
|
ipcRenderer.on(IpcEvents.QUICK_CSS_UPDATE, (_, css) => cb(css));
|
2022-08-31 02:07:16 +00:00
|
|
|
},
|
2023-05-02 00:50:51 +00:00
|
|
|
|
2023-08-04 17:52:20 +00:00
|
|
|
addThemeChangeListener(cb: () => void) {
|
2023-08-25 12:57:04 +00:00
|
|
|
ipcRenderer.on(IpcEvents.THEME_UPDATE, () => cb());
|
2023-08-04 17:52:20 +00:00
|
|
|
},
|
|
|
|
|
2023-05-02 00:50:51 +00:00
|
|
|
openFile: () => invoke<void>(IpcEvents.OPEN_QUICKCSS),
|
|
|
|
openEditor: () => invoke<void>(IpcEvents.OPEN_MONACO_EDITOR),
|
|
|
|
},
|
|
|
|
|
|
|
|
native: {
|
|
|
|
getVersions: () => process.versions as Partial<NodeJS.ProcessVersions>,
|
|
|
|
openExternal: (url: string) => invoke<void>(IpcEvents.OPEN_EXTERNAL, url)
|
|
|
|
},
|
2023-06-29 14:06:21 +00:00
|
|
|
|
|
|
|
pluginHelpers: {
|
|
|
|
OpenInApp: {
|
|
|
|
resolveRedirect: (url: string) => invoke<string>(IpcEvents.OPEN_IN_APP__RESOLVE_REDIRECT, url),
|
|
|
|
},
|
2023-07-25 23:27:04 +00:00
|
|
|
VoiceMessages: {
|
2023-07-26 23:56:45 +00:00
|
|
|
readRecording: (path: string) => invoke<Uint8Array | null>(IpcEvents.VOICE_MESSAGES_READ_RECORDING, path),
|
2023-07-25 23:27:04 +00:00
|
|
|
}
|
2023-06-29 14:06:21 +00:00
|
|
|
}
|
2022-09-16 20:59:34 +00:00
|
|
|
};
|