aboutsummaryrefslogtreecommitdiffstats
path: root/src/webview
diff options
context:
space:
mode:
authorLibravatar Vijay Aravamudhan <vraravam@users.noreply.github.com>2021-09-21 02:17:28 +0530
committerLibravatar GitHub <noreply@github.com>2021-09-20 22:47:28 +0200
commita40f9e8eb9e536d554b699f2dc428cc532cbc6f6 (patch)
treec13eac23445b318219e9ec73ef28702cda8864b3 /src/webview
parent5.6.3-nightly.8 [skip ci] (diff)
downloadferdium-app-a40f9e8eb9e536d554b699f2dc428cc532cbc6f6.tar.gz
ferdium-app-a40f9e8eb9e536d554b699f2dc428cc532cbc6f6.tar.zst
ferdium-app-a40f9e8eb9e536d554b699f2dc428cc532cbc6f6.zip
remove reference to '@electron/remote' module (for spell-checker) (#1968)
* fix: remove reference to '@electron/remote' module for spell-checker * chore: removed redundant methods from being exposed via 'window.ferdi' to the recipes
Diffstat (limited to 'src/webview')
-rw-r--r--src/webview/recipe.js9
-rw-r--r--src/webview/spellchecker.ts26
2 files changed, 12 insertions, 23 deletions
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.
105contextBridge.exposeInMainWorld('ferdi', { 105contextBridge.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 @@
1import { getCurrentWebContents } from '@electron/remote'; 1import { ipcRenderer } from 'electron';
2import { SPELLCHECKER_LOCALES } from '../i18n/languages'; 2import { SPELLCHECKER_LOCALES } from '../i18n/languages';
3import { DEFAULT_APP_SETTINGS, isMac } from '../environment'; 3import { isMac } from '../environment';
4 4
5const debug = require('debug')('Ferdi:spellchecker'); 5const debug = require('debug')('Ferdi:spellchecker');
6 6
7const { session } = getCurrentWebContents();
8const [defaultLocale] = session.getSpellCheckerLanguages();
9debug('Spellchecker default locale is', defaultLocale);
10
11export function getSpellcheckerLocaleByFuzzyIdentifier(identifier: string) { 7export 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
17export function switchDict(locale: string) { 13export 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}