From a40f9e8eb9e536d554b699f2dc428cc532cbc6f6 Mon Sep 17 00:00:00 2001 From: Vijay Aravamudhan Date: Tue, 21 Sep 2021 02:17:28 +0530 Subject: 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 --- CHANGELOG.md | 8 +++++++- src/index.js | 14 ++++++++++++++ src/webview/recipe.js | 9 ++++----- src/webview/spellchecker.ts | 26 ++++++++------------------ 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 @@ +# [v5.6.3-nightly.9](https://github.com/getferdi/ferdi/compare/v5.6.3-nightly.8...v5.6.3-nightly.9) (2021-09-21) + +### Under the hood + +- Removed more references to `@electron/remote` from the codebase (#1968) 💖 #kris7t, @vraravam + # [v5.6.3-nightly.8](https://github.com/getferdi/ferdi/compare/v5.6.3-nightly.7...v5.6.3-nightly.8) (2021-09-20) ### Under the hood -- Removed the final references to `@electron/remote` from the codebase (#1967) 💖 @vraravam +- Removed more references to `@electron/remote` from the codebase (#1967) 💖 #kris7t, @vraravam # [v5.6.3-nightly.7](https://github.com/getferdi/ferdi/compare/v5.6.3-nightly.4...v5.6.3-nightly.7) (2021-09-19) 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) => { e.returnValue = null; }); +ipcMain.on('set-spellchecker-locales', (e, { locale, serviceId }) => { + if (serviceId === undefined) { + return; + } + + const serviceSession = session.fromPartition(`persist:service-${serviceId}`); + const [defaultLocale] = serviceSession.getSpellCheckerLanguages(); + debug(`Spellchecker default locale is: ${defaultLocale}`); + + const locales = [locale, defaultLocale, DEFAULT_APP_SETTINGS.fallbackLocale]; + debug(`Setting spellchecker locales to: ${locales}`); + serviceSession.setSpellCheckerLanguages(locales); +}); + // Quit when all windows are closed. app.on('window-all-closed', () => { // 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) => { } }; -// We can't override APIs here, so we first expose functions via window.ferdi, +// We can't override APIs here, so we first expose functions via 'window.ferdi', // then overwrite the corresponding field of the window object by injected JS. contextBridge.exposeInMainWorld('ferdi', { open: window.open, @@ -108,7 +108,6 @@ contextBridge.exposeInMainWorld('ferdi', { safeParseInt: text => badgeHandler.safeParseInt(text), displayNotification: (title, options) => notificationsHandler.displayNotification(title, options), - releaseServiceWorkers: () => sessionHandler.releaseServiceWorkers(), getDisplayMediaSelector, }); @@ -275,8 +274,8 @@ class RecipeController { } if (this.settings.app.enableSpellchecking) { - debug('Setting spellchecker language to', this.spellcheckerLanguage); let { spellcheckerLanguage } = this; + debug(`Setting spellchecker language to ${spellcheckerLanguage}`); if (spellcheckerLanguage.includes('automatic')) { this.automaticLanguageDetection(); debug( @@ -285,7 +284,7 @@ class RecipeController { ); spellcheckerLanguage = this.settings.app.locale; } - switchDict(spellcheckerLanguage); + switchDict(spellcheckerLanguage, this.settings.service.id); } else { debug('Disable spellchecker'); } @@ -440,7 +439,7 @@ class RecipeController { spellcheckerLocale, ); if (spellcheckerLocale) { - switchDict(spellcheckerLocale); + switchDict(spellcheckerLocale, this.settings.service.id); } }, 225), ); 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 @@ -import { getCurrentWebContents } from '@electron/remote'; +import { ipcRenderer } from 'electron'; import { SPELLCHECKER_LOCALES } from '../i18n/languages'; -import { DEFAULT_APP_SETTINGS, isMac } from '../environment'; +import { isMac } from '../environment'; const debug = require('debug')('Ferdi:spellchecker'); -const { session } = getCurrentWebContents(); -const [defaultLocale] = session.getSpellCheckerLanguages(); -debug('Spellchecker default locale is', defaultLocale); - export function getSpellcheckerLocaleByFuzzyIdentifier(identifier: string) { const locales = Object.keys(SPELLCHECKER_LOCALES).filter((key) => key.toLocaleLowerCase() === identifier.toLowerCase() || key.split('-')[0] === identifier.toLowerCase()); return locales.length > 0 ? locales[0] : null; } -export function switchDict(locale: string) { +export function switchDict(fuzzyLocale: string, serviceId: string) { if (isMac) { debug('Ignoring dictionary changes on macOS'); return; } - debug('Setting spellchecker locale to', locale); - - const locales: string[] = []; - - const foundLocale = getSpellcheckerLocaleByFuzzyIdentifier(locale); - if (foundLocale) { - locales.push(foundLocale); + debug(`Setting spellchecker locale from: ${fuzzyLocale}`); + const locale = getSpellcheckerLocaleByFuzzyIdentifier(fuzzyLocale); + if (locale) { + debug(`Sending spellcheck locales to host: ${locale}`); + ipcRenderer.send('set-spellchecker-locales', { locale, serviceId }); } - - locales.push(defaultLocale, DEFAULT_APP_SETTINGS.fallbackLocale); - - session.setSpellCheckerLanguages(locales); } -- cgit v1.2.3-54-g00ecf