aboutsummaryrefslogtreecommitdiffstats
path: root/src/webview/spellchecker.js
diff options
context:
space:
mode:
authorLibravatar Amine El Mouafik <412895+kytwb@users.noreply.github.com>2021-02-08 10:34:45 +0100
committerLibravatar GitHub <noreply@github.com>2021-02-08 10:34:45 +0100
commit035002ceedf78d5ec73eabc0df7f06139939b967 (patch)
tree1c0d1e9531bae05fb65d70b9ea25baf404b74fe1 /src/webview/spellchecker.js
parentdocs: add k0staa as a contributor (#1193) (diff)
downloadferdium-app-035002ceedf78d5ec73eabc0df7f06139939b967.tar.gz
ferdium-app-035002ceedf78d5ec73eabc0df7f06139939b967.tar.zst
ferdium-app-035002ceedf78d5ec73eabc0df7f06139939b967.zip
Synchronize with Franz 5.6.0 (#1033)
Co-authored-by: FranzBot <i18n@meetfranz.com> Co-authored-by: vantezzen <hello@vantezzen.io> Co-authored-by: Makazzz <makazzzpro@live.ca> Co-authored-by: Stefan Malzner <stefan@adlk.io> Co-authored-by: Amine Mouafik <amine@mouafik.fr>
Diffstat (limited to 'src/webview/spellchecker.js')
-rw-r--r--src/webview/spellchecker.js73
1 files changed, 25 insertions, 48 deletions
diff --git a/src/webview/spellchecker.js b/src/webview/spellchecker.js
index 287c9cf11..e7ef102e9 100644
--- a/src/webview/spellchecker.js
+++ b/src/webview/spellchecker.js
@@ -1,64 +1,41 @@
1import { webFrame } from 'electron'; 1import {
2 remote,
3} from 'electron';
2import { SPELLCHECKER_LOCALES } from '../i18n/languages'; 4import { SPELLCHECKER_LOCALES } from '../i18n/languages';
3import setupContextMenu from './contextMenu'; 5import { isMac } from '../environment';
4 6
5const debug = require('debug')('Franz:spellchecker'); 7const debug = require('debug')('Franz:spellchecker');
6 8
7let _isEnabled = false; 9const webContents = remote.getCurrentWebContents();
10const [defaultLocale] = webContents.session.getSpellCheckerLanguages();
11debug('Spellchecker default locale is', defaultLocale);
8 12
9export async function switchDict(locales) { 13export function getSpellcheckerLocaleByFuzzyIdentifier(identifier) {
10 const { platform } = process; 14 const locales = Object.keys(SPELLCHECKER_LOCALES).filter(key => key.toLocaleLowerCase() === identifier.toLowerCase() || key.split('-')[0] === identifier.toLowerCase());
11 if (platform === 'darwin') {
12 // MacOS uses the build-in languages which cannot be changed
13 return;
14 }
15
16 try {
17 debug('Trying to load dictionary', locales);
18
19 webFrame.session.setSpellCheckerLanguages([...locales, 'en-US']);
20
21 debug('Switched dictionary to', locales);
22
23 _isEnabled = true;
24 } catch (err) {
25 console.error(err);
26 }
27}
28
29export default async function initialize(languages = ['en-us']) {
30 try {
31 debug('Init spellchecker');
32
33 switchDict([
34 navigator.language,
35 ...languages,
36 ]);
37 setupContextMenu();
38 15
39 return true; 16 if (locales.length >= 1) {
40 } catch (err) { 17 return locales[0];
41 console.error(err);
42 return false;
43 } 18 }
44}
45 19
46export function isEnabled() { 20 return null;
47 return _isEnabled;
48} 21}
49 22
50export function disable() { 23export function switchDict(locale) {
51 if (isEnabled()) { 24 if (isMac) {
52 // TODO: How to disable build-in spellchecker? 25 debug('Ignoring dictionary changes on macOS');
26 return;
53 } 27 }
54}
55 28
56export function getSpellcheckerLocaleByFuzzyIdentifier(identifier) { 29 debug('Setting spellchecker locale to', locale);
57 const locales = Object.keys(SPELLCHECKER_LOCALES).filter(key => key === identifier.toLowerCase() || key.split('-')[0] === identifier.toLowerCase());
58 30
59 if (locales.length >= 1) { 31 const locales = [];
60 return locales[0]; 32 const foundLocale = getSpellcheckerLocaleByFuzzyIdentifier(locale);
33
34 if (foundLocale) {
35 locales.push(foundLocale);
61 } 36 }
62 37
63 return null; 38 locales.push(defaultLocale, 'de');
39
40 webContents.session.setSpellCheckerLanguages(locales);
64} 41}