From 0d6d623d1e34cdbff2d46229165b49289a9a0619 Mon Sep 17 00:00:00 2001 From: Bennett Date: Sun, 21 Jun 2020 09:19:59 +0200 Subject: Add FAB to service dashboard (#824) * Implement #387 * Fix lint * Upgrade to Electron 9 * Remove dependency on electron-spellchecker * Allow multiple languages to be selected * Fix lint * Don't show spellchecker language chooser for macOS * Fix _requireAuthenticatedUser throwing error on startup * Add FAB --- src/webview/spellchecker.js | 50 ++++++++++++++++----------------------------- 1 file changed, 18 insertions(+), 32 deletions(-) (limited to 'src/webview/spellchecker.js') diff --git a/src/webview/spellchecker.js b/src/webview/spellchecker.js index a33a506b2..287c9cf11 100644 --- a/src/webview/spellchecker.js +++ b/src/webview/spellchecker.js @@ -1,53 +1,42 @@ import { webFrame } from 'electron'; -import { SpellCheckHandler } from 'electron-spellchecker'; import { SPELLCHECKER_LOCALES } from '../i18n/languages'; import setupContextMenu from './contextMenu'; const debug = require('debug')('Franz:spellchecker'); -let handler; -let currentDict; let _isEnabled = false; -export async function switchDict(locale) { - try { - debug('Trying to load dictionary', locale); - - if (!handler) { - console.warn('SpellcheckHandler not initialized'); - - return; - } - - if (locale === currentDict) { - console.warn('Dictionary is already used', currentDict); +export async function switchDict(locales) { + const { platform } = process; + if (platform === 'darwin') { + // MacOS uses the build-in languages which cannot be changed + return; + } - return; - } + try { + debug('Trying to load dictionary', locales); - handler.switchLanguage(locale); + webFrame.session.setSpellCheckerLanguages([...locales, 'en-US']); - debug('Switched dictionary to', locale); + debug('Switched dictionary to', locales); - currentDict = locale; _isEnabled = true; } catch (err) { console.error(err); } } -export default async function initialize(languageCode = 'en-us') { +export default async function initialize(languages = ['en-us']) { try { - handler = new SpellCheckHandler(); - setTimeout(() => handler.attachToInput(), 1000); - const locale = languageCode.toLowerCase(); - debug('Init spellchecker'); - switchDict(locale); - setupContextMenu(handler); + switchDict([ + navigator.language, + ...languages, + ]); + setupContextMenu(); - return handler; + return true; } catch (err) { console.error(err); return false; @@ -60,10 +49,7 @@ export function isEnabled() { export function disable() { if (isEnabled()) { - handler.unsubscribe(); - webFrame.setSpellCheckProvider(currentDict, { spellCheck: () => true }); - _isEnabled = false; - currentDict = null; + // TODO: How to disable build-in spellchecker? } } -- cgit v1.2.3-54-g00ecf