diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/index.js | 14 | ||||
-rw-r--r-- | src/webview/recipe.js | 9 | ||||
-rw-r--r-- | src/webview/spellchecker.ts | 26 |
3 files changed, 26 insertions, 23 deletions
diff --git a/src/index.js b/src/index.js index 758b11dc9..97a4f0379 100644 --- a/src/index.js +++ b/src/index.js | |||
@@ -550,6 +550,20 @@ ipcMain.on('stop-find-in-page', (e, action) => { | |||
550 | e.returnValue = null; | 550 | e.returnValue = null; |
551 | }); | 551 | }); |
552 | 552 | ||
553 | ipcMain.on('set-spellchecker-locales', (e, { locale, serviceId }) => { | ||
554 | if (serviceId === undefined) { | ||
555 | return; | ||
556 | } | ||
557 | |||
558 | const serviceSession = session.fromPartition(`persist:service-${serviceId}`); | ||
559 | const [defaultLocale] = serviceSession.getSpellCheckerLanguages(); | ||
560 | debug(`Spellchecker default locale is: ${defaultLocale}`); | ||
561 | |||
562 | const locales = [locale, defaultLocale, DEFAULT_APP_SETTINGS.fallbackLocale]; | ||
563 | debug(`Setting spellchecker locales to: ${locales}`); | ||
564 | serviceSession.setSpellCheckerLanguages(locales); | ||
565 | }); | ||
566 | |||
553 | // Quit when all windows are closed. | 567 | // Quit when all windows are closed. |
554 | app.on('window-all-closed', () => { | 568 | app.on('window-all-closed', () => { |
555 | // On OS X it is common for applications and their menu bar | 569 | // On OS X it is common for applications and their menu bar |
diff --git a/src/webview/recipe.js b/src/webview/recipe.js index 32df0f756..892b08e54 100644 --- a/src/webview/recipe.js +++ b/src/webview/recipe.js | |||
@@ -100,7 +100,7 @@ window.open = (url, frameName, features) => { | |||
100 | } | 100 | } |
101 | }; | 101 | }; |
102 | 102 | ||
103 | // We can't override APIs here, so we first expose functions via window.ferdi, | 103 | // We can't override APIs here, so we first expose functions via 'window.ferdi', |
104 | // then overwrite the corresponding field of the window object by injected JS. | 104 | // then overwrite the corresponding field of the window object by injected JS. |
105 | contextBridge.exposeInMainWorld('ferdi', { | 105 | contextBridge.exposeInMainWorld('ferdi', { |
106 | open: window.open, | 106 | open: window.open, |
@@ -108,7 +108,6 @@ contextBridge.exposeInMainWorld('ferdi', { | |||
108 | safeParseInt: text => badgeHandler.safeParseInt(text), | 108 | safeParseInt: text => badgeHandler.safeParseInt(text), |
109 | displayNotification: (title, options) => | 109 | displayNotification: (title, options) => |
110 | notificationsHandler.displayNotification(title, options), | 110 | notificationsHandler.displayNotification(title, options), |
111 | releaseServiceWorkers: () => sessionHandler.releaseServiceWorkers(), | ||
112 | getDisplayMediaSelector, | 111 | getDisplayMediaSelector, |
113 | }); | 112 | }); |
114 | 113 | ||
@@ -275,8 +274,8 @@ class RecipeController { | |||
275 | } | 274 | } |
276 | 275 | ||
277 | if (this.settings.app.enableSpellchecking) { | 276 | if (this.settings.app.enableSpellchecking) { |
278 | debug('Setting spellchecker language to', this.spellcheckerLanguage); | ||
279 | let { spellcheckerLanguage } = this; | 277 | let { spellcheckerLanguage } = this; |
278 | debug(`Setting spellchecker language to ${spellcheckerLanguage}`); | ||
280 | if (spellcheckerLanguage.includes('automatic')) { | 279 | if (spellcheckerLanguage.includes('automatic')) { |
281 | this.automaticLanguageDetection(); | 280 | this.automaticLanguageDetection(); |
282 | debug( | 281 | debug( |
@@ -285,7 +284,7 @@ class RecipeController { | |||
285 | ); | 284 | ); |
286 | spellcheckerLanguage = this.settings.app.locale; | 285 | spellcheckerLanguage = this.settings.app.locale; |
287 | } | 286 | } |
288 | switchDict(spellcheckerLanguage); | 287 | switchDict(spellcheckerLanguage, this.settings.service.id); |
289 | } else { | 288 | } else { |
290 | debug('Disable spellchecker'); | 289 | debug('Disable spellchecker'); |
291 | } | 290 | } |
@@ -440,7 +439,7 @@ class RecipeController { | |||
440 | spellcheckerLocale, | 439 | spellcheckerLocale, |
441 | ); | 440 | ); |
442 | if (spellcheckerLocale) { | 441 | if (spellcheckerLocale) { |
443 | switchDict(spellcheckerLocale); | 442 | switchDict(spellcheckerLocale, this.settings.service.id); |
444 | } | 443 | } |
445 | }, 225), | 444 | }, 225), |
446 | ); | 445 | ); |
diff --git a/src/webview/spellchecker.ts b/src/webview/spellchecker.ts index d0f6663d5..468a1b4ae 100644 --- a/src/webview/spellchecker.ts +++ b/src/webview/spellchecker.ts | |||
@@ -1,35 +1,25 @@ | |||
1 | import { getCurrentWebContents } from '@electron/remote'; | 1 | import { ipcRenderer } from 'electron'; |
2 | import { SPELLCHECKER_LOCALES } from '../i18n/languages'; | 2 | import { SPELLCHECKER_LOCALES } from '../i18n/languages'; |
3 | import { DEFAULT_APP_SETTINGS, isMac } from '../environment'; | 3 | import { isMac } from '../environment'; |
4 | 4 | ||
5 | const debug = require('debug')('Ferdi:spellchecker'); | 5 | const debug = require('debug')('Ferdi:spellchecker'); |
6 | 6 | ||
7 | const { session } = getCurrentWebContents(); | ||
8 | const [defaultLocale] = session.getSpellCheckerLanguages(); | ||
9 | debug('Spellchecker default locale is', defaultLocale); | ||
10 | |||
11 | export function getSpellcheckerLocaleByFuzzyIdentifier(identifier: string) { | 7 | export function getSpellcheckerLocaleByFuzzyIdentifier(identifier: string) { |
12 | const locales = Object.keys(SPELLCHECKER_LOCALES).filter((key) => key.toLocaleLowerCase() === identifier.toLowerCase() || key.split('-')[0] === identifier.toLowerCase()); | 8 | const locales = Object.keys(SPELLCHECKER_LOCALES).filter((key) => key.toLocaleLowerCase() === identifier.toLowerCase() || key.split('-')[0] === identifier.toLowerCase()); |
13 | 9 | ||
14 | return locales.length > 0 ? locales[0] : null; | 10 | return locales.length > 0 ? locales[0] : null; |
15 | } | 11 | } |
16 | 12 | ||
17 | export function switchDict(locale: string) { | 13 | export function switchDict(fuzzyLocale: string, serviceId: string) { |
18 | if (isMac) { | 14 | if (isMac) { |
19 | debug('Ignoring dictionary changes on macOS'); | 15 | debug('Ignoring dictionary changes on macOS'); |
20 | return; | 16 | return; |
21 | } | 17 | } |
22 | 18 | ||
23 | debug('Setting spellchecker locale to', locale); | 19 | debug(`Setting spellchecker locale from: ${fuzzyLocale}`); |
24 | 20 | const locale = getSpellcheckerLocaleByFuzzyIdentifier(fuzzyLocale); | |
25 | const locales: string[] = []; | 21 | if (locale) { |
26 | 22 | debug(`Sending spellcheck locales to host: ${locale}`); | |
27 | const foundLocale = getSpellcheckerLocaleByFuzzyIdentifier(locale); | 23 | ipcRenderer.send('set-spellchecker-locales', { locale, serviceId }); |
28 | if (foundLocale) { | ||
29 | locales.push(foundLocale); | ||
30 | } | 24 | } |
31 | |||
32 | locales.push(defaultLocale, DEFAULT_APP_SETTINGS.fallbackLocale); | ||
33 | |||
34 | session.setSpellCheckerLanguages(locales); | ||
35 | } | 25 | } |