diff options
author | 2017-12-11 12:25:49 +0100 | |
---|---|---|
committer | 2017-12-11 12:25:49 +0100 | |
commit | c5b44c0259387030f9e3d31ae1db8903a95b6b67 (patch) | |
tree | 123e726411a33c2f0cea1eb6529d7462636c315e | |
parent | Merge pull request #421 from meetfranz/feature/bugfixing (diff) | |
download | ferdium-app-c5b44c0259387030f9e3d31ae1db8903a95b6b67.tar.gz ferdium-app-c5b44c0259387030f9e3d31ae1db8903a95b6b67.tar.zst ferdium-app-c5b44c0259387030f9e3d31ae1db8903a95b6b67.zip |
always initialize ContextMenuBuilder but not spellchecker
-rw-r--r-- | gulpfile.babel.js | 6 | ||||
-rw-r--r-- | src/webview/plugin.js | 31 | ||||
-rw-r--r-- | src/webview/spellchecker.js | 48 |
3 files changed, 54 insertions, 31 deletions
diff --git a/gulpfile.babel.js b/gulpfile.babel.js index d947974b3..b50001b2d 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js | |||
@@ -110,7 +110,11 @@ export function watch() { | |||
110 | } | 110 | } |
111 | 111 | ||
112 | export function webserver() { | 112 | export function webserver() { |
113 | gulp.src(paths.dest) | 113 | gulp.src([ |
114 | paths.dest, | ||
115 | `!${paths.dest}/electron/**`, | ||
116 | `!${paths.dest}/webview/**`, | ||
117 | ]) | ||
114 | .pipe(server({ | 118 | .pipe(server({ |
115 | livereload: true, | 119 | livereload: true, |
116 | })); | 120 | })); |
diff --git a/src/webview/plugin.js b/src/webview/plugin.js index c877132b1..610dffc8e 100644 --- a/src/webview/plugin.js +++ b/src/webview/plugin.js | |||
@@ -1,14 +1,14 @@ | |||
1 | import { ipcRenderer } from 'electron'; | 1 | import { ipcRenderer } from 'electron'; |
2 | import { ContextMenuListener, ContextMenuBuilder } from 'electron-spellchecker'; | ||
2 | import path from 'path'; | 3 | import path from 'path'; |
3 | 4 | ||
5 | import { isDevMode } from '../environment'; | ||
4 | import RecipeWebview from './lib/RecipeWebview'; | 6 | import RecipeWebview from './lib/RecipeWebview'; |
5 | 7 | ||
6 | import Spellchecker from './spellchecker.js'; | 8 | import Spellchecker from './spellchecker.js'; |
7 | import './notifications.js'; | 9 | import './notifications.js'; |
8 | import './ime.js'; | 10 | import './ime.js'; |
9 | 11 | ||
10 | const spellchecker = new Spellchecker(); | ||
11 | |||
12 | ipcRenderer.on('initializeRecipe', (e, data) => { | 12 | ipcRenderer.on('initializeRecipe', (e, data) => { |
13 | const modulePath = path.join(data.recipe.path, 'webview.js'); | 13 | const modulePath = path.join(data.recipe.path, 'webview.js'); |
14 | // Delete module from cache | 14 | // Delete module from cache |
@@ -21,20 +21,27 @@ ipcRenderer.on('initializeRecipe', (e, data) => { | |||
21 | } | 21 | } |
22 | }); | 22 | }); |
23 | 23 | ||
24 | let contextMenuBuilder = new ContextMenuBuilder(null, null, isDevMode); | ||
25 | const spellchecker = new Spellchecker(); | ||
26 | |||
27 | new ContextMenuListener((info) => { // eslint-disable-line | ||
28 | contextMenuBuilder.showPopupMenu(info); | ||
29 | }); | ||
30 | |||
24 | ipcRenderer.on('settings-update', (e, data) => { | 31 | ipcRenderer.on('settings-update', (e, data) => { |
25 | if (data.enableSpellchecking) { | 32 | if (data.enableSpellchecking && !spellchecker.isInitialized) { |
26 | if (!spellchecker.isEnabled) { | 33 | spellchecker.initialize(); |
27 | spellchecker.enable(); | 34 | |
28 | 35 | contextMenuBuilder = new ContextMenuBuilder(spellchecker.handler, null, isDevMode); | |
29 | // TODO: this does not work yet, needs more testing | 36 | |
30 | // if (data.spellcheckingLanguage !== 'auto') { | 37 | new ContextMenuListener((info) => { // eslint-disable-line |
31 | // console.log('set spellchecking language to', data.spellcheckingLanguage); | 38 | contextMenuBuilder.showPopupMenu(info); |
32 | // spellchecker.switchLanguage(data.spellcheckingLanguage); | 39 | }); |
33 | // } | ||
34 | } | ||
35 | } | 40 | } |
36 | }); | 41 | }); |
37 | 42 | ||
43 | // initSpellche | ||
44 | |||
38 | document.addEventListener('DOMContentLoaded', () => { | 45 | document.addEventListener('DOMContentLoaded', () => { |
39 | ipcRenderer.sendToHost('hello'); | 46 | ipcRenderer.sendToHost('hello'); |
40 | }, false); | 47 | }, false); |
diff --git a/src/webview/spellchecker.js b/src/webview/spellchecker.js index 5beb77e03..5704779d7 100644 --- a/src/webview/spellchecker.js +++ b/src/webview/spellchecker.js | |||
@@ -1,30 +1,42 @@ | |||
1 | import { SpellCheckHandler, ContextMenuListener, ContextMenuBuilder } from 'electron-spellchecker'; | 1 | import { SpellCheckHandler } from 'electron-spellchecker'; |
2 | 2 | ||
3 | import { isMac } from '../environment'; | 3 | import { isMac } from '../environment'; |
4 | 4 | ||
5 | export default class Spellchecker { | 5 | export default class Spellchecker { |
6 | isEnabled = false; | 6 | isInitialized = false; |
7 | spellchecker = null; | 7 | handler = null; |
8 | initRetries = 0; | ||
9 | |||
10 | initialize() { | ||
11 | this.handler = new SpellCheckHandler(); | ||
8 | 12 | ||
9 | enable() { | ||
10 | this.spellchecker = new SpellCheckHandler(); | ||
11 | if (!isMac) { | 13 | if (!isMac) { |
12 | this.spellchecker.attachToInput(); | 14 | this.attach(); |
13 | this.spellchecker.switchLanguage(navigator.language); | 15 | } else { |
16 | this.isInitialized = true; | ||
14 | } | 17 | } |
18 | } | ||
15 | 19 | ||
16 | const contextMenuBuilder = new ContextMenuBuilder(this.spellchecker); | 20 | attach() { |
21 | let initFailed = false; | ||
17 | 22 | ||
18 | new ContextMenuListener((info) => { // eslint-disable-line | 23 | if (this.initRetries > 3) { |
19 | contextMenuBuilder.showPopupMenu(info); | 24 | console.error('Could not initialize spellchecker'); |
20 | }); | 25 | return; |
21 | } | 26 | } |
22 | 27 | ||
23 | // TODO: this does not work yet, needs more testing | 28 | try { |
24 | // switchLanguage(language) { | 29 | this.handler.attachToInput(); |
25 | // if (language !== 'auto') { | 30 | this.handler.switchLanguage(navigator.language); |
26 | // this.spellchecker.switchLanguage(language); | 31 | } catch (err) { |
27 | // } | 32 | initFailed = true; |
28 | // } | 33 | this.initRetries = +1; |
34 | setTimeout(() => { this.attach(); console.warn('Spellchecker init failed, trying again in 5s'); }, 5000); | ||
35 | } | ||
36 | |||
37 | if (!initFailed) { | ||
38 | this.isInitialized = true; | ||
39 | } | ||
40 | } | ||
29 | } | 41 | } |
30 | 42 | ||