diff options
author | Stefan Malzner <stefan@adlk.io> | 2019-10-03 17:15:46 +0200 |
---|---|---|
committer | Stefan Malzner <stefan@adlk.io> | 2019-10-03 17:15:46 +0200 |
commit | 6e5bf64ef3ef858a5cc40025f61f3b1cf550d4fe (patch) | |
tree | 0429f9b7af2ff312dfbdb4b184a6cbeec28969ca /src/webview | |
parent | Automatic i18n update (i18n.meetfranz.com) (diff) | |
parent | update strings (diff) | |
download | ferdium-app-6e5bf64ef3ef858a5cc40025f61f3b1cf550d4fe.tar.gz ferdium-app-6e5bf64ef3ef858a5cc40025f61f3b1cf550d4fe.tar.zst ferdium-app-6e5bf64ef3ef858a5cc40025f61f3b1cf550d4fe.zip |
Merge branch 'release/5.4.0' into i18n
Diffstat (limited to 'src/webview')
-rw-r--r-- | src/webview/contextMenu.js | 9 | ||||
-rw-r--r-- | src/webview/recipe.js | 36 | ||||
-rw-r--r-- | src/webview/spellchecker.js | 48 |
3 files changed, 67 insertions, 26 deletions
diff --git a/src/webview/contextMenu.js b/src/webview/contextMenu.js index 83914f581..d3b976554 100644 --- a/src/webview/contextMenu.js +++ b/src/webview/contextMenu.js | |||
@@ -255,9 +255,9 @@ const buildMenuTpl = (props, suggestions, isSpellcheckEnabled, defaultSpellcheck | |||
255 | }, | 255 | }, |
256 | { | 256 | { |
257 | id: 'resetToDefault', | 257 | id: 'resetToDefault', |
258 | label: `Reset to system default (${SPELLCHECKER_LOCALES[defaultSpellcheckerLanguage]})`, | 258 | label: `Reset to system default (${defaultSpellcheckerLanguage === 'automatic' ? 'Automatic' : SPELLCHECKER_LOCALES[defaultSpellcheckerLanguage]})`, |
259 | type: 'radio', | 259 | type: 'radio', |
260 | visible: defaultSpellcheckerLanguage !== spellcheckerLanguage, | 260 | visible: defaultSpellcheckerLanguage !== spellcheckerLanguage || (defaultSpellcheckerLanguage !== 'automatic' && spellcheckerLanguage === 'automatic'), |
261 | click() { | 261 | click() { |
262 | debug('Resetting service spellchecker to system default'); | 262 | debug('Resetting service spellchecker to system default'); |
263 | ipcRenderer.sendToHost('set-service-spellchecker-language', 'reset'); | 263 | ipcRenderer.sendToHost('set-service-spellchecker-language', 'reset'); |
@@ -297,12 +297,13 @@ const buildMenuTpl = (props, suggestions, isSpellcheckEnabled, defaultSpellcheck | |||
297 | }; | 297 | }; |
298 | 298 | ||
299 | export default function contextMenu(spellcheckProvider, isSpellcheckEnabled, getDefaultSpellcheckerLanguage, getSpellcheckerLanguage) { | 299 | export default function contextMenu(spellcheckProvider, isSpellcheckEnabled, getDefaultSpellcheckerLanguage, getSpellcheckerLanguage) { |
300 | webContents.on('context-menu', (e, props) => { | 300 | webContents.on('context-menu', async (e, props) => { |
301 | e.preventDefault(); | 301 | e.preventDefault(); |
302 | 302 | ||
303 | let suggestions = []; | 303 | let suggestions = []; |
304 | if (spellcheckProvider && props.misspelledWord) { | 304 | if (spellcheckProvider && props.misspelledWord) { |
305 | suggestions = spellcheckProvider.getSuggestion(props.misspelledWord); | 305 | debug('Mispelled word', props.misspelledWord); |
306 | suggestions = await spellcheckProvider.getSuggestion(props.misspelledWord); | ||
306 | 307 | ||
307 | debug('Suggestions', suggestions); | 308 | debug('Suggestions', suggestions); |
308 | } | 309 | } |
diff --git a/src/webview/recipe.js b/src/webview/recipe.js index c223b73de..e3e13b726 100644 --- a/src/webview/recipe.js +++ b/src/webview/recipe.js | |||
@@ -12,6 +12,7 @@ import contextMenu from './contextMenu'; | |||
12 | import './notifications'; | 12 | import './notifications'; |
13 | 13 | ||
14 | import { DEFAULT_APP_SETTINGS } from '../config'; | 14 | import { DEFAULT_APP_SETTINGS } from '../config'; |
15 | import { isDevMode } from '../environment'; | ||
15 | 16 | ||
16 | const debug = require('debug')('Franz:Plugin'); | 17 | const debug = require('debug')('Franz:Plugin'); |
17 | 18 | ||
@@ -32,7 +33,7 @@ class RecipeController { | |||
32 | 'settings-update': 'updateAppSettings', | 33 | 'settings-update': 'updateAppSettings', |
33 | 'service-settings-update': 'updateServiceSettings', | 34 | 'service-settings-update': 'updateServiceSettings', |
34 | 'get-service-id': 'serviceIdEcho', | 35 | 'get-service-id': 'serviceIdEcho', |
35 | } | 36 | }; |
36 | 37 | ||
37 | constructor() { | 38 | constructor() { |
38 | this.initialize(); | 39 | this.initialize(); |
@@ -173,11 +174,42 @@ new RecipeController(); | |||
173 | // Patching window.open | 174 | // Patching window.open |
174 | const originalWindowOpen = window.open; | 175 | const originalWindowOpen = window.open; |
175 | 176 | ||
177 | |||
176 | window.open = (url, frameName, features) => { | 178 | window.open = (url, frameName, features) => { |
179 | if (!url && !frameName && !features) { | ||
180 | // The service hasn't yet supplied a URL (as used in Skype). | ||
181 | // Return a new dummy window object and wait for the service to change the properties | ||
182 | const newWindow = { | ||
183 | location: { | ||
184 | href: '', | ||
185 | }, | ||
186 | }; | ||
187 | |||
188 | const checkInterval = setInterval(() => { | ||
189 | // Has the service changed the URL yet? | ||
190 | if (newWindow.location.href !== '') { | ||
191 | // Open the new URL | ||
192 | ipcRenderer.sendToHost('new-window', newWindow.location.href); | ||
193 | clearInterval(checkInterval); | ||
194 | } | ||
195 | }, 0); | ||
196 | |||
197 | setTimeout(() => { | ||
198 | // Stop checking for location changes after 1 second | ||
199 | clearInterval(checkInterval); | ||
200 | }, 1000); | ||
201 | |||
202 | return newWindow; | ||
203 | } | ||
204 | |||
177 | // We need to differentiate if the link should be opened in a popup or in the systems default browser | 205 | // We need to differentiate if the link should be opened in a popup or in the systems default browser |
178 | if (!frameName && !features) { | 206 | if (!frameName && !features && typeof features !== 'string') { |
179 | return ipcRenderer.sendToHost('new-window', url); | 207 | return ipcRenderer.sendToHost('new-window', url); |
180 | } | 208 | } |
181 | 209 | ||
182 | return originalWindowOpen(url, frameName, features); | 210 | return originalWindowOpen(url, frameName, features); |
183 | }; | 211 | }; |
212 | |||
213 | if (isDevMode) { | ||
214 | window.log = console.log; | ||
215 | } | ||
diff --git a/src/webview/spellchecker.js b/src/webview/spellchecker.js index 9158b3b94..06cbd283a 100644 --- a/src/webview/spellchecker.js +++ b/src/webview/spellchecker.js | |||
@@ -1,6 +1,7 @@ | |||
1 | import { webFrame } from 'electron'; | 1 | import { webFrame } from 'electron'; |
2 | import { SpellCheckerProvider } from 'electron-hunspell'; | 2 | import { attachSpellCheckProvider, SpellCheckerProvider } from 'electron-hunspell'; |
3 | import path from 'path'; | 3 | import path from 'path'; |
4 | import { readFileSync } from 'fs'; | ||
4 | 5 | ||
5 | import { DICTIONARY_PATH } from '../config'; | 6 | import { DICTIONARY_PATH } from '../config'; |
6 | import { SPELLCHECKER_LOCALES } from '../i18n/languages'; | 7 | import { SPELLCHECKER_LOCALES } from '../i18n/languages'; |
@@ -10,18 +11,21 @@ const debug = require('debug')('Franz:spellchecker'); | |||
10 | let provider; | 11 | let provider; |
11 | let currentDict; | 12 | let currentDict; |
12 | let _isEnabled = false; | 13 | let _isEnabled = false; |
14 | let attached; | ||
15 | |||
16 | const DEFAULT_LOCALE = 'en-us'; | ||
13 | 17 | ||
14 | async function loadDictionary(locale) { | 18 | async function loadDictionary(locale) { |
15 | try { | 19 | try { |
16 | const fileLocation = path.join(DICTIONARY_PATH, `hunspell-dict-${locale}/${locale}`); | 20 | const fileLocation = path.join(DICTIONARY_PATH, `hunspell-dict-${locale}/${locale}`); |
17 | await provider.loadDictionary(locale, `${fileLocation}.dic`, `${fileLocation}.aff`); | ||
18 | debug('Loaded dictionary', locale, 'from', fileLocation); | 21 | debug('Loaded dictionary', locale, 'from', fileLocation); |
22 | return provider.loadDictionary(locale, readFileSync(`${fileLocation}.dic`), readFileSync(`${fileLocation}.aff`)); | ||
19 | } catch (err) { | 23 | } catch (err) { |
20 | console.error('Could not load dictionary', err); | 24 | console.error('Could not load dictionary', err); |
21 | } | 25 | } |
22 | } | 26 | } |
23 | 27 | ||
24 | export async function switchDict(locale) { | 28 | export async function switchDict(locale = DEFAULT_LOCALE) { |
25 | try { | 29 | try { |
26 | debug('Trying to load dictionary', locale); | 30 | debug('Trying to load dictionary', locale); |
27 | 31 | ||
@@ -40,8 +44,8 @@ export async function switchDict(locale) { | |||
40 | if (currentDict) { | 44 | if (currentDict) { |
41 | provider.unloadDictionary(locale); | 45 | provider.unloadDictionary(locale); |
42 | } | 46 | } |
43 | loadDictionary(locale); | 47 | await loadDictionary(locale); |
44 | provider.switchDictionary(locale); | 48 | await attached.switchLanguage(locale); |
45 | 49 | ||
46 | debug('Switched dictionary to', locale); | 50 | debug('Switched dictionary to', locale); |
47 | 51 | ||
@@ -52,18 +56,32 @@ export async function switchDict(locale) { | |||
52 | } | 56 | } |
53 | } | 57 | } |
54 | 58 | ||
55 | export default async function initialize(languageCode = 'en-us') { | 59 | export function getSpellcheckerLocaleByFuzzyIdentifier(identifier) { |
60 | const locales = Object.keys(SPELLCHECKER_LOCALES).filter(key => key === identifier.toLowerCase() || key.split('-')[0] === identifier.toLowerCase()); | ||
61 | |||
62 | if (locales.length >= 1) { | ||
63 | return locales[0]; | ||
64 | } | ||
65 | |||
66 | return null; | ||
67 | } | ||
68 | |||
69 | export default async function initialize(languageCode = DEFAULT_LOCALE) { | ||
56 | try { | 70 | try { |
57 | provider = new SpellCheckerProvider(); | 71 | provider = new SpellCheckerProvider(); |
58 | const locale = languageCode.toLowerCase(); | 72 | const locale = getSpellcheckerLocaleByFuzzyIdentifier(languageCode); |
59 | 73 | ||
60 | debug('Init spellchecker'); | 74 | debug('Init spellchecker'); |
61 | await provider.initialize(); | 75 | await provider.initialize(); |
62 | // await loadDictionaries(); | ||
63 | 76 | ||
64 | debug('Available spellchecker dictionaries', provider.availableDictionaries); | 77 | debug('Attaching spellcheck provider'); |
78 | attached = await attachSpellCheckProvider(provider); | ||
79 | |||
80 | const availableDictionaries = await provider.getAvailableDictionaries(); | ||
65 | 81 | ||
66 | switchDict(locale); | 82 | debug('Available spellchecker dictionaries', availableDictionaries); |
83 | |||
84 | await switchDict(locale); | ||
67 | 85 | ||
68 | return provider; | 86 | return provider; |
69 | } catch (err) { | 87 | } catch (err) { |
@@ -83,13 +101,3 @@ export function disable() { | |||
83 | currentDict = null; | 101 | currentDict = null; |
84 | } | 102 | } |
85 | } | 103 | } |
86 | |||
87 | export function getSpellcheckerLocaleByFuzzyIdentifier(identifier) { | ||
88 | const locales = Object.keys(SPELLCHECKER_LOCALES).filter(key => key === identifier.toLowerCase() || key.split('-')[0] === identifier.toLowerCase()); | ||
89 | |||
90 | if (locales.length >= 1) { | ||
91 | return locales[0]; | ||
92 | } | ||
93 | |||
94 | return null; | ||
95 | } | ||