use electron 8 spellchecker instead of electron-spellchecker, WIP

This commit is contained in:
zadam
2020-02-28 22:07:08 +01:00
parent a2d6a5c3e9
commit 16f42dd4ab
30 changed files with 98 additions and 74 deletions

View File

@@ -121,15 +121,13 @@ async function exportToTar(taskContext, branch, format, res) {
type: note.type,
mime: note.mime,
// we don't export utcDateCreated and utcDateModified of any entity since that would be a bit misleading
attributes: (await note.getOwnedAttributes()).map(attribute => {
return {
attributes: (await note.getOwnedAttributes()).map(attribute => ({
type: attribute.type,
name: attribute.name,
value: attribute.value,
isInheritable: attribute.isInheritable,
position: attribute.position
};
})
}))
};
taskContext.increaseProgressCount();

View File

@@ -102,13 +102,11 @@ async function initStartupOptions() {
function getKeyboardDefaultOptions() {
return keyboardActions.DEFAULT_KEYBOARD_ACTIONS
.filter(ka => !!ka.actionName)
.map(ka => {
return {
name: "keyboardShortcuts" + ka.actionName.charAt(0).toUpperCase() + ka.actionName.slice(1),
value: JSON.stringify(ka.defaultShortcuts),
isSynced: false
};
});
.map(ka => ({
name: "keyboardShortcuts" + ka.actionName.charAt(0).toUpperCase() + ka.actionName.slice(1),
value: JSON.stringify(ka.defaultShortcuts),
isSynced: false
}));
}
module.exports = {

View File

@@ -23,6 +23,8 @@ async function createMainWindow() {
defaultHeight: 800
});
const spellcheckEnabled = await optionService.getOptionBool('spellCheckEnabled');
const {BrowserWindow} = require('electron'); // should not be statically imported
mainWindow = new BrowserWindow({
x: mainWindowState.x,
@@ -31,7 +33,8 @@ async function createMainWindow() {
height: mainWindowState.height,
title: 'Trilium Notes',
webPreferences: {
nodeIntegration: true
nodeIntegration: true,
spellcheck: spellcheckEnabled
},
frame: await optionService.getOptionBool('nativeTitleBarVisible'),
icon: getIcon()
@@ -43,15 +46,17 @@ async function createMainWindow() {
mainWindow.loadURL('http://127.0.0.1:' + await port);
mainWindow.on('closed', () => mainWindow = null);
mainWindow.webContents.on('new-window', (e, url) => {
if (url !== mainWindow.webContents.getURL()) {
const {webContents} = mainWindow;
webContents.on('new-window', (e, url) => {
if (url !== webContents.getURL()) {
e.preventDefault();
require('electron').shell.openExternal(url);
}
});
// prevent drag & drop to navigate away from trilium
mainWindow.webContents.on('will-navigate', (ev, targetUrl) => {
webContents.on('will-navigate', (ev, targetUrl) => {
const parsedUrl = url.parse(targetUrl);
// we still need to allow internal redirects from setup and migration pages
@@ -59,6 +64,14 @@ async function createMainWindow() {
ev.preventDefault();
}
});
if (spellcheckEnabled) {
const languageCodes = (await optionService.getOption('spellCheckLanguageCode'))
.split('/')
.map(code => code.trim());
webContents.session.setSpellCheckerLanguages(languageCodes);
}
}
function getIcon() {