Files
Vesktop/src/preload/VesktopNative.ts

90 lines
4.0 KiB
TypeScript
Raw Normal View History

2023-04-09 22:49:50 +02:00
/*
2023-07-13 19:03:13 +02:00
* Vesktop, a desktop app aiming to give you a snappier Discord Experience
2023-04-09 22:49:50 +02:00
* Copyright (c) 2023 Vendicated and Vencord contributors
* SPDX-License-Identifier: GPL-3.0-or-later
2023-04-09 22:49:50 +02:00
*/
import { Node } from "@vencord/venmic";
2023-06-25 03:44:19 +02:00
import { ipcRenderer } from "electron";
2025-02-02 03:17:37 +01:00
import { IpcMessage, IpcResponse } from "main/ipcCommands";
import type { Settings } from "shared/settings";
2023-04-09 22:49:50 +02:00
2023-04-09 01:22:31 +02:00
import { IpcEvents } from "../shared/IpcEvents";
2023-06-26 00:41:52 +02:00
import { invoke, sendSync } from "./typedIpc";
2023-06-25 03:44:19 +02:00
type SpellCheckerResultCallback = (word: string, suggestions: string[]) => void;
const spellCheckCallbacks = new Set<SpellCheckerResultCallback>();
ipcRenderer.on(IpcEvents.SPELLCHECK_RESULT, (_, w: string, s: string[]) => {
spellCheckCallbacks.forEach(cb => cb(w, s));
});
2023-07-13 19:03:13 +02:00
export const VesktopNative = {
2023-04-04 01:35:37 +02:00
app: {
relaunch: () => invoke<void>(IpcEvents.RELAUNCH),
2023-06-23 17:20:54 +02:00
getVersion: () => sendSync<void>(IpcEvents.GET_VERSION),
setBadgeCount: (count: number) => invoke<void>(IpcEvents.SET_BADGE_COUNT, count),
supportsWindowsTransparency: () => sendSync<boolean>(IpcEvents.SUPPORTS_WINDOWS_TRANSPARENCY),
getEnableHardwareAcceleration: () => sendSync<boolean>(IpcEvents.GET_ENABLE_HARDWARE_ACCELERATION)
},
2023-06-21 16:13:20 +02:00
autostart: {
isEnabled: () => sendSync<boolean>(IpcEvents.AUTOSTART_ENABLED),
enable: () => invoke<void>(IpcEvents.ENABLE_AUTOSTART),
disable: () => invoke<void>(IpcEvents.DISABLE_AUTOSTART)
},
fileManager: {
showItemInFolder: (path: string) => invoke<void>(IpcEvents.SHOW_ITEM_IN_FOLDER, path),
getVencordDir: () => sendSync<string | undefined>(IpcEvents.GET_VENCORD_DIR),
selectVencordDir: (value?: null) => invoke<"cancelled" | "invalid" | "ok">(IpcEvents.SELECT_VENCORD_DIR, value)
},
settings: {
get: () => sendSync<Settings>(IpcEvents.GET_SETTINGS),
set: (settings: Settings, path?: string) => invoke<void>(IpcEvents.SET_SETTINGS, settings, path)
},
2023-04-14 04:05:56 +02:00
spellcheck: {
getAvailableLanguages: () => sendSync<string[]>(IpcEvents.SPELLCHECK_GET_AVAILABLE_LANGUAGES),
2023-06-25 03:44:19 +02:00
onSpellcheckResult(cb: SpellCheckerResultCallback) {
spellCheckCallbacks.add(cb);
},
offSpellcheckResult(cb: SpellCheckerResultCallback) {
spellCheckCallbacks.delete(cb);
},
replaceMisspelling: (word: string) => invoke<void>(IpcEvents.SPELLCHECK_REPLACE_MISSPELLING, word),
addToDictionary: (word: string) => invoke<void>(IpcEvents.SPELLCHECK_ADD_TO_DICTIONARY, word)
2023-04-14 04:05:56 +02:00
},
win: {
2023-08-07 00:23:27 +02:00
focus: () => invoke<void>(IpcEvents.FOCUS),
2024-01-18 21:33:17 +01:00
close: (key?: string) => invoke<void>(IpcEvents.CLOSE, key),
2025-04-05 02:44:47 +13:00
minimize: (key?: string) => invoke<void>(IpcEvents.MINIMIZE, key),
maximize: (key?: string) => invoke<void>(IpcEvents.MAXIMIZE, key)
2023-06-21 20:52:56 +02:00
},
capturer: {
getLargeThumbnail: (id: string) => invoke<string>(IpcEvents.CAPTURER_GET_LARGE_THUMBNAIL, id)
},
/** only available on Linux. */
virtmic: {
list: () =>
2024-04-20 16:09:40 +02:00
invoke<
{ ok: false; isGlibCxxOutdated: boolean } | { ok: true; targets: Node[]; hasPipewirePulse: boolean }
2024-04-20 16:09:40 +02:00
>(IpcEvents.VIRT_MIC_LIST),
start: (include: Node[]) => invoke<void>(IpcEvents.VIRT_MIC_START, include),
startSystem: (exclude: Node[]) => invoke<void>(IpcEvents.VIRT_MIC_START_SYSTEM, exclude),
stop: () => invoke<void>(IpcEvents.VIRT_MIC_STOP)
},
clipboard: {
copyImage: (imageBuffer: Uint8Array, imageSrc: string) =>
invoke<void>(IpcEvents.CLIPBOARD_COPY_IMAGE, imageBuffer, imageSrc)
},
debug: {
launchGpu: () => invoke<void>(IpcEvents.DEBUG_LAUNCH_GPU),
launchWebrtcInternals: () => invoke<void>(IpcEvents.DEBUG_LAUNCH_WEBRTC_INTERNALS)
2025-02-02 03:17:37 +01:00
},
commands: {
onCommand(cb: (message: IpcMessage) => void) {
ipcRenderer.on(IpcEvents.IPC_COMMAND, (_, message) => cb(message));
},
respond: (response: IpcResponse) => ipcRenderer.send(IpcEvents.IPC_COMMAND, response)
2023-04-04 01:35:37 +02:00
}
2023-04-09 22:49:50 +02:00
};