aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores/DictionaryStore.js
diff options
context:
space:
mode:
authorLibravatar Stefan Malzner <stefan@adlk.io>2018-12-02 15:08:07 +0100
committerLibravatar Stefan Malzner <stefan@adlk.io>2018-12-02 15:08:07 +0100
commita5aa5e1380a0847eb33be3315d164fb9e0e23255 (patch)
treea1ea4b0f635cabb54d9cf028809d2f079727b9a1 /src/stores/DictionaryStore.js
parentAdd instruction to install Franz with homebrew (#1134) (diff)
parentMerge branch 'develop' into release/5.0.0-beta.19 (diff)
downloadferdium-app-a5aa5e1380a0847eb33be3315d164fb9e0e23255.tar.gz
ferdium-app-a5aa5e1380a0847eb33be3315d164fb9e0e23255.tar.zst
ferdium-app-a5aa5e1380a0847eb33be3315d164fb9e0e23255.zip
Merge branch 'release/5.0.0-beta.19'
Diffstat (limited to 'src/stores/DictionaryStore.js')
-rw-r--r--src/stores/DictionaryStore.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/stores/DictionaryStore.js b/src/stores/DictionaryStore.js
new file mode 100644
index 000000000..b9c5f2abf
--- /dev/null
+++ b/src/stores/DictionaryStore.js
@@ -0,0 +1,45 @@
1import { observable } from 'mobx';
2import { createDownloader } from 'hunspell-dict-downloader';
3
4import Store from './lib/Store';
5
6import { DICTIONARY_PATH } from '../config';
7
8const debug = require('debug')('Franz:DictionaryStore');
9
10export 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}