diff options
author | 2018-12-07 20:25:42 +0100 | |
---|---|---|
committer | 2018-12-07 20:25:42 +0100 | |
commit | baf7d60af40e9cc3ce5403c5e109331098d5e1d6 (patch) | |
tree | 1973e6304b04088dc6ff9324b7e73fb52c400c9e /src/webview | |
parent | Update package-lock.json (diff) | |
download | ferdium-app-baf7d60af40e9cc3ce5403c5e109331098d5e1d6.tar.gz ferdium-app-baf7d60af40e9cc3ce5403c5e109331098d5e1d6.tar.zst ferdium-app-baf7d60af40e9cc3ce5403c5e109331098d5e1d6.zip |
feat(Service): Add option to change spellchecking language by service
Diffstat (limited to 'src/webview')
-rw-r--r-- | src/webview/plugin.js | 31 | ||||
-rw-r--r-- | src/webview/spellchecker.js | 2 |
2 files changed, 28 insertions, 5 deletions
diff --git a/src/webview/plugin.js b/src/webview/plugin.js index 72530733d..6d4e65062 100644 --- a/src/webview/plugin.js +++ b/src/webview/plugin.js | |||
@@ -1,5 +1,6 @@ | |||
1 | import { ipcRenderer } from 'electron'; | 1 | import { ipcRenderer } from 'electron'; |
2 | import path from 'path'; | 2 | import path from 'path'; |
3 | import { observable } from 'mobx'; | ||
3 | 4 | ||
4 | import RecipeWebview from './lib/RecipeWebview'; | 5 | import RecipeWebview from './lib/RecipeWebview'; |
5 | 6 | ||
@@ -12,6 +13,8 @@ const debug = require('debug')('Franz:Plugin'); | |||
12 | 13 | ||
13 | window.franzSettings = {}; | 14 | window.franzSettings = {}; |
14 | let serviceData; | 15 | let serviceData; |
16 | let overrideSpellcheckerLanguage = false; | ||
17 | |||
15 | 18 | ||
16 | ipcRenderer.on('initializeRecipe', (e, data) => { | 19 | ipcRenderer.on('initializeRecipe', (e, data) => { |
17 | const modulePath = path.join(data.recipe.path, 'webview.js'); | 20 | const modulePath = path.join(data.recipe.path, 'webview.js'); |
@@ -28,6 +31,13 @@ ipcRenderer.on('initializeRecipe', (e, data) => { | |||
28 | injectDarkModeStyle(data.recipe.path); | 31 | injectDarkModeStyle(data.recipe.path); |
29 | debug('Add dark theme styles'); | 32 | debug('Add dark theme styles'); |
30 | } | 33 | } |
34 | |||
35 | if (data.spellcheckerLanguage) { | ||
36 | debug('Overriding spellchecker language to', data.spellcheckerLanguage); | ||
37 | switchDict(data.spellcheckerLanguage); | ||
38 | |||
39 | overrideSpellcheckerLanguage = true; | ||
40 | } | ||
31 | } catch (err) { | 41 | } catch (err) { |
32 | debug('Recipe initialization failed', err); | 42 | debug('Recipe initialization failed', err); |
33 | } | 43 | } |
@@ -42,10 +52,11 @@ ipcRenderer.on('initializeRecipe', (e, data) => { | |||
42 | ipcRenderer.on('settings-update', async (e, data) => { | 52 | ipcRenderer.on('settings-update', async (e, data) => { |
43 | debug('Settings update received', data); | 53 | debug('Settings update received', data); |
44 | 54 | ||
45 | if (data.enableSpellchecking) { | 55 | if (!data.enableSpellchecking) { |
46 | switchDict(data.spellcheckerLanguage); | ||
47 | } else { | ||
48 | disableSpellchecker(); | 56 | disableSpellchecker(); |
57 | } else if (!overrideSpellcheckerLanguage) { | ||
58 | debug('Setting spellchecker language based on app settings to', data.spellcheckerLanguage); | ||
59 | switchDict(data.spellcheckerLanguage); | ||
49 | } | 60 | } |
50 | 61 | ||
51 | window.franzSettings = data; | 62 | window.franzSettings = data; |
@@ -54,6 +65,8 @@ ipcRenderer.on('settings-update', async (e, data) => { | |||
54 | ipcRenderer.on('service-settings-update', (e, data) => { | 65 | ipcRenderer.on('service-settings-update', (e, data) => { |
55 | debug('Service settings update received', data); | 66 | debug('Service settings update received', data); |
56 | 67 | ||
68 | serviceData = data; | ||
69 | |||
57 | if (data.isDarkModeEnabled && !isDarkModeStyleInjected()) { | 70 | if (data.isDarkModeEnabled && !isDarkModeStyleInjected()) { |
58 | injectDarkModeStyle(serviceData.recipe.path); | 71 | injectDarkModeStyle(serviceData.recipe.path); |
59 | 72 | ||
@@ -63,6 +76,18 @@ ipcRenderer.on('service-settings-update', (e, data) => { | |||
63 | 76 | ||
64 | debug('Disable service dark mode'); | 77 | debug('Disable service dark mode'); |
65 | } | 78 | } |
79 | |||
80 | if (data.spellcheckerLanguage) { | ||
81 | debug('Overriding spellchecker language to', data.spellcheckerLanguage); | ||
82 | switchDict(data.spellcheckerLanguage); | ||
83 | |||
84 | overrideSpellcheckerLanguage = true; | ||
85 | } else { | ||
86 | debug('Going back to default spellchecker language to', window.franzSettings.spellcheckerLanguage); | ||
87 | switchDict(window.franzSettings.spellcheckerLanguage); | ||
88 | |||
89 | overrideSpellcheckerLanguage = false; | ||
90 | } | ||
66 | }); | 91 | }); |
67 | 92 | ||
68 | // Needed for current implementation of electrons 'login' event 🤦 | 93 | // Needed for current implementation of electrons 'login' event 🤦 |
diff --git a/src/webview/spellchecker.js b/src/webview/spellchecker.js index ab0cc9a90..f1bae1cd7 100644 --- a/src/webview/spellchecker.js +++ b/src/webview/spellchecker.js | |||
@@ -13,9 +13,7 @@ let _isEnabled = false; | |||
13 | 13 | ||
14 | async function loadDictionary(locale) { | 14 | async function loadDictionary(locale) { |
15 | try { | 15 | try { |
16 | // Replacing app.asar is not beautiful but unforunately necessary | ||
17 | const fileLocation = path.join(DICTIONARY_PATH, `hunspell-dict-${locale}/${locale}`); | 16 | const fileLocation = path.join(DICTIONARY_PATH, `hunspell-dict-${locale}/${locale}`); |
18 | console.log(fileLocation, __dirname); | ||
19 | await provider.loadDictionary(locale, `${fileLocation}.dic`, `${fileLocation}.aff`); | 17 | await provider.loadDictionary(locale, `${fileLocation}.dic`, `${fileLocation}.aff`); |
20 | } catch (err) { | 18 | } catch (err) { |
21 | console.error('Could not load dictionary', err); | 19 | console.error('Could not load dictionary', err); |