2022-10-21 19:17:06 -04:00
|
|
|
/*
|
|
|
|
* Vencord, a modification for Discord's desktop app
|
|
|
|
* Copyright (c) 2022
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2023-05-01 20:50:51 -04:00
|
|
|
import { IpcEvents } from "@utils/IpcEvents";
|
|
|
|
import { IpcRes } from "@utils/types";
|
|
|
|
import { ipcRenderer } from "electron";
|
2022-08-29 12:11:44 -04:00
|
|
|
|
2023-05-01 20:50:51 -04:00
|
|
|
function invoke<T = any>(event: IpcEvents, ...args: any[]) {
|
|
|
|
return ipcRenderer.invoke(event, ...args) as Promise<T>;
|
2022-08-31 16:08:05 -04:00
|
|
|
}
|
2023-05-01 20:50:51 -04:00
|
|
|
|
|
|
|
export function sendSync<T = any>(event: IpcEvents, ...args: any[]) {
|
|
|
|
return ipcRenderer.sendSync(event, ...args) as T;
|
|
|
|
}
|
|
|
|
|
2022-08-29 12:11:44 -04:00
|
|
|
export default {
|
2023-05-01 20:50:51 -04: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-30 22:07:16 -04:00
|
|
|
},
|
2023-05-01 20:50:51 -04: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 10:06:21 -04:00
|
|
|
|
|
|
|
pluginHelpers: {
|
|
|
|
OpenInApp: {
|
|
|
|
resolveRedirect: (url: string) => invoke<string>(IpcEvents.OPEN_IN_APP__RESOLVE_REDIRECT, url),
|
|
|
|
},
|
|
|
|
}
|
2022-09-16 16:59:34 -04:00
|
|
|
};
|