diff options
-rw-r--r-- | package-lock.json | 50 | ||||
-rw-r--r-- | package.json | 2 | ||||
-rw-r--r-- | src/webview/contextMenu.js | 5 | ||||
-rw-r--r-- | src/webview/spellchecker.js | 18 |
4 files changed, 50 insertions, 25 deletions
diff --git a/package-lock.json b/package-lock.json index 54f49fd0d..2a2c83bc9 100644 --- a/package-lock.json +++ b/package-lock.json | |||
@@ -7036,14 +7036,12 @@ | |||
7036 | } | 7036 | } |
7037 | }, | 7037 | }, |
7038 | "electron-hunspell": { | 7038 | "electron-hunspell": { |
7039 | "version": "0.1.1", | 7039 | "version": "1.0.0-beta.7", |
7040 | "resolved": "https://registry.npmjs.org/electron-hunspell/-/electron-hunspell-0.1.1.tgz", | 7040 | "resolved": "https://registry.npmjs.org/electron-hunspell/-/electron-hunspell-1.0.0-beta.7.tgz", |
7041 | "integrity": "sha512-B3nOQqHexIX+8bz72FZkNk+iFBrdqS9DpV2SaH+t7T9SLbONBVBRLJ2Jj2ytXFUzvw81q7vz2dfxPCddh/E3ww==", | 7041 | "integrity": "sha512-BByCXqU8sZbuzyoxKcBYjycp8ORiqjeYZd2OT8RNjVW+XGPmZkHewXUu4tUa1IXW6ij6IqojV5kr+xhYKLN1DA==", |
7042 | "requires": { | 7042 | "requires": { |
7043 | "hunspell-asm": "1.0.2", | 7043 | "hunspell-asm": "^2.0.0", |
7044 | "lodash": "^4.17.11", | 7044 | "tslib": "1.9.3" |
7045 | "tslib": "1.9.3", | ||
7046 | "unixify": "1.0.0" | ||
7047 | } | 7045 | } |
7048 | }, | 7046 | }, |
7049 | "electron-is-dev": { | 7047 | "electron-is-dev": { |
@@ -11374,14 +11372,34 @@ | |||
11374 | } | 11372 | } |
11375 | }, | 11373 | }, |
11376 | "hunspell-asm": { | 11374 | "hunspell-asm": { |
11377 | "version": "1.0.2", | 11375 | "version": "2.0.0", |
11378 | "resolved": "https://registry.npmjs.org/hunspell-asm/-/hunspell-asm-1.0.2.tgz", | 11376 | "resolved": "https://registry.npmjs.org/hunspell-asm/-/hunspell-asm-2.0.0.tgz", |
11379 | "integrity": "sha512-UTLBvc0yZiIcHl9qrgxnFTZbX3zF4CprzEY+u+N0iXlUKZnUJRIgvgppTdgiQTsucm5b0aN/rHsgXz2q/0kBRA==", | 11377 | "integrity": "sha512-FMIUBpy+bRREFAvC63RcYEK9U6+FdlEojGSVsvMTpuZ2CekYyUBwEfG4+ExIQOQyEN0U6f1MoVgrFqvgPNSA2g==", |
11380 | "requires": { | 11378 | "requires": { |
11381 | "emscripten-wasm-loader": "^1.0.0", | 11379 | "emscripten-wasm-loader": "^2.2.3", |
11382 | "nanoid": "^1.0.2", | 11380 | "nanoid": "^2.0.1", |
11383 | "tslib": "^1.9.0", | 11381 | "tslib": "^1.9.3", |
11384 | "unixify": "^1.0.0" | 11382 | "unixify": "^1.0.0" |
11383 | }, | ||
11384 | "dependencies": { | ||
11385 | "emscripten-wasm-loader": { | ||
11386 | "version": "2.2.3", | ||
11387 | "resolved": "https://registry.npmjs.org/emscripten-wasm-loader/-/emscripten-wasm-loader-2.2.3.tgz", | ||
11388 | "integrity": "sha512-//gI0afvtVnY7smttrPOW/BM+pTJLmdIcXAQV3fgRdQ0o6wm2vdSI0kjLYVOeo/rbtRsGgVuMLu6fT+O//EfaA==", | ||
11389 | "requires": { | ||
11390 | "getroot": "^1.0.0", | ||
11391 | "nanoid": "^1.3.4", | ||
11392 | "tslib": "^1.9.3", | ||
11393 | "unixify": "^1.0.0" | ||
11394 | }, | ||
11395 | "dependencies": { | ||
11396 | "nanoid": { | ||
11397 | "version": "1.3.4", | ||
11398 | "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-1.3.4.tgz", | ||
11399 | "integrity": "sha512-4ug4BsuHxiVHoRUe1ud6rUFT3WUMmjXt1W0quL0CviZQANdan7D8kqN5/maw53hmAApY/jfzMRkC57BNNs60ZQ==" | ||
11400 | } | ||
11401 | } | ||
11402 | } | ||
11385 | } | 11403 | } |
11386 | }, | 11404 | }, |
11387 | "husky": { | 11405 | "husky": { |
@@ -14360,9 +14378,9 @@ | |||
14360 | "integrity": "sha512-JY7V6lRkStKcKTvHO5NVSQRv+RV+FIL5pvDoLiAtSL9pKlC5x9PKQcZDsq7m4FO4d57mkhC6Z+QhAh3Jdk5JFw==" | 14378 | "integrity": "sha512-JY7V6lRkStKcKTvHO5NVSQRv+RV+FIL5pvDoLiAtSL9pKlC5x9PKQcZDsq7m4FO4d57mkhC6Z+QhAh3Jdk5JFw==" |
14361 | }, | 14379 | }, |
14362 | "nanoid": { | 14380 | "nanoid": { |
14363 | "version": "1.3.4", | 14381 | "version": "2.0.3", |
14364 | "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-1.3.4.tgz", | 14382 | "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-2.0.3.tgz", |
14365 | "integrity": "sha512-4ug4BsuHxiVHoRUe1ud6rUFT3WUMmjXt1W0quL0CviZQANdan7D8kqN5/maw53hmAApY/jfzMRkC57BNNs60ZQ==" | 14383 | "integrity": "sha512-NbaoqdhIYmY6FXDRB4eYtDVC9Z9eCbn8TyaiC16LNKtpPv/aqa0tOPD8y6gNE4yUNnaZ7LLhYtXOev/6+cBtfw==" |
14366 | }, | 14384 | }, |
14367 | "nanomatch": { | 14385 | "nanomatch": { |
14368 | "version": "1.2.13", | 14386 | "version": "1.2.13", |
diff --git a/package.json b/package.json index 245eb71d6..d03de2f20 100644 --- a/package.json +++ b/package.json | |||
@@ -47,7 +47,7 @@ | |||
47 | "du": "^0.1.0", | 47 | "du": "^0.1.0", |
48 | "electron-dl": "1.12.0", | 48 | "electron-dl": "1.12.0", |
49 | "electron-fetch": "1.3.0", | 49 | "electron-fetch": "1.3.0", |
50 | "electron-hunspell": "0.1.1", | 50 | "electron-hunspell": "1.0.0-beta.7", |
51 | "electron-is-dev": "1.0.1", | 51 | "electron-is-dev": "1.0.1", |
52 | "electron-react-titlebar": "0.8.1", | 52 | "electron-react-titlebar": "0.8.1", |
53 | "electron-updater": "4.0.6", | 53 | "electron-updater": "4.0.6", |
diff --git a/src/webview/contextMenu.js b/src/webview/contextMenu.js index a4a6ab899..967e8e667 100644 --- a/src/webview/contextMenu.js +++ b/src/webview/contextMenu.js | |||
@@ -280,12 +280,13 @@ const buildMenuTpl = (props, suggestions, isSpellcheckEnabled, defaultSpellcheck | |||
280 | }; | 280 | }; |
281 | 281 | ||
282 | export default function contextMenu(spellcheckProvider, isSpellcheckEnabled, getDefaultSpellcheckerLanguage, getSpellcheckerLanguage) { | 282 | export default function contextMenu(spellcheckProvider, isSpellcheckEnabled, getDefaultSpellcheckerLanguage, getSpellcheckerLanguage) { |
283 | webContents.on('context-menu', (e, props) => { | 283 | webContents.on('context-menu', async (e, props) => { |
284 | e.preventDefault(); | 284 | e.preventDefault(); |
285 | 285 | ||
286 | let suggestions = []; | 286 | let suggestions = []; |
287 | if (spellcheckProvider && props.misspelledWord) { | 287 | if (spellcheckProvider && props.misspelledWord) { |
288 | suggestions = spellcheckProvider.getSuggestion(props.misspelledWord); | 288 | debug('Mispelled word', props.misspelledWord); |
289 | suggestions = await spellcheckProvider.getSuggestion(props.misspelledWord); | ||
289 | 290 | ||
290 | debug('Suggestions', suggestions); | 291 | debug('Suggestions', suggestions); |
291 | } | 292 | } |
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 @@ | |||
1 | import { webFrame } from 'electron'; | 1 | import { webFrame } from 'electron'; |
2 | import { SpellCheckerProvider } from 'electron-hunspell'; | 2 | import { attachSpellCheckProvider, SpellCheckerProvider } from 'electron-hunspell'; |
3 | import { ENVIRONMENT } from 'hunspell-asm'; | ||
3 | import path from 'path'; | 4 | import path from 'path'; |
5 | import { readFileSync } from 'fs'; | ||
4 | 6 | ||
5 | import { DICTIONARY_PATH } from '../config'; | 7 | import { DICTIONARY_PATH } from '../config'; |
6 | import { SPELLCHECKER_LOCALES } from '../i18n/languages'; | 8 | import { SPELLCHECKER_LOCALES } from '../i18n/languages'; |
@@ -10,11 +12,12 @@ const debug = require('debug')('Franz:spellchecker'); | |||
10 | let provider; | 12 | let provider; |
11 | let currentDict; | 13 | let currentDict; |
12 | let _isEnabled = false; | 14 | let _isEnabled = false; |
15 | let attached; | ||
13 | 16 | ||
14 | async function loadDictionary(locale) { | 17 | async function loadDictionary(locale) { |
15 | try { | 18 | try { |
16 | const fileLocation = path.join(DICTIONARY_PATH, `hunspell-dict-${locale}/${locale}`); | 19 | const fileLocation = path.join(DICTIONARY_PATH, `hunspell-dict-${locale}/${locale}`); |
17 | await provider.loadDictionary(locale, `${fileLocation}.dic`, `${fileLocation}.aff`); | 20 | await provider.loadDictionary(locale, readFileSync(`${fileLocation}.dic`), readFileSync(`${fileLocation}.aff`)); |
18 | debug('Loaded dictionary', locale, 'from', fileLocation); | 21 | debug('Loaded dictionary', locale, 'from', fileLocation); |
19 | } catch (err) { | 22 | } catch (err) { |
20 | console.error('Could not load dictionary', err); | 23 | console.error('Could not load dictionary', err); |
@@ -41,7 +44,7 @@ export async function switchDict(locale) { | |||
41 | provider.unloadDictionary(locale); | 44 | provider.unloadDictionary(locale); |
42 | } | 45 | } |
43 | loadDictionary(locale); | 46 | loadDictionary(locale); |
44 | provider.switchDictionary(locale); | 47 | attached.switchLanguage(locale); |
45 | 48 | ||
46 | debug('Switched dictionary to', locale); | 49 | debug('Switched dictionary to', locale); |
47 | 50 | ||
@@ -58,12 +61,15 @@ export default async function initialize(languageCode = 'en-us') { | |||
58 | const locale = languageCode.toLowerCase(); | 61 | const locale = languageCode.toLowerCase(); |
59 | 62 | ||
60 | debug('Init spellchecker'); | 63 | debug('Init spellchecker'); |
61 | await provider.initialize(); | 64 | await provider.initialize({ environment: ENVIRONMENT.NODE }); |
62 | // await loadDictionaries(); | 65 | |
66 | debug('Attaching spellcheck provider'); | ||
67 | attached = await attachSpellCheckProvider(provider); | ||
63 | 68 | ||
64 | debug('Available spellchecker dictionaries', provider.availableDictionaries); | 69 | debug('Available spellchecker dictionaries', provider.availableDictionaries); |
65 | 70 | ||
66 | switchDict(locale); | 71 | attached.switchLanguage(locale); |
72 | console.log('seas oida', attached, provider); | ||
67 | 73 | ||
68 | return provider; | 74 | return provider; |
69 | } catch (err) { | 75 | } catch (err) { |