From 70dd38f79d9090e80dc95a4980ec5732d0726a5e Mon Sep 17 00:00:00 2001 From: Vendicated Date: Fri, 14 Apr 2023 04:05:56 +0200 Subject: [PATCH] make spellcheck use all system locales --- src/main/ipc.ts | 10 +++++++++- src/preload/VencordDesktopNative.ts | 4 ++++ src/preload/index.ts | 3 ++- src/shared/IpcEvents.ts | 2 ++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/ipc.ts b/src/main/ipc.ts index 83c4d58..5dc3479 100644 --- a/src/main/ipc.ts +++ b/src/main/ipc.ts @@ -4,7 +4,7 @@ * Copyright (c) 2023 Vendicated and Vencord contributors */ -import { app, dialog, ipcMain, shell } from "electron"; +import { app, dialog, ipcMain, session, shell } from "electron"; import { existsSync, readFileSync, watch } from "fs"; import { open, readFile } from "fs/promises"; import { join } from "path"; @@ -60,6 +60,14 @@ ipcMain.handle(IpcEvents.CLOSE, e => { e.sender.close(); }); +ipcMain.handle(IpcEvents.SPELLCHECK_SET_LANGUAGES, (_, languages: string[]) => { + const ses = session.defaultSession; + + const available = ses.availableSpellCheckerLanguages; + const applicable = languages.filter(l => available.includes(l)).slice(0, 3); + if (applicable.length) ses.setSpellCheckerLanguages(applicable); +}); + ipcMain.handle(IpcEvents.SELECT_VENCORD_DIR, async () => { const res = await dialog.showOpenDialog(mainWin!, { properties: ["openDirectory"] diff --git a/src/preload/VencordDesktopNative.ts b/src/preload/VencordDesktopNative.ts index a4a23f4..f6b0829 100644 --- a/src/preload/VencordDesktopNative.ts +++ b/src/preload/VencordDesktopNative.ts @@ -23,6 +23,10 @@ export const VencordDesktopNative = { get: () => sendSync(IpcEvents.GET_SETTINGS), set: (settings: Settings, path?: string) => invoke(IpcEvents.SET_SETTINGS, settings, path) }, + spellcheck: { + setLanguages: (languages: readonly string[]) => invoke(IpcEvents.SPELLCHECK_SET_LANGUAGES, languages) + // todo: perhaps add ways to learn words + }, win: { focus: () => invoke(IpcEvents.FOCUS) } diff --git a/src/preload/index.ts b/src/preload/index.ts index 039357a..5b40c2e 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -39,5 +39,6 @@ if (IS_DEV) { document.getElementById("vcd-css-core")!.textContent = readFileSync(rendererCss, "utf-8"); }); } - // #endregion + +VencordDesktopNative.spellcheck.setLanguages(window.navigator.languages); diff --git a/src/shared/IpcEvents.ts b/src/shared/IpcEvents.ts index 09ab674..9d1c75f 100644 --- a/src/shared/IpcEvents.ts +++ b/src/shared/IpcEvents.ts @@ -25,5 +25,7 @@ export const enum IpcEvents { UPDATER_DOWNLOAD = "VCD_UPDATER_DOWNLOAD", UPDATE_IGNORE = "VCD_UPDATE_IGNORE", + SPELLCHECK_SET_LANGUAGES = "VCD_SPELLCHECK_SET_LANGUAGES", + CLOSE = "VCD_CLOSE" }