diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/config.js | 3 | ||||
-rw-r--r-- | src/stores/DictionaryStore.js | 45 | ||||
-rw-r--r-- | src/stores/index.js | 2 | ||||
-rw-r--r-- | src/webview/spellchecker.js | 34 |
4 files changed, 15 insertions, 69 deletions
diff --git a/src/config.js b/src/config.js index d981f9c6a..789ddd1a0 100644 --- a/src/config.js +++ b/src/config.js | |||
@@ -56,4 +56,5 @@ export const FILE_SYSTEM_SETTINGS_TYPES = [ | |||
56 | 56 | ||
57 | export const SETTINGS_PATH = path.join(app.getPath('userData'), 'config'); | 57 | export const SETTINGS_PATH = path.join(app.getPath('userData'), 'config'); |
58 | 58 | ||
59 | export const DICTIONARY_PATH = path.join(app.getPath('userData'), 'dicts'); | 59 | // Replacing app.asar is not beautiful but unforunately necessary |
60 | export const DICTIONARY_PATH = path.join(__dirname, 'dictionaries').replace('app.asar', 'app.asar.unpacked'); | ||
diff --git a/src/stores/DictionaryStore.js b/src/stores/DictionaryStore.js deleted file mode 100644 index b9c5f2abf..000000000 --- a/src/stores/DictionaryStore.js +++ /dev/null | |||
@@ -1,45 +0,0 @@ | |||
1 | import { observable } from 'mobx'; | ||
2 | import { createDownloader } from 'hunspell-dict-downloader'; | ||
3 | |||
4 | import Store from './lib/Store'; | ||
5 | |||
6 | import { DICTIONARY_PATH } from '../config'; | ||
7 | |||
8 | const debug = require('debug')('Franz:DictionaryStore'); | ||
9 | |||
10 | export default class DictionaryStore extends Store { | ||
11 | @observable available = [] | ||
12 | @observable installed = [] | ||
13 | |||
14 | _dictDownloader = null | ||
15 | |||
16 | constructor(...args) { | ||
17 | super(...args); | ||
18 | |||
19 | this.registerReactions([ | ||
20 | this._downloadDictForUserLocale.bind(this), | ||
21 | ]); | ||
22 | } | ||
23 | |||
24 | async setup() { | ||
25 | this._dictDownloader = await createDownloader(DICTIONARY_PATH); | ||
26 | debug('dicts', this._dictDownloader); | ||
27 | |||
28 | this.available = this._dictDownloader.availableDictionaries; | ||
29 | this.installed = this._dictDownloader.installedDictionaries; | ||
30 | |||
31 | if (!this.installed.includes('en-us')) { | ||
32 | this._dictDownloader.installDictionary('en-us'); | ||
33 | } | ||
34 | } | ||
35 | |||
36 | _downloadDictForUserLocale() { | ||
37 | const spellcheckerLanguage = this.stores.settings.app.spellcheckerLanguage; | ||
38 | |||
39 | debug('trying to Downloading dict for', spellcheckerLanguage); | ||
40 | if (!this.installed.includes(spellcheckerLanguage) && this.available.includes(spellcheckerLanguage) && spellcheckerLanguage !== 'en-us') { | ||
41 | debug('Downloading dict for', spellcheckerLanguage); | ||
42 | this._dictDownloader.installDictionary(spellcheckerLanguage); | ||
43 | } | ||
44 | } | ||
45 | } | ||
diff --git a/src/stores/index.js b/src/stores/index.js index f547d0a7a..96b844c95 100644 --- a/src/stores/index.js +++ b/src/stores/index.js | |||
@@ -9,7 +9,6 @@ import UIStore from './UIStore'; | |||
9 | import PaymentStore from './PaymentStore'; | 9 | import PaymentStore from './PaymentStore'; |
10 | import NewsStore from './NewsStore'; | 10 | import NewsStore from './NewsStore'; |
11 | import RequestStore from './RequestStore'; | 11 | import RequestStore from './RequestStore'; |
12 | import DictionaryStore from './DictionaryStore'; | ||
13 | import GlobalErrorStore from './GlobalErrorStore'; | 12 | import GlobalErrorStore from './GlobalErrorStore'; |
14 | 13 | ||
15 | export default (api, actions, router) => { | 14 | export default (api, actions, router) => { |
@@ -27,7 +26,6 @@ export default (api, actions, router) => { | |||
27 | payment: new PaymentStore(stores, api, actions), | 26 | payment: new PaymentStore(stores, api, actions), |
28 | news: new NewsStore(stores, api, actions), | 27 | news: new NewsStore(stores, api, actions), |
29 | requests: new RequestStore(stores, api, actions), | 28 | requests: new RequestStore(stores, api, actions), |
30 | dictionary: new DictionaryStore(stores, api, actions), | ||
31 | globalError: new GlobalErrorStore(stores, api, actions), | 29 | globalError: new GlobalErrorStore(stores, api, actions), |
32 | }); | 30 | }); |
33 | // Initialize all stores | 31 | // Initialize all stores |
diff --git a/src/webview/spellchecker.js b/src/webview/spellchecker.js index b0192b7ef..ab0cc9a90 100644 --- a/src/webview/spellchecker.js +++ b/src/webview/spellchecker.js | |||
@@ -1,28 +1,24 @@ | |||
1 | import { webFrame } from 'electron'; | 1 | import { webFrame } from 'electron'; |
2 | import fs from 'fs'; | ||
3 | import path from 'path'; | ||
4 | import { SpellCheckerProvider } from 'electron-hunspell'; | 2 | import { SpellCheckerProvider } from 'electron-hunspell'; |
3 | import path from 'path'; | ||
5 | 4 | ||
6 | import { DICTIONARY_PATH } from '../config'; | 5 | import { DICTIONARY_PATH } from '../config'; |
7 | 6 | ||
7 | |||
8 | const debug = require('debug')('Franz:spellchecker'); | 8 | const debug = require('debug')('Franz:spellchecker'); |
9 | 9 | ||
10 | let provider; | 10 | let provider; |
11 | let currentDict; | 11 | let currentDict; |
12 | let _isEnabled = false; | 12 | let _isEnabled = false; |
13 | 13 | ||
14 | async function loadDictionaries() { | 14 | async function loadDictionary(locale) { |
15 | const rawList = fs.readdirSync(DICTIONARY_PATH); | 15 | try { |
16 | 16 | // Replacing app.asar is not beautiful but unforunately necessary | |
17 | const dicts = rawList.filter(item => !item.startsWith('.') && fs.lstatSync(path.join(DICTIONARY_PATH, item)).isDirectory()); | 17 | const fileLocation = path.join(DICTIONARY_PATH, `hunspell-dict-${locale}/${locale}`); |
18 | 18 | console.log(fileLocation, __dirname); | |
19 | debug('Found dictionaries', dicts); | 19 | await provider.loadDictionary(locale, `${fileLocation}.dic`, `${fileLocation}.aff`); |
20 | 20 | } catch (err) { | |
21 | for (let i = 0; i < dicts.length; i += 1) { | 21 | console.error('Could not load dictionary', err); |
22 | const fileLocation = `${DICTIONARY_PATH}/${dicts[i]}/${dicts[i]}`; | ||
23 | debug('Trying to load', fileLocation); | ||
24 | // eslint-disable-next-line | ||
25 | await provider.loadDictionary(dicts[i], `${fileLocation}.dic`, `${fileLocation}.aff`); | ||
26 | } | 22 | } |
27 | } | 23 | } |
28 | 24 | ||
@@ -30,12 +26,6 @@ export async function switchDict(locale) { | |||
30 | try { | 26 | try { |
31 | debug('Trying to load dictionary', locale); | 27 | debug('Trying to load dictionary', locale); |
32 | 28 | ||
33 | if (!provider.availableDictionaries.includes(locale)) { | ||
34 | console.warn('Dict not available', locale); | ||
35 | |||
36 | return; | ||
37 | } | ||
38 | |||
39 | if (!provider) { | 29 | if (!provider) { |
40 | console.warn('SpellcheckProvider not initialized'); | 30 | console.warn('SpellcheckProvider not initialized'); |
41 | 31 | ||
@@ -48,6 +38,8 @@ export async function switchDict(locale) { | |||
48 | return; | 38 | return; |
49 | } | 39 | } |
50 | 40 | ||
41 | provider.unloadDictionary(locale); | ||
42 | loadDictionary(locale); | ||
51 | provider.switchDictionary(locale); | 43 | provider.switchDictionary(locale); |
52 | 44 | ||
53 | debug('Switched dictionary to', locale); | 45 | debug('Switched dictionary to', locale); |
@@ -66,7 +58,7 @@ export default async function initialize(languageCode = 'en-us') { | |||
66 | 58 | ||
67 | debug('Init spellchecker'); | 59 | debug('Init spellchecker'); |
68 | await provider.initialize(); | 60 | await provider.initialize(); |
69 | await loadDictionaries(); | 61 | // await loadDictionaries(); |
70 | 62 | ||
71 | debug('Available spellchecker dictionaries', provider.availableDictionaries); | 63 | debug('Available spellchecker dictionaries', provider.availableDictionaries); |
72 | 64 | ||