aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores
diff options
context:
space:
mode:
authorLibravatar Stefan Malzner <stefan@adlk.io>2018-11-30 14:32:45 +0100
committerLibravatar Stefan Malzner <stefan@adlk.io>2018-11-30 14:32:45 +0100
commit3d87c0e45cead95ddb6c11fc6540b82e375bdcf5 (patch)
treec91f425a39cb585242d6df5b4070de4a2141b3b4 /src/stores
parentMerge branch 'update/monetization' into develop (diff)
downloadferdium-app-3d87c0e45cead95ddb6c11fc6540b82e375bdcf5.tar.gz
ferdium-app-3d87c0e45cead95ddb6c11fc6540b82e375bdcf5.tar.zst
ferdium-app-3d87c0e45cead95ddb6c11fc6540b82e375bdcf5.zip
feat(App): Improved spell checker & context menu
Diffstat (limited to 'src/stores')
-rw-r--r--src/stores/AppStore.js64
-rw-r--r--src/stores/DictionaryStore.js45
-rw-r--r--src/stores/ServicesStore.js12
-rw-r--r--src/stores/SettingsStore.js11
-rw-r--r--src/stores/index.js2
5 files changed, 100 insertions, 34 deletions
diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js
index 3e8b18801..45335c488 100644
--- a/src/stores/AppStore.js
+++ b/src/stores/AppStore.js
@@ -13,6 +13,7 @@ import { isMac, isLinux, isWindows } from '../environment';
13import locales from '../i18n/translations'; 13import locales from '../i18n/translations';
14import { gaEvent } from '../lib/analytics'; 14import { gaEvent } from '../lib/analytics';
15import { onVisibilityChange } from '../helpers/visibility-helper'; 15import { onVisibilityChange } from '../helpers/visibility-helper';
16import { getLocale } from '../helpers/i18n-helpers';
16 17
17import { getServiceIdsFromPartitions, removeServicePartitionDirectory } from '../helpers/service-helpers.js'; 18import { getServiceIdsFromPartitions, removeServicePartitionDirectory } from '../helpers/service-helpers.js';
18 19
@@ -59,6 +60,8 @@ export default class AppStore extends Store {
59 60
60 @observable isFocused = true; 61 @observable isFocused = true;
61 62
63 dictionaries = [];
64
62 constructor(...args) { 65 constructor(...args) {
63 super(...args); 66 super(...args);
64 67
@@ -82,7 +85,7 @@ export default class AppStore extends Store {
82 ]); 85 ]);
83 } 86 }
84 87
85 setup() { 88 async setup() {
86 this._appStartsCounter(); 89 this._appStartsCounter();
87 // Focus the active service 90 // Focus the active service
88 window.addEventListener('focus', this.actions.service.focusActiveService); 91 window.addEventListener('focus', this.actions.service.focusActiveService);
@@ -169,11 +172,6 @@ export default class AppStore extends Store {
169 172
170 onVisibilityChange((isVisible) => { 173 onVisibilityChange((isVisible) => {
171 this.isFocused = isVisible; 174 this.isFocused = isVisible;
172 // debug('Last focus', moment().diff(this.timeLastFocusStart));
173
174 // if (isVisible) {
175 // this.timeLastFocusStart = moment();
176 // }
177 175
178 debug('Window is visible/focused', isVisible); 176 debug('Window is visible/focused', isVisible);
179 }); 177 });
@@ -322,31 +320,37 @@ export default class AppStore extends Store {
322 } 320 }
323 321
324 _getDefaultLocale() { 322 _getDefaultLocale() {
325 let locale = app.getLocale(); 323 return getLocale({
326 if (locales[locale] === undefined) { 324 locale: app.getLocale(),
327 let localeFuzzy; 325 locales,
328 Object.keys(locales).forEach((localStr) => { 326 defaultLocale,
329 if (locales && Object.hasOwnProperty.call(locales, localStr)) { 327 fallbackLocale: DEFAULT_APP_SETTINGS.fallbackLocale,
330 if (locale.substring(0, 2) === localStr.substring(0, 2)) { 328 });
331 localeFuzzy = localStr;
332 }
333 }
334 });
335
336 if (localeFuzzy !== undefined) {
337 locale = localeFuzzy;
338 }
339 }
340
341 if (locales[locale] === undefined) {
342 locale = defaultLocale;
343 }
344
345 if (!locale) {
346 locale = DEFAULT_APP_SETTINGS.fallbackLocale;
347 }
348 329
349 return locale; 330 // if (locales[locale] === undefined) {
331 // let localeFuzzy;
332 // Object.keys(locales).forEach((localStr) => {
333 // if (locales && Object.hasOwnProperty.call(locales, localStr)) {
334 // if (locale.substring(0, 2) === localStr.substring(0, 2)) {
335 // localeFuzzy = localStr;
336 // }
337 // }
338 // });
339
340 // if (localeFuzzy !== undefined) {
341 // locale = localeFuzzy;
342 // }
343 // }
344
345 // if (locales[locale] === undefined) {
346 // locale = defaultLocale;
347 // }
348
349 // if (!locale) {
350 // locale = DEFAULT_APP_SETTINGS.fallbackLocale;
351 // }
352
353 // return locale;
350 } 354 }
351 355
352 _muteAppHandler() { 356 _muteAppHandler() {
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}
diff --git a/src/stores/ServicesStore.js b/src/stores/ServicesStore.js
index e22b343e7..8f217ea94 100644
--- a/src/stores/ServicesStore.js
+++ b/src/stores/ServicesStore.js
@@ -67,9 +67,14 @@ export default class ServicesStore extends Store {
67 } 67 }
68 68
69 setup() { 69 setup() {
70 // Single key reactions 70 // Single key reactions for the sake of your CPU
71 reaction( 71 reaction(
72 () => this.stores.settings.all.app.enableSpellchecking, 72 () => this.stores.settings.app.enableSpellchecking,
73 () => this._shareSettingsWithServiceProcess(),
74 );
75
76 reaction(
77 () => this.stores.settings.app.spellcheckerLanguage,
73 () => this._shareSettingsWithServiceProcess(), 78 () => this._shareSettingsWithServiceProcess(),
74 ); 79 );
75 } 80 }
@@ -590,9 +595,10 @@ export default class ServicesStore extends Store {
590 } 595 }
591 596
592 _shareSettingsWithServiceProcess() { 597 _shareSettingsWithServiceProcess() {
598 const settings = this.stores.settings.app;
593 this.actions.service.sendIPCMessageToAllServices({ 599 this.actions.service.sendIPCMessageToAllServices({
594 channel: 'settings-update', 600 channel: 'settings-update',
595 args: this.stores.settings.all.app, 601 args: settings,
596 }); 602 });
597 } 603 }
598 604
diff --git a/src/stores/SettingsStore.js b/src/stores/SettingsStore.js
index b62ac15e0..4a42ed924 100644
--- a/src/stores/SettingsStore.js
+++ b/src/stores/SettingsStore.js
@@ -5,8 +5,10 @@ import localStorage from 'mobx-localstorage';
5import Store from './lib/Store'; 5import Store from './lib/Store';
6import Request from './lib/Request'; 6import Request from './lib/Request';
7import CachedRequest from './lib/CachedRequest'; 7import CachedRequest from './lib/CachedRequest';
8import { getLocale } from '../helpers/i18n-helpers';
8 9
9import { DEFAULT_APP_SETTINGS, FILE_SYSTEM_SETTINGS_TYPES } from '../config'; 10import { DEFAULT_APP_SETTINGS, FILE_SYSTEM_SETTINGS_TYPES } from '../config';
11import { SPELLCHECKER_LOCALES } from '../i18n/languages';
10 12
11const { systemPreferences } = remote; 13const { systemPreferences } = remote;
12const debug = require('debug')('Franz:SettingsStore'); 14const debug = require('debug')('Franz:SettingsStore');
@@ -41,7 +43,6 @@ export default class SettingsStore extends Store {
41 }); 43 });
42 44
43 this.fileSystemSettingsTypes.forEach((type) => { 45 this.fileSystemSettingsTypes.forEach((type) => {
44 console.log(type);
45 ipcRenderer.send('getAppSettings', type); 46 ipcRenderer.send('getAppSettings', type);
46 }); 47 });
47 } 48 }
@@ -157,10 +158,18 @@ export default class SettingsStore extends Store {
157 158
158 // Enable dark mode once 159 // Enable dark mode once
159 if (!this.all.migration['5.0.0-beta.19-settings']) { 160 if (!this.all.migration['5.0.0-beta.19-settings']) {
161 const spellcheckerLanguage = getLocale({
162 locale: this.stores.settings.app.locale,
163 locales: SPELLCHECKER_LOCALES,
164 defaultLocale: DEFAULT_APP_SETTINGS.spellcheckerLanguage,
165 fallbackLocale: DEFAULT_APP_SETTINGS.spellcheckerLanguage,
166 });
167
160 this.actions.settings.update({ 168 this.actions.settings.update({
161 type: 'app', 169 type: 'app',
162 data: { 170 data: {
163 darkMode: systemPreferences.isDarkMode(), 171 darkMode: systemPreferences.isDarkMode(),
172 spellcheckerLanguage,
164 }, 173 },
165 }); 174 });
166 175
diff --git a/src/stores/index.js b/src/stores/index.js
index 96b844c95..f547d0a7a 100644
--- a/src/stores/index.js
+++ b/src/stores/index.js
@@ -9,6 +9,7 @@ import UIStore from './UIStore';
9import PaymentStore from './PaymentStore'; 9import PaymentStore from './PaymentStore';
10import NewsStore from './NewsStore'; 10import NewsStore from './NewsStore';
11import RequestStore from './RequestStore'; 11import RequestStore from './RequestStore';
12import DictionaryStore from './DictionaryStore';
12import GlobalErrorStore from './GlobalErrorStore'; 13import GlobalErrorStore from './GlobalErrorStore';
13 14
14export default (api, actions, router) => { 15export default (api, actions, router) => {
@@ -26,6 +27,7 @@ export default (api, actions, router) => {
26 payment: new PaymentStore(stores, api, actions), 27 payment: new PaymentStore(stores, api, actions),
27 news: new NewsStore(stores, api, actions), 28 news: new NewsStore(stores, api, actions),
28 requests: new RequestStore(stores, api, actions), 29 requests: new RequestStore(stores, api, actions),
30 dictionary: new DictionaryStore(stores, api, actions),
29 globalError: new GlobalErrorStore(stores, api, actions), 31 globalError: new GlobalErrorStore(stores, api, actions),
30 }); 32 });
31 // Initialize all stores 33 // Initialize all stores