From 830b6f88f3d30708cf0264375b8db5b2e5714218 Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Wed, 5 Jun 2019 17:18:52 +0200 Subject: Fix spellchecker integration --- src/webview/spellchecker.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src/webview/spellchecker.js') diff --git a/src/webview/spellchecker.js b/src/webview/spellchecker.js index 9158b3b94..64575753f 100644 --- a/src/webview/spellchecker.js +++ b/src/webview/spellchecker.js @@ -1,6 +1,8 @@ import { webFrame } from 'electron'; -import { SpellCheckerProvider } from 'electron-hunspell'; +import { attachSpellCheckProvider, SpellCheckerProvider } from 'electron-hunspell'; +import { ENVIRONMENT } from 'hunspell-asm'; import path from 'path'; +import { readFileSync } from 'fs'; import { DICTIONARY_PATH } from '../config'; import { SPELLCHECKER_LOCALES } from '../i18n/languages'; @@ -10,11 +12,12 @@ 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, `${fileLocation}.dic`, `${fileLocation}.aff`); + await provider.loadDictionary(locale, readFileSync(`${fileLocation}.dic`), readFileSync(`${fileLocation}.aff`)); debug('Loaded dictionary', locale, 'from', fileLocation); } catch (err) { console.error('Could not load dictionary', err); @@ -41,7 +44,7 @@ export async function switchDict(locale) { provider.unloadDictionary(locale); } loadDictionary(locale); - provider.switchDictionary(locale); + attached.switchLanguage(locale); debug('Switched dictionary to', locale); @@ -58,12 +61,15 @@ export default async function initialize(languageCode = 'en-us') { const locale = languageCode.toLowerCase(); debug('Init spellchecker'); - await provider.initialize(); - // await loadDictionaries(); + await provider.initialize({ environment: ENVIRONMENT.NODE }); + + debug('Attaching spellcheck provider'); + attached = await attachSpellCheckProvider(provider); debug('Available spellchecker dictionaries', provider.availableDictionaries); - switchDict(locale); + attached.switchLanguage(locale); + console.log('seas oida', attached, provider); return provider; } catch (err) { -- cgit v1.2.3-54-g00ecf