aboutsummaryrefslogtreecommitdiffstats
path: root/src/webview/spellchecker.ts
diff options
context:
space:
mode:
authorLibravatar Vijay Aravamudhan <vraravam@users.noreply.github.com>2021-09-21 02:17:28 +0530
committerLibravatar GitHub <noreply@github.com>2021-09-20 22:47:28 +0200
commita40f9e8eb9e536d554b699f2dc428cc532cbc6f6 (patch)
treec13eac23445b318219e9ec73ef28702cda8864b3 /src/webview/spellchecker.ts
parent5.6.3-nightly.8 [skip ci] (diff)
downloadferdium-app-a40f9e8eb9e536d554b699f2dc428cc532cbc6f6.tar.gz
ferdium-app-a40f9e8eb9e536d554b699f2dc428cc532cbc6f6.tar.zst
ferdium-app-a40f9e8eb9e536d554b699f2dc428cc532cbc6f6.zip
remove reference to '@electron/remote' module (for spell-checker) (#1968)
* fix: remove reference to '@electron/remote' module for spell-checker * chore: removed redundant methods from being exposed via 'window.ferdi' to the recipes
Diffstat (limited to 'src/webview/spellchecker.ts')
-rw-r--r--src/webview/spellchecker.ts26
1 files changed, 8 insertions, 18 deletions
diff --git a/src/webview/spellchecker.ts b/src/webview/spellchecker.ts
index d0f6663d5..468a1b4ae 100644
--- a/src/webview/spellchecker.ts
+++ b/src/webview/spellchecker.ts
@@ -1,35 +1,25 @@
1import { getCurrentWebContents } from '@electron/remote'; 1import { ipcRenderer } from 'electron';
2import { SPELLCHECKER_LOCALES } from '../i18n/languages'; 2import { SPELLCHECKER_LOCALES } from '../i18n/languages';
3import { DEFAULT_APP_SETTINGS, isMac } from '../environment'; 3import { isMac } from '../environment';
4 4
5const debug = require('debug')('Ferdi:spellchecker'); 5const debug = require('debug')('Ferdi:spellchecker');
6 6
7const { session } = getCurrentWebContents();
8const [defaultLocale] = session.getSpellCheckerLanguages();
9debug('Spellchecker default locale is', defaultLocale);
10
11export function getSpellcheckerLocaleByFuzzyIdentifier(identifier: string) { 7export function getSpellcheckerLocaleByFuzzyIdentifier(identifier: string) {
12 const locales = Object.keys(SPELLCHECKER_LOCALES).filter((key) => key.toLocaleLowerCase() === identifier.toLowerCase() || key.split('-')[0] === identifier.toLowerCase()); 8 const locales = Object.keys(SPELLCHECKER_LOCALES).filter((key) => key.toLocaleLowerCase() === identifier.toLowerCase() || key.split('-')[0] === identifier.toLowerCase());
13 9
14 return locales.length > 0 ? locales[0] : null; 10 return locales.length > 0 ? locales[0] : null;
15} 11}
16 12
17export function switchDict(locale: string) { 13export function switchDict(fuzzyLocale: string, serviceId: string) {
18 if (isMac) { 14 if (isMac) {
19 debug('Ignoring dictionary changes on macOS'); 15 debug('Ignoring dictionary changes on macOS');
20 return; 16 return;
21 } 17 }
22 18
23 debug('Setting spellchecker locale to', locale); 19 debug(`Setting spellchecker locale from: ${fuzzyLocale}`);
24 20 const locale = getSpellcheckerLocaleByFuzzyIdentifier(fuzzyLocale);
25 const locales: string[] = []; 21 if (locale) {
26 22 debug(`Sending spellcheck locales to host: ${locale}`);
27 const foundLocale = getSpellcheckerLocaleByFuzzyIdentifier(locale); 23 ipcRenderer.send('set-spellchecker-locales', { locale, serviceId });
28 if (foundLocale) {
29 locales.push(foundLocale);
30 } 24 }
31
32 locales.push(defaultLocale, DEFAULT_APP_SETTINGS.fallbackLocale);
33
34 session.setSpellCheckerLanguages(locales);
35} 25}