/* * Vesktop, a desktop app aiming to give you a snappier Discord Experience * Copyright (c) 2023 Vendicated and Vencord contributors * SPDX-License-Identifier: GPL-3.0-or-later */ import { Node } from "@vencord/venmic"; import { ipcRenderer } from "electron"; import { IpcMessage, IpcResponse } from "main/ipcCommands"; import type { Settings } from "shared/settings"; import { IpcEvents } from "../shared/IpcEvents"; import { invoke, sendSync } from "./typedIpc"; 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)); }); let onDevtoolsOpen = () => {}; let onDevtoolsClose = () => {}; ipcRenderer.on(IpcEvents.DEVTOOLS_OPENED, () => onDevtoolsOpen()); ipcRenderer.on(IpcEvents.DEVTOOLS_CLOSED, () => onDevtoolsClose()); export const VesktopNative = { app: { relaunch: () => invoke(IpcEvents.RELAUNCH), getVersion: () => sendSync(IpcEvents.GET_VERSION), setBadgeCount: (count: number) => invoke(IpcEvents.SET_BADGE_COUNT, count), supportsWindowsTransparency: () => sendSync(IpcEvents.SUPPORTS_WINDOWS_TRANSPARENCY), getEnableHardwareAcceleration: () => sendSync(IpcEvents.GET_ENABLE_HARDWARE_ACCELERATION), isOutdated: () => invoke(IpcEvents.UPDATER_IS_OUTDATED), openUpdater: () => invoke(IpcEvents.UPDATER_OPEN) }, 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), getVencordDir: () => sendSync(IpcEvents.GET_VENCORD_DIR), selectVencordDir: (value?: null) => invoke<"cancelled" | "invalid" | "ok">(IpcEvents.SELECT_VENCORD_DIR, value), chooseUserAsset: (asset: string, value?: null) => invoke<"cancelled" | "invalid" | "ok" | "failed">(IpcEvents.CHOOSE_USER_ASSET, asset, value) }, settings: { get: () => sendSync(IpcEvents.GET_SETTINGS), set: (settings: Settings, path?: string) => invoke(IpcEvents.SET_SETTINGS, settings, path) }, spellcheck: { getAvailableLanguages: () => sendSync(IpcEvents.SPELLCHECK_GET_AVAILABLE_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), close: (key?: string) => invoke(IpcEvents.CLOSE, key), minimize: (key?: string) => invoke(IpcEvents.MINIMIZE, key), maximize: (key?: string) => invoke(IpcEvents.MAXIMIZE, key), setDevtoolsCallbacks: (onOpen: () => void, onClose: () => void) => { onDevtoolsOpen = onOpen; onDevtoolsClose = onClose; } }, capturer: { getLargeThumbnail: (id: string) => invoke(IpcEvents.CAPTURER_GET_LARGE_THUMBNAIL, id) }, /** only available on Linux. */ virtmic: { list: () => invoke< { ok: false; isGlibCxxOutdated: boolean } | { ok: true; targets: Node[]; hasPipewirePulse: boolean } >(IpcEvents.VIRT_MIC_LIST), start: (include: Node[]) => invoke(IpcEvents.VIRT_MIC_START, include), startSystem: (exclude: Node[]) => invoke(IpcEvents.VIRT_MIC_START_SYSTEM, exclude), stop: () => invoke(IpcEvents.VIRT_MIC_STOP) }, clipboard: { copyImage: (imageBuffer: Uint8Array, imageSrc: string) => invoke(IpcEvents.CLIPBOARD_COPY_IMAGE, imageBuffer, imageSrc) }, debug: { launchGpu: () => invoke(IpcEvents.DEBUG_LAUNCH_GPU), launchWebrtcInternals: () => invoke(IpcEvents.DEBUG_LAUNCH_WEBRTC_INTERNALS) }, commands: { onCommand(cb: (message: IpcMessage) => void) { ipcRenderer.on(IpcEvents.IPC_COMMAND, (_, message) => cb(message)); }, respond: (response: IpcResponse) => ipcRenderer.send(IpcEvents.IPC_COMMAND, response) } };