fix(electron): respect locale for spellchecker (#8844)

may fix #8837.
fix AF-1712

MacOS automatically do spellcheck based on given text. This only works for Win/Linux.
![image.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/T2klNLEk0wxLh4NRDzhk/25058395-d70a-42a4-b869-c69fa71bc418.png)
This commit is contained in:
pengx17
2024-11-20 06:44:36 +00:00
parent 8689465e00
commit 47243247b9
3 changed files with 37 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
import { app, nativeTheme, shell } from 'electron';
import { getLinkPreview } from 'link-preview-js';
import { isMacOS } from '../../shared/utils';
import { persistentConfig } from '../config-storage/persist';
import { logger } from '../logger';
import type { WorkbenchViewMeta } from '../shared-state-schema';
@@ -220,4 +221,15 @@ export const uiHandlers = {
app.relaunch();
app.quit();
},
onLanguageChange: async (e, language: string) => {
// only works for win/linux
// see https://www.electronjs.org/docs/latest/tutorial/spellchecker#how-to-set-the-languages-the-spellchecker-uses
if (isMacOS()) {
return;
}
if (e.sender.session.availableSpellCheckerLanguages.includes(language)) {
e.sender.session.setSpellCheckerLanguages([language, 'en-US']);
}
},
} satisfies NamespaceHandlers;