/* * 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 */ import { ipcRenderer } from "electron"; import type { Settings } from "shared/settings"; import type { LiteralUnion } from "type-fest"; import { IpcEvents } from "../shared/IpcEvents"; import { invoke, sendSync } from "./typedIpcs"; type SpellCheckerResultCallback = (word: string, suggestions: string[]) => void; const spellCheckCallbacks = new Set(); ipcRenderer.on(IpcEvents.SPELLCHECK_RESULT, (_, w: string, s: string[]) => { spellCheckCallbacks.forEach(cb => cb(w, s)); }); export const VencordDesktopNative = { app: { relaunch: () => invoke(IpcEvents.RELAUNCH), getVersion: () => sendSync(IpcEvents.GET_VERSION), setBadgeCount: (count: number) => invoke(IpcEvents.SET_BADGE_COUNT, count) }, autostart: { isEnabled: () => sendSync(IpcEvents.AUTOSTART_ENABLED), enable: () => invoke(IpcEvents.ENABLE_AUTOSTART), disable: () => invoke(IpcEvents.DISABLE_AUTOSTART) }, fileManager: { showItemInFolder: (path: string) => invoke(IpcEvents.SHOW_ITEM_IN_FOLDER, path), selectVencordDir: () => invoke>(IpcEvents.SELECT_VENCORD_DIR) }, settings: { get: () => sendSync(IpcEvents.GET_SETTINGS), set: (settings: Settings, path?: string) => invoke(IpcEvents.SET_SETTINGS, settings, path) }, spellcheck: { setLanguages: (languages: readonly string[]) => invoke(IpcEvents.SPELLCHECK_SET_LANGUAGES, languages), onSpellcheckResult(cb: SpellCheckerResultCallback) { spellCheckCallbacks.add(cb); }, offSpellcheckResult(cb: SpellCheckerResultCallback) { spellCheckCallbacks.delete(cb); }, replaceMisspelling: (word: string) => invoke(IpcEvents.SPELLCHECK_REPLACE_MISSPELLING, word), addToDictionary: (word: string) => invoke(IpcEvents.SPELLCHECK_ADD_TO_DICTIONARY, word) }, win: { focus: () => invoke(IpcEvents.FOCUS) }, capturer: { getLargeThumbnail: (id: string) => invoke(IpcEvents.CAPTURER_GET_LARGE_THUMBNAIL, id) } };