/*
* 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 .
*/
import { IpcEvents } from "@utils/IpcEvents";
import { IpcRes } from "@utils/types";
import { ipcRenderer } from "electron";
function invoke(event: IpcEvents, ...args: any[]) {
return ipcRenderer.invoke(event, ...args) as Promise;
}
export function sendSync(event: IpcEvents, ...args: any[]) {
return ipcRenderer.sendSync(event, ...args) as T;
}
export default {
updater: {
getUpdates: () => invoke[]>>(IpcEvents.GET_UPDATES),
update: () => invoke>(IpcEvents.UPDATE),
rebuild: () => invoke>(IpcEvents.BUILD),
getRepo: () => invoke>(IpcEvents.GET_REPO),
},
settings: {
get: () => sendSync(IpcEvents.GET_SETTINGS),
set: (settings: string) => invoke(IpcEvents.SET_SETTINGS, settings),
getSettingsDir: () => invoke(IpcEvents.GET_SETTINGS_DIR),
},
quickCss: {
get: () => invoke(IpcEvents.GET_QUICK_CSS),
set: (css: string) => invoke(IpcEvents.SET_QUICK_CSS, css),
addChangeListener(cb: (newCss: string) => void) {
ipcRenderer.on(IpcEvents.QUICK_CSS_UPDATE, (_, css) => cb(css));
},
openFile: () => invoke(IpcEvents.OPEN_QUICKCSS),
openEditor: () => invoke(IpcEvents.OPEN_MONACO_EDITOR),
},
native: {
getVersions: () => process.versions as Partial,
openExternal: (url: string) => invoke(IpcEvents.OPEN_EXTERNAL, url)
},
pluginHelpers: {
OpenInApp: {
resolveRedirect: (url: string) => invoke(IpcEvents.OPEN_IN_APP__RESOLVE_REDIRECT, url),
},
VoiceMessages: {
readRecording: () => invoke(IpcEvents.VOICE_MESSAGES_READ_RECORDING),
}
}
};