forked from mirror/Vesktop
Co-authored-by: V <vendicated@riseup.net> Co-authored-by: kaitlynkitty <87152313+kaitlynkittyy@users.noreply.github.com> Co-authored-by: Curve <fynnbwdt@gmail.com>
74 lines
3.1 KiB
TypeScript
74 lines
3.1 KiB
TypeScript
/*
|
|
* SPDX-License-Identifier: GPL-3.0
|
|
* Vesktop, 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 "./typedIpc";
|
|
|
|
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));
|
|
});
|
|
|
|
export const VesktopNative = {
|
|
app: {
|
|
relaunch: () => invoke<void>(IpcEvents.RELAUNCH),
|
|
getVersion: () => sendSync<void>(IpcEvents.GET_VERSION),
|
|
setBadgeCount: (count: number) => invoke<void>(IpcEvents.SET_BADGE_COUNT, count),
|
|
supportsWindowsTransparency: () => sendSync<boolean>(IpcEvents.SUPPORTS_WINDOWS_TRANSPARENCY)
|
|
},
|
|
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),
|
|
selectVencordDir: () => invoke<LiteralUnion<"cancelled" | "invalid", string>>(IpcEvents.SELECT_VENCORD_DIR)
|
|
},
|
|
settings: {
|
|
get: () => sendSync<Settings>(IpcEvents.GET_SETTINGS),
|
|
set: (settings: Settings, path?: string) => invoke<void>(IpcEvents.SET_SETTINGS, settings, path)
|
|
},
|
|
spellcheck: {
|
|
setLanguages: (languages: readonly string[]) => invoke<void>(IpcEvents.SPELLCHECK_SET_LANGUAGES, languages),
|
|
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)
|
|
},
|
|
win: {
|
|
focus: () => invoke<void>(IpcEvents.FOCUS),
|
|
close: () => invoke<void>(IpcEvents.CLOSE),
|
|
minimize: () => invoke<void>(IpcEvents.MINIMIZE),
|
|
maximize: () => invoke<void>(IpcEvents.MAXIMIZE)
|
|
},
|
|
capturer: {
|
|
getLargeThumbnail: (id: string) => invoke<string>(IpcEvents.CAPTURER_GET_LARGE_THUMBNAIL, id)
|
|
},
|
|
/** only available on Linux. */
|
|
virtmic: {
|
|
list: () => invoke<string[] | null>(IpcEvents.VIRT_MIC_LIST),
|
|
start: (target: string) => invoke<void>(IpcEvents.VIRT_MIC_START, target),
|
|
startSystem: () => invoke<void>(IpcEvents.VIRT_MIC_START_SYSTEM),
|
|
stop: () => invoke<void>(IpcEvents.VIRT_MIC_STOP)
|
|
},
|
|
arrpc: {
|
|
onActivity(cb: (data: string) => void) {
|
|
ipcRenderer.on(IpcEvents.ARRPC_ACTIVITY, (_, data: string) => cb(data));
|
|
}
|
|
}
|
|
};
|