haitop/src/preload/VesktopNative.ts

75 lines
3.1 KiB
TypeScript
Raw Normal View History

2023-04-09 22:49:50 +02:00
/*
* SPDX-License-Identifier: GPL-3.0
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
*/
2023-06-25 03:44:19 +02:00
import { ipcRenderer } from "electron";
import type { Settings } from "shared/settings";
import type { LiteralUnion } from "type-fest";
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)
},
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),
2023-04-09 22:49:50 +02:00
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)
},
2023-04-14 04:05:56 +02:00
spellcheck: {
2023-06-25 03:44:19 +02:00
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)
2023-04-14 04:05:56 +02:00
},
win: {
2023-08-07 00:23:27 +02:00
focus: () => invoke<void>(IpcEvents.FOCUS),
close: () => invoke<void>(IpcEvents.CLOSE),
minimize: () => invoke<void>(IpcEvents.MINIMIZE),
maximize: () => invoke<void>(IpcEvents.MAXIMIZE)
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: () => 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));
}
2023-04-04 01:35:37 +02:00
}
2023-04-09 22:49:50 +02:00
};