aboutsummaryrefslogtreecommitdiffstats
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
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
-rw-r--r--CHANGELOG.md8
-rw-r--r--src/index.js14
-rw-r--r--src/webview/recipe.js9
-rw-r--r--src/webview/spellchecker.ts26
4 files changed, 33 insertions, 24 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a625aeee4..94c2c1eda 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,8 +1,14 @@
1# [v5.6.3-nightly.9](https://github.com/getferdi/ferdi/compare/v5.6.3-nightly.8...v5.6.3-nightly.9) (2021-09-21)
2
3### Under the hood
4
5- Removed more references to `@electron/remote` from the codebase (#1968) 💖 #kris7t, @vraravam
6
1# [v5.6.3-nightly.8](https://github.com/getferdi/ferdi/compare/v5.6.3-nightly.7...v5.6.3-nightly.8) (2021-09-20) 7# [v5.6.3-nightly.8](https://github.com/getferdi/ferdi/compare/v5.6.3-nightly.7...v5.6.3-nightly.8) (2021-09-20)
2 8
3### Under the hood 9### Under the hood
4 10
5- Removed the final references to `@electron/remote` from the codebase (#1967) 💖 @vraravam 11- Removed more references to `@electron/remote` from the codebase (#1967) 💖 #kris7t, @vraravam
6 12
7# [v5.6.3-nightly.7](https://github.com/getferdi/ferdi/compare/v5.6.3-nightly.4...v5.6.3-nightly.7) (2021-09-19) 13# [v5.6.3-nightly.7](https://github.com/getferdi/ferdi/compare/v5.6.3-nightly.4...v5.6.3-nightly.7) (2021-09-19)
8 14
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
553ipcMain.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.
554app.on('window-all-closed', () => { 568app.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.
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}