Fixed dictionary initialization

This commit is contained in:
Mr. Stallion 2020-04-12 09:07:09 -05:00
parent 326e1b9445
commit 50ef1f3c15
4 changed files with 21 additions and 11 deletions

View File

@ -47,7 +47,7 @@
import Vue from 'vue'; import Vue from 'vue';
import l from '../chat/localize'; import l from '../chat/localize';
import {GeneralSettings} from './common'; import {GeneralSettings} from './common';
import { getSafeLanguages } from './language'; import { getSafeLanguages, updateSupportedLanguages } from './language';
const browserWindow = electron.remote.getCurrentWindow(); const browserWindow = electron.remote.getCurrentWindow();
@ -89,7 +89,11 @@
@Hook('mounted') @Hook('mounted')
async mounted(): Promise<void> { async mounted(): Promise<void> {
// top bar devtools // 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)); browserWindow.webContents.session.setSpellCheckerLanguages(getSafeLanguages(this.settings.spellcheckLang));
@ -103,6 +107,8 @@
electron.ipcRenderer.on('quit', () => this.destroyAllTabs()); electron.ipcRenderer.on('quit', () => this.destroyAllTabs());
electron.ipcRenderer.on('update-dictionaries', (_e: Event, langs: string[]) => { electron.ipcRenderer.on('update-dictionaries', (_e: Event, langs: string[]) => {
// console.log('UPDATE DICTIONARIES', langs);
browserWindow.webContents.session.setSpellCheckerLanguages(langs); browserWindow.webContents.session.setSpellCheckerLanguages(langs);
for (const t of this.tabs) { for (const t of this.tabs) {
@ -145,7 +151,7 @@
document.addEventListener('click', () => this.activeTab!.view.webContents.focus()); document.addEventListener('click', () => this.activeTab!.view.webContents.focus());
window.addEventListener('focus', () => this.activeTab!.view.webContents.focus()); window.addEventListener('focus', () => this.activeTab!.view.webContents.focus());
console.log('SORTABLE', Sortable); // console.log('SORTABLE', Sortable);
Sortable.create(<HTMLElement>this.$refs['tabs'], { Sortable.create(<HTMLElement>this.$refs['tabs'], {
animation: 50, animation: 50,
@ -216,8 +222,9 @@
const view = new electron.remote.BrowserView({webPreferences: {webviewTag: true, nodeIntegration: true, spellcheck: true}}); const view = new electron.remote.BrowserView({webPreferences: {webviewTag: true, nodeIntegration: true, spellcheck: true}});
// tab devtools // 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.webContents.session.setSpellCheckerLanguages(getSafeLanguages(this.settings.spellcheckLang));
view.setAutoResize({width: true, height: true}); view.setAutoResize({width: true, height: true});

View File

@ -9,7 +9,7 @@ export function getSafeLanguages(langs: string | string[] | undefined): string[]
const initialCount = initialLanguages.length; const initialCount = initialLanguages.length;
const safeLanguages = _.filter(initialLanguages, (il) => (_.indexOf(supportedLanguages, il) >= 0)); const safeLanguages = _.filter(initialLanguages, (il) => (_.indexOf(supportedLanguages, il) >= 0));
if ((initialCount > 0) && (safeLanguages.length)) { if ((initialCount > 0) && (!safeLanguages.length)) {
safeLanguages.push('en-GB'); safeLanguages.push('en-GB');
} }

View File

@ -90,6 +90,8 @@ if(!settings.hwAcceleration) {
export function updateSpellCheckerLanguages(langs: string[]): void { export function updateSpellCheckerLanguages(langs: string[]): void {
// console.log('UPDATESPELLCHECKERLANGUAGES', langs);
// console.log('Language support:', langs); // console.log('Language support:', langs);
electron.session.defaultSession.setSpellCheckerLanguages(langs); electron.session.defaultSession.setSpellCheckerLanguages(langs);
@ -181,7 +183,11 @@ function createWindow(): Electron.BrowserWindow | undefined {
const window = new electron.BrowserWindow(windowProperties); const window = new electron.BrowserWindow(windowProperties);
windows.push(window); 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); electron.session.defaultSession.setSpellCheckerLanguages(safeLanguages);
window.webContents.session.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 // tslint:disable-next-line:no-floating-promises
window.loadFile( window.loadFile(
@ -290,8 +295,6 @@ function onReady(): void {
log.transports.file.file = path.join(baseDir, 'log.txt'); log.transports.file.file = path.join(baseDir, 'log.txt');
log.info('Starting application.'); log.info('Starting application.');
updateSupportedLanguages(electron.session.defaultSession.availableSpellCheckerLanguages);
app.setAppUserModelId('com.squirrel.fchat.F-Chat'); app.setAppUserModelId('com.squirrel.fchat.F-Chat');
app.on('open-file', createWindow); app.on('open-file', createWindow);

View File

@ -54,7 +54,7 @@ This repository contains a heavily customized version of the mainline F-Chat 3.0
* Message search matches character names * Message search matches character names
* PM list shows characters' online status as a colored icon * PM list shows characters' online status as a colored icon
* Technical Details for Nerds * 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 * 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) * Multi-language support for spell checking (Windows only language is autodetected on MacOS)