From c1e592e6f530eadf730a77e4fa551f4eb0dbf337 Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Tue, 25 Jun 2019 13:00:16 +0200 Subject: [PATCH] Revert: fix spellchecker --- package-lock.json | 50 ++++++++++++------------------------- package.json | 2 +- src/webview/contextMenu.js | 5 ++-- src/webview/spellchecker.js | 17 +++++-------- 4 files changed, 25 insertions(+), 49 deletions(-) diff --git a/package-lock.json b/package-lock.json index 53b46196a..b4d86c5e1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7043,12 +7043,14 @@ } }, "electron-hunspell": { - "version": "1.0.0-beta.7", - "resolved": "https://registry.npmjs.org/electron-hunspell/-/electron-hunspell-1.0.0-beta.7.tgz", - "integrity": "sha512-BByCXqU8sZbuzyoxKcBYjycp8ORiqjeYZd2OT8RNjVW+XGPmZkHewXUu4tUa1IXW6ij6IqojV5kr+xhYKLN1DA==", + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/electron-hunspell/-/electron-hunspell-0.1.1.tgz", + "integrity": "sha512-B3nOQqHexIX+8bz72FZkNk+iFBrdqS9DpV2SaH+t7T9SLbONBVBRLJ2Jj2ytXFUzvw81q7vz2dfxPCddh/E3ww==", "requires": { - "hunspell-asm": "^2.0.0", - "tslib": "1.9.3" + "hunspell-asm": "1.0.2", + "lodash": "^4.17.11", + "tslib": "1.9.3", + "unixify": "1.0.0" } }, "electron-is-dev": { @@ -11379,34 +11381,14 @@ } }, "hunspell-asm": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/hunspell-asm/-/hunspell-asm-2.0.0.tgz", - "integrity": "sha512-FMIUBpy+bRREFAvC63RcYEK9U6+FdlEojGSVsvMTpuZ2CekYyUBwEfG4+ExIQOQyEN0U6f1MoVgrFqvgPNSA2g==", + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/hunspell-asm/-/hunspell-asm-1.0.2.tgz", + "integrity": "sha512-UTLBvc0yZiIcHl9qrgxnFTZbX3zF4CprzEY+u+N0iXlUKZnUJRIgvgppTdgiQTsucm5b0aN/rHsgXz2q/0kBRA==", "requires": { - "emscripten-wasm-loader": "^2.2.3", - "nanoid": "^2.0.1", - "tslib": "^1.9.3", + "emscripten-wasm-loader": "^1.0.0", + "nanoid": "^1.0.2", + "tslib": "^1.9.0", "unixify": "^1.0.0" - }, - "dependencies": { - "emscripten-wasm-loader": { - "version": "2.2.3", - "resolved": "https://registry.npmjs.org/emscripten-wasm-loader/-/emscripten-wasm-loader-2.2.3.tgz", - "integrity": "sha512-//gI0afvtVnY7smttrPOW/BM+pTJLmdIcXAQV3fgRdQ0o6wm2vdSI0kjLYVOeo/rbtRsGgVuMLu6fT+O//EfaA==", - "requires": { - "getroot": "^1.0.0", - "nanoid": "^1.3.4", - "tslib": "^1.9.3", - "unixify": "^1.0.0" - }, - "dependencies": { - "nanoid": { - "version": "1.3.4", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-1.3.4.tgz", - "integrity": "sha512-4ug4BsuHxiVHoRUe1ud6rUFT3WUMmjXt1W0quL0CviZQANdan7D8kqN5/maw53hmAApY/jfzMRkC57BNNs60ZQ==" - } - } - } } }, "husky": { @@ -14385,9 +14367,9 @@ "integrity": "sha512-JY7V6lRkStKcKTvHO5NVSQRv+RV+FIL5pvDoLiAtSL9pKlC5x9PKQcZDsq7m4FO4d57mkhC6Z+QhAh3Jdk5JFw==" }, "nanoid": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-2.0.3.tgz", - "integrity": "sha512-NbaoqdhIYmY6FXDRB4eYtDVC9Z9eCbn8TyaiC16LNKtpPv/aqa0tOPD8y6gNE4yUNnaZ7LLhYtXOev/6+cBtfw==" + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-1.3.4.tgz", + "integrity": "sha512-4ug4BsuHxiVHoRUe1ud6rUFT3WUMmjXt1W0quL0CviZQANdan7D8kqN5/maw53hmAApY/jfzMRkC57BNNs60ZQ==" }, "nanomatch": { "version": "1.2.13", diff --git a/package.json b/package.json index e982c7542..517dd1c6f 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "du": "^0.1.0", "electron-dl": "1.12.0", "electron-fetch": "1.3.0", - "electron-hunspell": "1.0.0-beta.7", + "electron-hunspell": "0.1.1", "electron-is-dev": "1.0.1", "electron-react-titlebar": "0.8.1", "electron-updater": "4.0.6", diff --git a/src/webview/contextMenu.js b/src/webview/contextMenu.js index 967e8e667..a4a6ab899 100644 --- a/src/webview/contextMenu.js +++ b/src/webview/contextMenu.js @@ -280,13 +280,12 @@ const buildMenuTpl = (props, suggestions, isSpellcheckEnabled, defaultSpellcheck }; export default function contextMenu(spellcheckProvider, isSpellcheckEnabled, getDefaultSpellcheckerLanguage, getSpellcheckerLanguage) { - webContents.on('context-menu', async (e, props) => { + webContents.on('context-menu', (e, props) => { e.preventDefault(); let suggestions = []; if (spellcheckProvider && props.misspelledWord) { - debug('Mispelled word', props.misspelledWord); - suggestions = await spellcheckProvider.getSuggestion(props.misspelledWord); + suggestions = spellcheckProvider.getSuggestion(props.misspelledWord); debug('Suggestions', suggestions); } diff --git a/src/webview/spellchecker.js b/src/webview/spellchecker.js index 417d1ea1a..9158b3b94 100644 --- a/src/webview/spellchecker.js +++ b/src/webview/spellchecker.js @@ -1,8 +1,6 @@ import { webFrame } from 'electron'; -import { attachSpellCheckProvider, SpellCheckerProvider } from 'electron-hunspell'; -import { ENVIRONMENT } from 'hunspell-asm'; +import { SpellCheckerProvider } from 'electron-hunspell'; import path from 'path'; -import { readFileSync } from 'fs'; import { DICTIONARY_PATH } from '../config'; import { SPELLCHECKER_LOCALES } from '../i18n/languages'; @@ -12,12 +10,11 @@ const debug = require('debug')('Franz:spellchecker'); let provider; let currentDict; let _isEnabled = false; -let attached; async function loadDictionary(locale) { try { const fileLocation = path.join(DICTIONARY_PATH, `hunspell-dict-${locale}/${locale}`); - await provider.loadDictionary(locale, readFileSync(`${fileLocation}.dic`), readFileSync(`${fileLocation}.aff`)); + await provider.loadDictionary(locale, `${fileLocation}.dic`, `${fileLocation}.aff`); debug('Loaded dictionary', locale, 'from', fileLocation); } catch (err) { console.error('Could not load dictionary', err); @@ -44,7 +41,7 @@ export async function switchDict(locale) { provider.unloadDictionary(locale); } loadDictionary(locale); - attached.switchLanguage(locale); + provider.switchDictionary(locale); debug('Switched dictionary to', locale); @@ -61,14 +58,12 @@ export default async function initialize(languageCode = 'en-us') { const locale = languageCode.toLowerCase(); debug('Init spellchecker'); - await provider.initialize({ environment: ENVIRONMENT.NODE }); - - debug('Attaching spellcheck provider'); - attached = await attachSpellCheckProvider(provider); + await provider.initialize(); + // await loadDictionaries(); debug('Available spellchecker dictionaries', provider.availableDictionaries); - attached.switchLanguage(locale); + switchDict(locale); return provider; } catch (err) {