diff options
author | 2018-12-08 22:33:58 +0100 | |
---|---|---|
committer | 2018-12-08 22:33:58 +0100 | |
commit | e5c1751c3dc691458ba9e870d4849e4872db2ff1 (patch) | |
tree | 6a1f94eaaf4b2a43e92b58b73eb651ce1fa5f1f9 /src/webview | |
parent | Only show loader on initial service load (diff) | |
download | ferdium-app-e5c1751c3dc691458ba9e870d4849e4872db2ff1.tar.gz ferdium-app-e5c1751c3dc691458ba9e870d4849e4872db2ff1.tar.zst ferdium-app-e5c1751c3dc691458ba9e870d4849e4872db2ff1.zip |
Minor recipe plugin polishing
Diffstat (limited to 'src/webview')
-rw-r--r-- | src/webview/contextMenu.js | 12 | ||||
-rw-r--r-- | src/webview/recipe.js | 12 | ||||
-rw-r--r-- | src/webview/spellchecker.js | 6 |
3 files changed, 22 insertions, 8 deletions
diff --git a/src/webview/contextMenu.js b/src/webview/contextMenu.js index f9afa1913..0349a5d6c 100644 --- a/src/webview/contextMenu.js +++ b/src/webview/contextMenu.js | |||
@@ -22,7 +22,7 @@ function delUnusedElements(menuTpl) { | |||
22 | }); | 22 | }); |
23 | } | 23 | } |
24 | 24 | ||
25 | const buildMenuTpl = (props, suggestions, defaultSpellcheckerLanguage, spellcheckerLanguage) => { | 25 | const buildMenuTpl = (props, suggestions, isSpellcheckEnabled, defaultSpellcheckerLanguage, spellcheckerLanguage) => { |
26 | const { editFlags } = props; | 26 | const { editFlags } = props; |
27 | const textSelection = props.selectionText.trim(); | 27 | const textSelection = props.selectionText.trim(); |
28 | const hasText = textSelection.length > 0; | 28 | const hasText = textSelection.length > 0; |
@@ -205,11 +205,14 @@ const buildMenuTpl = (props, suggestions, defaultSpellcheckerLanguage, spellchec | |||
205 | }); | 205 | }); |
206 | }); | 206 | }); |
207 | 207 | ||
208 | console.log('isSpellcheckEnabled', isSpellcheckEnabled); | ||
209 | |||
208 | menuTpl.push({ | 210 | menuTpl.push({ |
209 | type: 'separator', | 211 | type: 'separator', |
210 | }, { | 212 | }, { |
211 | id: 'spellchecker', | 213 | id: 'spellchecker', |
212 | label: 'Spellchecker', | 214 | label: 'Spell Checking', |
215 | visible: isSpellcheckEnabled, | ||
213 | submenu: [ | 216 | submenu: [ |
214 | { | 217 | { |
215 | id: 'spellchecker', | 218 | id: 'spellchecker', |
@@ -222,6 +225,7 @@ const buildMenuTpl = (props, suggestions, defaultSpellcheckerLanguage, spellchec | |||
222 | id: 'resetToDefault', | 225 | id: 'resetToDefault', |
223 | label: `Reset to system default (${SPELLCHECKER_LOCALES[defaultSpellcheckerLanguage]})`, | 226 | label: `Reset to system default (${SPELLCHECKER_LOCALES[defaultSpellcheckerLanguage]})`, |
224 | type: 'radio', | 227 | type: 'radio', |
228 | visible: defaultSpellcheckerLanguage !== spellcheckerLanguage, | ||
225 | click() { | 229 | click() { |
226 | debug('Resetting service spellchecker to system default'); | 230 | debug('Resetting service spellchecker to system default'); |
227 | ipcRenderer.sendToHost('set-service-spellchecker-language', 'reset'); | 231 | ipcRenderer.sendToHost('set-service-spellchecker-language', 'reset'); |
@@ -229,6 +233,7 @@ const buildMenuTpl = (props, suggestions, defaultSpellcheckerLanguage, spellchec | |||
229 | }, | 233 | }, |
230 | { | 234 | { |
231 | type: 'separator', | 235 | type: 'separator', |
236 | visible: defaultSpellcheckerLanguage !== spellcheckerLanguage, | ||
232 | }, | 237 | }, |
233 | ...spellcheckingLanguages], | 238 | ...spellcheckingLanguages], |
234 | }); | 239 | }); |
@@ -249,7 +254,7 @@ const buildMenuTpl = (props, suggestions, defaultSpellcheckerLanguage, spellchec | |||
249 | return delUnusedElements(menuTpl); | 254 | return delUnusedElements(menuTpl); |
250 | }; | 255 | }; |
251 | 256 | ||
252 | export default function contextMenu(spellcheckProvider, getDefaultSpellcheckerLanguage, getSpellcheckerLanguage) { | 257 | export default function contextMenu(spellcheckProvider, isSpellcheckEnabled, getDefaultSpellcheckerLanguage, getSpellcheckerLanguage) { |
253 | webContents.on('context-menu', (e, props) => { | 258 | webContents.on('context-menu', (e, props) => { |
254 | e.preventDefault(); | 259 | e.preventDefault(); |
255 | 260 | ||
@@ -264,6 +269,7 @@ export default function contextMenu(spellcheckProvider, getDefaultSpellcheckerLa | |||
264 | buildMenuTpl( | 269 | buildMenuTpl( |
265 | props, | 270 | props, |
266 | suggestions.slice(0, 5), | 271 | suggestions.slice(0, 5), |
272 | isSpellcheckEnabled(), | ||
267 | getDefaultSpellcheckerLanguage(), | 273 | getDefaultSpellcheckerLanguage(), |
268 | getSpellcheckerLanguage(), | 274 | getSpellcheckerLanguage(), |
269 | ), | 275 | ), |
diff --git a/src/webview/recipe.js b/src/webview/recipe.js index a2c157af8..c9117ac72 100644 --- a/src/webview/recipe.js +++ b/src/webview/recipe.js | |||
@@ -9,13 +9,18 @@ import { injectDarkModeStyle, isDarkModeStyleInjected, removeDarkModeStyle } fro | |||
9 | import contextMenu from './contextMenu'; | 9 | import contextMenu from './contextMenu'; |
10 | import './notifications'; | 10 | import './notifications'; |
11 | 11 | ||
12 | import { DEFAULT_APP_SETTINGS } from '../config'; | ||
13 | |||
12 | const debug = require('debug')('Franz:Plugin'); | 14 | const debug = require('debug')('Franz:Plugin'); |
13 | 15 | ||
14 | class RecipeController { | 16 | class RecipeController { |
15 | @observable settings = { | 17 | @observable settings = { |
16 | overrideSpellcheckerLanguage: false, | 18 | overrideSpellcheckerLanguage: false, |
17 | app: {}, | 19 | app: DEFAULT_APP_SETTINGS, |
18 | service: {}, | 20 | service: { |
21 | isDarkModeEnabled: false, | ||
22 | spellcheckerLanguage: '', | ||
23 | }, | ||
19 | }; | 24 | }; |
20 | 25 | ||
21 | spellcheckProvider = null; | 26 | spellcheckProvider = null; |
@@ -49,6 +54,7 @@ class RecipeController { | |||
49 | this.spellcheckingProvider = await spellchecker(); | 54 | this.spellcheckingProvider = await spellchecker(); |
50 | contextMenu( | 55 | contextMenu( |
51 | this.spellcheckingProvider, | 56 | this.spellcheckingProvider, |
57 | () => this.settings.app.enableSpellchecking, | ||
52 | () => this.settings.app.spellcheckerLanguage, | 58 | () => this.settings.app.spellcheckerLanguage, |
53 | () => this.spellcheckerLanguage); | 59 | () => this.spellcheckerLanguage); |
54 | 60 | ||
@@ -81,10 +87,10 @@ class RecipeController { | |||
81 | debug('Setting spellchecker language to', this.spellcheckerLanguage); | 87 | debug('Setting spellchecker language to', this.spellcheckerLanguage); |
82 | switchDict(this.spellcheckerLanguage); | 88 | switchDict(this.spellcheckerLanguage); |
83 | } else { | 89 | } else { |
90 | debug('Disable spellchecker'); | ||
84 | disableSpellchecker(); | 91 | disableSpellchecker(); |
85 | } | 92 | } |
86 | 93 | ||
87 | console.log(this.settings.service); | ||
88 | if (this.settings.service.isDarkModeEnabled) { | 94 | if (this.settings.service.isDarkModeEnabled) { |
89 | debug('Enable dark mode'); | 95 | debug('Enable dark mode'); |
90 | injectDarkModeStyle(this.settings.service.recipe.path); | 96 | injectDarkModeStyle(this.settings.service.recipe.path); |
diff --git a/src/webview/spellchecker.js b/src/webview/spellchecker.js index f1bae1cd7..becaed449 100644 --- a/src/webview/spellchecker.js +++ b/src/webview/spellchecker.js | |||
@@ -4,7 +4,6 @@ import path from 'path'; | |||
4 | 4 | ||
5 | import { DICTIONARY_PATH } from '../config'; | 5 | import { DICTIONARY_PATH } from '../config'; |
6 | 6 | ||
7 | |||
8 | const debug = require('debug')('Franz:spellchecker'); | 7 | const debug = require('debug')('Franz:spellchecker'); |
9 | 8 | ||
10 | let provider; | 9 | let provider; |
@@ -15,6 +14,7 @@ async function loadDictionary(locale) { | |||
15 | try { | 14 | try { |
16 | const fileLocation = path.join(DICTIONARY_PATH, `hunspell-dict-${locale}/${locale}`); | 15 | const fileLocation = path.join(DICTIONARY_PATH, `hunspell-dict-${locale}/${locale}`); |
17 | await provider.loadDictionary(locale, `${fileLocation}.dic`, `${fileLocation}.aff`); | 16 | await provider.loadDictionary(locale, `${fileLocation}.dic`, `${fileLocation}.aff`); |
17 | debug('Loaded dictionary', locale, 'from', fileLocation); | ||
18 | } catch (err) { | 18 | } catch (err) { |
19 | console.error('Could not load dictionary', err); | 19 | console.error('Could not load dictionary', err); |
20 | } | 20 | } |
@@ -36,7 +36,9 @@ export async function switchDict(locale) { | |||
36 | return; | 36 | return; |
37 | } | 37 | } |
38 | 38 | ||
39 | provider.unloadDictionary(locale); | 39 | if (currentDict) { |
40 | provider.unloadDictionary(locale); | ||
41 | } | ||
40 | loadDictionary(locale); | 42 | loadDictionary(locale); |
41 | provider.switchDictionary(locale); | 43 | provider.switchDictionary(locale); |
42 | 44 | ||