From 50ef1f3c1563da9f63a1ad3bed135a979a565e38 Mon Sep 17 00:00:00 2001 From: "Mr. Stallion" Date: Sun, 12 Apr 2020 09:07:09 -0500 Subject: [PATCH] Fixed dictionary initialization --- electron/Window.vue | 15 +++++++++++---- electron/language.ts | 2 +- electron/main.ts | 13 ++++++++----- readme.md | 2 +- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/electron/Window.vue b/electron/Window.vue index 4bebf67..9057a4c 100644 --- a/electron/Window.vue +++ b/electron/Window.vue @@ -47,7 +47,7 @@ import Vue from 'vue'; import l from '../chat/localize'; import {GeneralSettings} from './common'; - import { getSafeLanguages } from './language'; + import { getSafeLanguages, updateSupportedLanguages } from './language'; const browserWindow = electron.remote.getCurrentWindow(); @@ -89,7 +89,11 @@ @Hook('mounted') async mounted(): Promise { // top bar devtools - // browserWindow.webContents.openDevTools({ mode: 'detach' }); + browserWindow.webContents.openDevTools({ mode: 'detach' }); + + updateSupportedLanguages(browserWindow.webContents.session.availableSpellCheckerLanguages); + + // console.log('MOUNT DICTIONARIES', getSafeLanguages(this.settings.spellcheckLang), this.settings.spellcheckLang); browserWindow.webContents.session.setSpellCheckerLanguages(getSafeLanguages(this.settings.spellcheckLang)); @@ -103,6 +107,8 @@ electron.ipcRenderer.on('quit', () => this.destroyAllTabs()); electron.ipcRenderer.on('update-dictionaries', (_e: Event, langs: string[]) => { + // console.log('UPDATE DICTIONARIES', langs); + browserWindow.webContents.session.setSpellCheckerLanguages(langs); for (const t of this.tabs) { @@ -145,7 +151,7 @@ document.addEventListener('click', () => this.activeTab!.view.webContents.focus()); window.addEventListener('focus', () => this.activeTab!.view.webContents.focus()); - console.log('SORTABLE', Sortable); + // console.log('SORTABLE', Sortable); Sortable.create(this.$refs['tabs'], { animation: 50, @@ -216,8 +222,9 @@ const view = new electron.remote.BrowserView({webPreferences: {webviewTag: true, nodeIntegration: true, spellcheck: true}}); // tab devtools - // view.webContents.openDevTools(); + view.webContents.openDevTools(); + // console.log('ADD TAB LANGUAGES', getSafeLanguages(this.settings.spellcheckLang), this.settings.spellcheckLang); view.webContents.session.setSpellCheckerLanguages(getSafeLanguages(this.settings.spellcheckLang)); view.setAutoResize({width: true, height: true}); diff --git a/electron/language.ts b/electron/language.ts index 0b2f4d9..191bf5f 100644 --- a/electron/language.ts +++ b/electron/language.ts @@ -9,7 +9,7 @@ export function getSafeLanguages(langs: string | string[] | undefined): string[] const initialCount = initialLanguages.length; const safeLanguages = _.filter(initialLanguages, (il) => (_.indexOf(supportedLanguages, il) >= 0)); - if ((initialCount > 0) && (safeLanguages.length)) { + if ((initialCount > 0) && (!safeLanguages.length)) { safeLanguages.push('en-GB'); } diff --git a/electron/main.ts b/electron/main.ts index 39bbbbe..b48ee2f 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -90,6 +90,8 @@ if(!settings.hwAcceleration) { export function updateSpellCheckerLanguages(langs: string[]): void { + // console.log('UPDATESPELLCHECKERLANGUAGES', langs); + // console.log('Language support:', langs); electron.session.defaultSession.setSpellCheckerLanguages(langs); @@ -181,7 +183,11 @@ function createWindow(): Electron.BrowserWindow | undefined { const window = new electron.BrowserWindow(windowProperties); windows.push(window); - const safeLanguages = settings.spellcheckLang ? _.castArray(settings.spellcheckLang) : []; + updateSupportedLanguages(electron.session.defaultSession.availableSpellCheckerLanguages); + + const safeLanguages = getSafeLanguages(settings.spellcheckLang); + + // console.log('CREATEWINDOW', safeLanguages); electron.session.defaultSession.setSpellCheckerLanguages(safeLanguages); window.webContents.session.setSpellCheckerLanguages(safeLanguages); @@ -247,8 +253,7 @@ function createWindow(): Electron.BrowserWindow | undefined { } ); - - console.log('GOT HERE'); + // console.log('GOT HERE'); // tslint:disable-next-line:no-floating-promises window.loadFile( @@ -290,8 +295,6 @@ function onReady(): void { log.transports.file.file = path.join(baseDir, 'log.txt'); log.info('Starting application.'); - updateSupportedLanguages(electron.session.defaultSession.availableSpellCheckerLanguages); - app.setAppUserModelId('com.squirrel.fchat.F-Chat'); app.on('open-file', createWindow); diff --git a/readme.md b/readme.md index 61e6ab8..67d38d1 100644 --- a/readme.md +++ b/readme.md @@ -54,7 +54,7 @@ This repository contains a heavily customized version of the mainline F-Chat 3.0 * Message search matches character names * PM list shows characters' online status as a colored icon * Technical Details for Nerds - * Upgraded to Electron 8.x + * Upgraded to Electron 9.x * Replaced `node-spellchecker` with the built-in spellchecker that ships with Electron 8 * Multi-language support for spell checking (Windows only – language is autodetected on MacOS)