2023-04-10 05:49:50 +09:00
|
|
|
/*
|
|
|
|
* SPDX-License-Identifier: GPL-3.0
|
2023-07-14 02:03:13 +09:00
|
|
|
* Vesktop, a desktop app aiming to give you a snappier Discord Experience
|
2023-04-10 05:49:50 +09:00
|
|
|
* Copyright (c) 2023 Vendicated and Vencord contributors
|
|
|
|
*/
|
|
|
|
|
2023-06-25 10:44:19 +09:00
|
|
|
import { ipcRenderer } from "electron";
|
2023-04-09 09:26:31 +09:00
|
|
|
import type { Settings } from "shared/settings";
|
|
|
|
import type { LiteralUnion } from "type-fest";
|
2023-04-10 05:49:50 +09:00
|
|
|
|
2023-04-09 08:22:31 +09:00
|
|
|
import { IpcEvents } from "../shared/IpcEvents";
|
2023-06-26 07:41:52 +09:00
|
|
|
import { invoke, sendSync } from "./typedIpc";
|
2023-04-09 09:26:31 +09:00
|
|
|
|
2023-06-25 10:44:19 +09: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-14 02:03:13 +09:00
|
|
|
export const VesktopNative = {
|
2023-04-04 08:35:37 +09:00
|
|
|
app: {
|
2023-04-09 09:26:31 +09:00
|
|
|
relaunch: () => invoke<void>(IpcEvents.RELAUNCH),
|
2023-06-24 00:20:54 +09:00
|
|
|
getVersion: () => sendSync<void>(IpcEvents.GET_VERSION),
|
2023-07-12 03:45:30 +09:00
|
|
|
setBadgeCount: (count: number) => invoke<void>(IpcEvents.SET_BADGE_COUNT, count),
|
|
|
|
supportsWindowsTransparency: () => sendSync<boolean>(IpcEvents.SUPPORTS_WINDOWS_TRANSPARENCY)
|
2023-04-04 11:40:03 +09:00
|
|
|
},
|
2023-06-21 23:13:20 +09:00
|
|
|
autostart: {
|
|
|
|
isEnabled: () => sendSync<boolean>(IpcEvents.AUTOSTART_ENABLED),
|
|
|
|
enable: () => invoke<void>(IpcEvents.ENABLE_AUTOSTART),
|
|
|
|
disable: () => invoke<void>(IpcEvents.DISABLE_AUTOSTART)
|
|
|
|
},
|
2023-04-05 12:19:48 +09:00
|
|
|
fileManager: {
|
2023-04-09 09:26:31 +09:00
|
|
|
showItemInFolder: (path: string) => invoke<void>(IpcEvents.SHOW_ITEM_IN_FOLDER, path),
|
2024-01-23 08:39:13 +09:00
|
|
|
selectVencordDir: () => invoke<LiteralUnion<"cancelled" | "invalid", string>>(IpcEvents.SELECT_VENCORD_DIR),
|
|
|
|
selectImagePath: () => invoke<LiteralUnion<"cancelled", string>>(IpcEvents.SELECT_IMAGE_PATH)
|
2023-04-04 11:40:03 +09:00
|
|
|
},
|
|
|
|
settings: {
|
2023-04-09 09:26:31 +09:00
|
|
|
get: () => sendSync<Settings>(IpcEvents.GET_SETTINGS),
|
2023-04-10 08:43:47 +09:00
|
|
|
set: (settings: Settings, path?: string) => invoke<void>(IpcEvents.SET_SETTINGS, settings, path)
|
2023-04-05 12:19:48 +09:00
|
|
|
},
|
2023-04-14 11:05:56 +09:00
|
|
|
spellcheck: {
|
2023-06-25 10:44:19 +09: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 11:05:56 +09:00
|
|
|
},
|
2023-04-05 12:19:48 +09:00
|
|
|
win: {
|
2023-08-07 07:23:27 +09:00
|
|
|
focus: () => invoke<void>(IpcEvents.FOCUS),
|
2024-01-19 05:33:17 +09:00
|
|
|
close: (key?: string) => invoke<void>(IpcEvents.CLOSE, key),
|
2023-08-07 07:23:27 +09:00
|
|
|
minimize: () => invoke<void>(IpcEvents.MINIMIZE),
|
|
|
|
maximize: () => invoke<void>(IpcEvents.MAXIMIZE)
|
2023-06-22 03:52:56 +09:00
|
|
|
},
|
|
|
|
capturer: {
|
|
|
|
getLargeThumbnail: (id: string) => invoke<string>(IpcEvents.CAPTURER_GET_LARGE_THUMBNAIL, id)
|
2023-10-13 11:00:28 +09:00
|
|
|
},
|
2023-10-22 05:15:55 +09:00
|
|
|
/** only available on Linux. */
|
|
|
|
virtmic: {
|
2023-10-27 07:27:35 +09:00
|
|
|
list: () =>
|
2024-05-09 02:34:24 +09:00
|
|
|
invoke<
|
|
|
|
{ ok: false; isGlibCxxOutdated: boolean } | { ok: true; targets: string[]; hasPipewirePulse: boolean }
|
|
|
|
>(IpcEvents.VIRT_MIC_LIST),
|
2024-01-29 00:55:46 +09:00
|
|
|
start: (targets: string[], workaround?: boolean) => invoke<void>(IpcEvents.VIRT_MIC_START, targets, workaround),
|
2024-05-09 02:34:24 +09:00
|
|
|
startSystem: (workaround?: boolean, onlyDefaultSpeakers?: boolean) =>
|
|
|
|
invoke<void>(IpcEvents.VIRT_MIC_START_SYSTEM, workaround, onlyDefaultSpeakers),
|
2023-10-22 05:15:55 +09:00
|
|
|
stop: () => invoke<void>(IpcEvents.VIRT_MIC_STOP)
|
|
|
|
},
|
2023-10-13 11:00:28 +09:00
|
|
|
arrpc: {
|
|
|
|
onActivity(cb: (data: string) => void) {
|
|
|
|
ipcRenderer.on(IpcEvents.ARRPC_ACTIVITY, (_, data: string) => cb(data));
|
|
|
|
}
|
2024-01-14 03:04:32 +09:00
|
|
|
},
|
|
|
|
clipboard: {
|
|
|
|
copyImage: (imageBuffer: Uint8Array, imageSrc: string) =>
|
|
|
|
invoke<void>(IpcEvents.CLIPBOARD_COPY_IMAGE, imageBuffer, imageSrc)
|
2023-04-04 08:35:37 +09:00
|
|
|
}
|
2023-04-10 05:49:50 +09:00
|
|
|
};
|