fix(desktop): configure composer spellcheck languages #7745
Closedhevlyo(GitHub profile, opens in a new tab)wants to merge 6 commits into
main fromrefs/pull/7745/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/desktop/src/electron/ElectronSpellcheck.ts lines 100 to 103OutdatedResolvedby hevlyo(GitHub profile, opens in a new tab)@@ -0,0 +83,21 @@83+ }84+ }85+ return layouts;86+}87+88+export function keyboardLayoutsFromVconsole(contents: string): string[] {89+ const layouts: string[] = [];90+ for (const line of contents.split(/\r?\n/)) {91+ const trimmed = line.trim();92+ if (trimmed.length === 0 || trimmed.startsWith("#")) {93+ continue;94+ }95+ const separator = trimmed.indexOf("=");96+ if (separator < 0) {97+ continue;98+ }99+ const key = trimmed.slice(0, separator).trim();100+ const value = trimmed101+ .slice(separator + 1)102+ .trim()103+ .replaceAll('"', "");
- apps/desktop/src/electron/ElectronSpellcheck.ts line 295OutdatedResolvedby hevlyo(GitHub profile, opens in a new tab)@@ -0,0 +275,21 @@275+ const clientSettings = yield* DesktopClientSettings.DesktopClientSettings;276+ const electronApp = yield* ElectronApp.ElectronApp;277+ const fileSystem = yield* FileSystem.FileSystem;278+ const settings = Option.getOrElse(yield* clientSettings.get, () => DEFAULT_CLIENT_SETTINGS);279+ const systemLocale = yield* electronApp.systemLocale;280+ const vconsole =281+ environment.platform === "linux"282+ ? yield* fileSystem283+ .readFileString("/etc/vconsole.conf")284+ .pipe(Effect.orElseSucceed(() => ""))285+ : "";286+ yield* Effect.try({287+ try: () =>288+ applySpellCheckerSession(window.webContents.session, {289+ enabled: settings.spellcheckEnabled,290+ configuredLanguages: settings.spellcheckLanguages,291+ systemLocale,292+ env: process.env,293+ vconsole,294+ }),295+ catch: (cause) => ({ cause }),
- apps/desktop/src/electron/ElectronSpellcheck.ts lines 281 to 285OutdatedResolvedby hevlyo(GitHub profile, opens in a new tab)@@ -0,0 +265,21 @@265+ }266+ return { languages };267+}268+269+export const syncBrowserWindowSpellChecker = (window: Electron.BrowserWindow) =>270+ Effect.gen(function* () {271+ if (window.isDestroyed()) {272+ return;273+ }274+ const environment = yield* DesktopEnvironment.DesktopEnvironment;275+ const clientSettings = yield* DesktopClientSettings.DesktopClientSettings;276+ const electronApp = yield* ElectronApp.ElectronApp;277+ const fileSystem = yield* FileSystem.FileSystem;278+ const settings = Option.getOrElse(yield* clientSettings.get, () => DEFAULT_CLIENT_SETTINGS);279+ const systemLocale = yield* electronApp.systemLocale;280+ const vconsole =281+ environment.platform === "linux"282+ ? yield* fileSystem283+ .readFileString("/etc/vconsole.conf")284+ .pipe(Effect.orElseSucceed(() => ""))285+ : "";apps/desktop/src/electron/ElectronSpellcheck.ts lines 118 to 122OutdatedResolvedby hevlyo(GitHub profile, opens in a new tab)@@ -0,0 +102,21 @@102+ .trim()103+ .replaceAll('"', "");104+ if (key === "XKBLAYOUT") {105+ layouts.push(...parseXkbLayouts(value));106+ continue;107+ }108+ if (key === "KEYMAP") {109+ const base = value.toLowerCase().split(".")[0]?.split("-")[0];110+ if (base !== undefined && base.length > 0) {111+ layouts.push(base);112+ }113+ }114+ }115+ return layouts;116+}117+118+export function keyboardLayoutsFromEnvironment(env: NodeJS.Dict<string>): string[] {119+ return [120+ ...parseXkbLayouts(env.XKBLAYOUT ?? ""),121+ ...parseXkbLayouts(env.XKB_DEFAULT_LAYOUT ?? ""),122+ ];
- apps/web/src/components/settings/SettingsPanels.tsx line 117Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -114,3 +114,4 @@114114 NumberFieldInput,115115 } from "../ui/number-field";116116 import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "../ui/select";117+import { Checkbox } from "../ui/checkbox";
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
hevlyo(GitHub profile, opens in a new tab) changed the title
- apps/desktop/src/ipc/methods/clientSettings.ts line 39OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -23,4 +25,15 @@2325 result: Schema.Void,2426 handler: Effect.fn("desktop.ipc.clientSettings.set")(function* (settings) {2527 const clientSettings = yield* DesktopClientSettings.DesktopClientSettings;28+ const previousSettings = yield* clientSettings.get;2629 yield* clientSettings.set(settings);30+ if (31+ Option.isSome(previousSettings) &&32+ ElectronSpellcheck.spellcheckSettingsEqual(previousSettings.value, settings)33+ ) {34+ return;35+ }36+ const electronWindow = yield* ElectronWindow.ElectronWindow;37+ const window = yield* electronWindow.currentMainOrFirst;38+ if (Option.isSome(window)) {39+ yield* ElectronSpellcheck.syncBrowserWindowSpellChecker(window.value, settings);
- apps/desktop/src/electron/ElectronApp.ts lines 138 to 140Resolvedby hevlyo(GitHub profile, opens in a new tab)@@ -130,3 +135,6 @@130135 // (`en_GB`). `Intl` rejects those outright rather than normalizing them, so131136 // the tag is normalized here rather than in the renderer that consumes it.132137 systemLocale: Effect.sync(() => Electron.app.getSystemLocale().replace(/_/g, "-")),138+ preferredSystemLanguages: Effect.sync(() =>139+ Electron.app.getPreferredSystemLanguages().map((language) => language.replace(/_/g, "-")),140+ ),
- apps/desktop/src/electron/ElectronSpellcheck.ts lines 282 to 284Resolvedby hevlyo(GitHub profile, opens in a new tab)@@ -0,0 +262,21 @@262+ const exact = availableByLower.get(preferredLower);263+ if (exact !== undefined) {264+ return exact;265+ }266+ const language = preferredLower.split("-")[0] ?? preferredLower;267+ if (preferredLower.includes("-")) {268+ const languageOnly = availableByLower.get(language);269+ if (languageOnly !== undefined) {270+ return languageOnly;271+ }272+ }273+ const regional = available.filter(274+ (candidate) =>275+ candidate.toLowerCase() === language || candidate.toLowerCase().startsWith(`${language}-`),276+ );277+ if (regional.length === 0) {278+ return undefined;279+ }280+ const us = regional.find((candidate) => candidate.toLowerCase() === `${language}-us`);281+ if (us !== undefined) {282+ return us;
- apps/desktop/src/window/DesktopWindow.ts line 73Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -66,3 +69,5 @@6669 | ElectronShell.ElectronShell6770 | ElectronTheme.ElectronTheme6871 | ElectronWindow.ElectronWindow72+ | FileSystem.FileSystem73+ | ChildProcessSpawner.ChildProcessSpawner
- apps/web/src/components/settings/SettingsPanels.tsx lines 1407 to 1407OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1321,0 +1387,21 @@1387+ <SettingResetButton1388+ label="spelling"1389+ onClick={() =>1390+ updateSettings({1391+ spellcheckEnabled: DEFAULT_UNIFIED_SETTINGS.spellcheckEnabled,1392+ spellcheckLanguages: DEFAULT_UNIFIED_SETTINGS.spellcheckLanguages,1393+ })1394+ }1395+ />1396+ ) : null1397+ }1398+ control={1399+ <Switch1400+ checked={settings.spellcheckEnabled}1401+ onCheckedChange={(checked) => updateSettings({ spellcheckEnabled: Boolean(checked) })}1402+ aria-label="Check spelling in the composer"1403+ />1404+ }1405+ >1406+ {canSelectLanguages && settings.spellcheckEnabled ? (1407+ <div className="space-y-2 pt-3">
- apps/desktop/src/window/DesktopWindow.ts line 383OutdatedResolvedby hevlyo(GitHub profile, opens in a new tab)@@ -375,3 +380,4 @@375380 if (environment.platform === "darwin") {376381 window.setAutoHideCursor(false);377382 }383+ yield* syncBrowserWindowSpellChecker(window).pipe(Effect.provide(context));
juliusmarminge closed this
Sign in to join this conversation.



Note
Reviews paused#
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
reviews.auto_review.auto_pause_after_reviewed_commitssetting.Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.Use the checkboxes below for quick actions:
📝 Walkthrough
Walkthrough#
This PR adds persisted spellcheck settings, platform language discovery, Electron session synchronization, synchronous IPC access, and web controls. It uses explicit languages, keyboard layouts, system preferences, and platform-specific behavior.
Changes#
Desktop spellcheck configuration
packages/contracts/src/settings.ts,packages/contracts/src/ipc.ts,packages/contracts/src/*test.tsapps/desktop/src/electron/*,apps/desktop/src/app/*test.ts,apps/desktop/src/telemetry/*test.ts,apps/desktop/src/window/DesktopApplicationMenu.test.tsapps/desktop/src/window/DesktopWindow*,apps/desktop/src/ipc/methods/clientSettings*apps/desktop/src/ipc/channels.ts,apps/desktop/src/ipc/DesktopIpcHandlers.ts,apps/desktop/src/ipc/methods/window*,apps/desktop/src/preload.tsapps/web/src/components/settings/*,apps/web/src/components/ComposerPromptEditor.tsx,docs/user/composer.mdEstimated code review effort: 4 (Complex) | ~60 minutes
Merge Risk: 🟡 Moderate · up to
f5290This change adds platform-aware spellcheck selection and persistence, but automatic detection can still choose the wrong dictionary for some bare
cakeyboard layouts, and the unavailable-dictionary state is not fully exposed to assistive technologies. A failed synchronization can also leave saved and active spellcheck settings temporarily different, so merge should wait for these issues to be fixed or explicitly accepted.Sequence Diagram(s)#
Suggested reviewers:
juliusmarminge🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
✅ Passed checks (4 passed)
#7742with language selection, spellcheck controls, keyboard-layout detection, and fallback prevention.✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share