From 035002ceedf78d5ec73eabc0df7f06139939b967 Mon Sep 17 00:00:00 2001 From: Amine El Mouafik <412895+kytwb@users.noreply.github.com> Date: Mon, 8 Feb 2021 10:34:45 +0100 Subject: Synchronize with Franz 5.6.0 (#1033) Co-authored-by: FranzBot Co-authored-by: vantezzen Co-authored-by: Makazzz Co-authored-by: Stefan Malzner Co-authored-by: Amine Mouafik --- src/webview/recipe.js | 61 +++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 33 deletions(-) (limited to 'src/webview/recipe.js') diff --git a/src/webview/recipe.js b/src/webview/recipe.js index 675f8e311..d29f3edbd 100644 --- a/src/webview/recipe.js +++ b/src/webview/recipe.js @@ -3,7 +3,6 @@ import { ipcRenderer, remote, desktopCapturer } from 'electron'; import path from 'path'; import { autorun, computed, observable } from 'mobx'; import fs from 'fs-extra'; -import { loadModule } from 'cld3-asm'; import { debounce } from 'lodash'; import { FindInPage } from 'electron-find'; @@ -23,8 +22,9 @@ import customDarkModeCss from './darkmode/custom'; import RecipeWebview from './lib/RecipeWebview'; import Userscript from './lib/Userscript'; -import spellchecker, { switchDict, disable as disableSpellchecker, getSpellcheckerLocaleByFuzzyIdentifier } from './spellchecker'; +import { switchDict, getSpellcheckerLocaleByFuzzyIdentifier } from './spellchecker'; import { injectDarkModeStyle, isDarkModeStyleInjected, removeDarkModeStyle } from './darkmode'; +import contextMenu from './contextMenu'; import './notifications'; import { DEFAULT_APP_SETTINGS } from '../config'; @@ -156,7 +156,14 @@ class RecipeController { debug('Send "hello" to host'); setTimeout(() => ipcRenderer.sendToHost('hello'), 100); - await spellchecker(); + + this.spellcheckingProvider = null; + contextMenu( + () => this.settings.app.enableSpellchecking, + () => this.settings.app.spellcheckerLanguage, + () => this.spellcheckerLanguage, + ); + autorun(() => this.update()); document.addEventListener('DOMContentLoaded', () => { @@ -240,22 +247,15 @@ class RecipeController { if (this.settings.app.enableSpellchecking) { debug('Setting spellchecker language to', this.spellcheckerLanguage); - const { spellcheckerLanguage } = this; + let { spellcheckerLanguage } = this; if (spellcheckerLanguage.includes('automatic')) { this.automaticLanguageDetection(); debug('Found `automatic` locale, falling back to user locale until detected', this.settings.app.locale); - spellcheckerLanguage.push(this.settings.app.locale); - } else if (this.cldIdentifier) { - this.cldIdentifier.destroy(); + spellcheckerLanguage = this.settings.app.locale; } switchDict(spellcheckerLanguage); } else { debug('Disable spellchecker'); - disableSpellchecker(); - - if (this.cldIdentifier) { - this.cldIdentifier.destroy(); - } } if (!this.recipe) { @@ -366,10 +366,7 @@ class RecipeController { } async automaticLanguageDetection() { - const cldFactory = await loadModule(); - this.cldIdentifier = cldFactory.create(0, 1000); - - window.addEventListener('keyup', debounce((e) => { + window.addEventListener('keyup', debounce(async (e) => { const element = e.target; if (!element) return; @@ -382,22 +379,15 @@ class RecipeController { } // Force a minimum length to get better detection results - if (value.length < 30) return; + if (value.length < 25) return; debug('Detecting language for', value); - const findResult = this.cldIdentifier.findLanguage(value); - - debug('Language detection result', findResult); - - if (findResult.is_reliable) { - const spellcheckerLocale = getSpellcheckerLocaleByFuzzyIdentifier(findResult.language); - debug('Language detected reliably, setting spellchecker language to', spellcheckerLocale); - if (spellcheckerLocale) { - switchDict([ - ...this.spellcheckerLanguage, - spellcheckerLocale, - ]); - } + const locale = await ipcRenderer.invoke('detect-language', { sample: value }); + + const spellcheckerLocale = getSpellcheckerLocaleByFuzzyIdentifier(locale); + debug('Language detected reliably, setting spellchecker language to', spellcheckerLocale); + if (spellcheckerLocale) { + switchDict(spellcheckerLocale); } }, 225)); } @@ -411,7 +401,8 @@ new RecipeController(); const originalWindowOpen = window.open; window.open = (url, frameName, features) => { - if (!url && !frameName && !features) { + debug('window.open', url, frameName, features); + if (!url) { // The service hasn't yet supplied a URL (as used in Skype). // Return a new dummy window object and wait for the service to change the properties const newWindow = { @@ -423,8 +414,12 @@ window.open = (url, frameName, features) => { const checkInterval = setInterval(() => { // Has the service changed the URL yet? if (newWindow.location.href !== '') { - // Open the new URL - ipcRenderer.sendToHost('new-window', newWindow.location.href); + if (features) { + originalWindowOpen(newWindow.location.href, frameName, features); + } else { + // Open the new URL + ipcRenderer.sendToHost('new-window', newWindow.location.href); + } clearInterval(checkInterval); } }, 0); -- cgit v1.2.3-54-g00ecf