From 035002ceedf78d5ec73eabc0df7f06139939b967 Mon Sep 17 00:00:00 2001 From: Amine El Mouafik <412895+kytwb@users.noreply.github.com> Date: Mon, 8 Feb 2021 10:34:45 +0100 Subject: Synchronize with Franz 5.6.0 (#1033) Co-authored-by: FranzBot Co-authored-by: vantezzen Co-authored-by: Makazzz Co-authored-by: Stefan Malzner Co-authored-by: Amine Mouafik --- src/webview/spellchecker.js | 73 ++++++++++++++++----------------------------- 1 file changed, 25 insertions(+), 48 deletions(-) (limited to 'src/webview/spellchecker.js') 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 @@ -import { webFrame } from 'electron'; +import { + remote, +} from 'electron'; import { SPELLCHECKER_LOCALES } from '../i18n/languages'; -import setupContextMenu from './contextMenu'; +import { isMac } from '../environment'; const debug = require('debug')('Franz:spellchecker'); -let _isEnabled = false; +const webContents = remote.getCurrentWebContents(); +const [defaultLocale] = webContents.session.getSpellCheckerLanguages(); +debug('Spellchecker default locale is', defaultLocale); -export async function switchDict(locales) { - const { platform } = process; - if (platform === 'darwin') { - // MacOS uses the build-in languages which cannot be changed - return; - } - - try { - debug('Trying to load dictionary', locales); - - webFrame.session.setSpellCheckerLanguages([...locales, 'en-US']); - - debug('Switched dictionary to', locales); - - _isEnabled = true; - } catch (err) { - console.error(err); - } -} - -export default async function initialize(languages = ['en-us']) { - try { - debug('Init spellchecker'); - - switchDict([ - navigator.language, - ...languages, - ]); - setupContextMenu(); +export function getSpellcheckerLocaleByFuzzyIdentifier(identifier) { + const locales = Object.keys(SPELLCHECKER_LOCALES).filter(key => key.toLocaleLowerCase() === identifier.toLowerCase() || key.split('-')[0] === identifier.toLowerCase()); - return true; - } catch (err) { - console.error(err); - return false; + if (locales.length >= 1) { + return locales[0]; } -} -export function isEnabled() { - return _isEnabled; + return null; } -export function disable() { - if (isEnabled()) { - // TODO: How to disable build-in spellchecker? +export function switchDict(locale) { + if (isMac) { + debug('Ignoring dictionary changes on macOS'); + return; } -} -export function getSpellcheckerLocaleByFuzzyIdentifier(identifier) { - const locales = Object.keys(SPELLCHECKER_LOCALES).filter(key => key === identifier.toLowerCase() || key.split('-')[0] === identifier.toLowerCase()); + debug('Setting spellchecker locale to', locale); - if (locales.length >= 1) { - return locales[0]; + const locales = []; + const foundLocale = getSpellcheckerLocaleByFuzzyIdentifier(locale); + + if (foundLocale) { + locales.push(foundLocale); } - return null; + locales.push(defaultLocale, 'de'); + + webContents.session.setSpellCheckerLanguages(locales); } -- cgit v1.2.3-70-g09d2