upgrade to electron v16 and node v16

This commit is contained in:
zadam
2021-11-16 22:43:08 +01:00
parent b7efc92099
commit 89322c4b03
17 changed files with 228 additions and 90 deletions

View File

@@ -101,6 +101,8 @@ require('./services/consistency_checks');
require('./services/scheduler');
require('@electron/remote/main').initialize();
module.exports = {
app,
sessionParser

View File

@@ -34,7 +34,9 @@ noteAutocompleteService.init();
if (utils.isElectron()) {
const electron = utils.dynamicRequire('electron');
const {webContents} = electron.remote.getCurrentWindow();
const remote = utils.dynamicRequire('@electron/remote');
const {webContents} = remote.getCurrentWindow();
webContents.on('context-menu', (event, params) => {
const {editFlags} = params;

View File

@@ -122,7 +122,7 @@ export default class ProtectedSessionOptions {
this.$availableLanguageCodes = $("#available-language-codes");
if (utils.isElectron()) {
const {webContents} = utils.dynamicRequire('electron').remote.getCurrentWindow();
const {webContents} = utils.dynamicRequire('@electron/remote').getCurrentWindow();
this.$availableLanguageCodes.text(webContents.session.availableSpellCheckerLanguages.join(', '));
}

View File

@@ -35,7 +35,7 @@ export default class Entrypoints extends Component {
openDevToolsCommand() {
if (utils.isElectron()) {
utils.dynamicRequire('electron').remote.getCurrentWindow().toggleDevTools();
utils.dynamicRequire('@electron/remote').getCurrentWindow().toggleDevTools();
}
}
@@ -44,7 +44,7 @@ export default class Entrypoints extends Component {
return;
}
const {remote} = utils.dynamicRequire('electron');
const remote = utils.dynamicRequire('@electron/remote');
const {FindInPage} = utils.dynamicRequire('electron-find');
const findInPage = new FindInPage(remote.getCurrentWebContents(), {
offsetTop: 10,
@@ -116,7 +116,7 @@ export default class Entrypoints extends Component {
toggleFullscreenCommand() {
if (utils.isElectron()) {
const win = utils.dynamicRequire('electron').remote.getCurrentWindow();
const win = utils.dynamicRequire('@electron/remote').getCurrentWindow();
if (win.isFullScreenable()) {
win.setFullScreen(!win.isFullScreen());
@@ -143,7 +143,7 @@ export default class Entrypoints extends Component {
backInNoteHistoryCommand() {
if (utils.isElectron()) {
// standard JS version does not work completely correctly in electron
const webContents = utils.dynamicRequire('electron').remote.getCurrentWebContents();
const webContents = utils.dynamicRequire('@electron/remote').getCurrentWebContents();
const activeIndex = parseInt(webContents.getActiveIndex());
webContents.goToIndex(activeIndex - 1);
@@ -156,7 +156,7 @@ export default class Entrypoints extends Component {
forwardInNoteHistoryCommand() {
if (utils.isElectron()) {
// standard JS version does not work completely correctly in electron
const webContents = utils.dynamicRequire('electron').remote.getCurrentWebContents();
const webContents = utils.dynamicRequire('@electron/remote').getCurrentWebContents();
const activeIndex = parseInt(webContents.getActiveIndex());
webContents.goToIndex(activeIndex + 1);

View File

@@ -7,7 +7,7 @@ function getFileUrl(noteId) {
function download(url) {
if (utils.isElectron()) {
const remote = utils.dynamicRequire('electron').remote;
const remote = utils.dynamicRequire('@electron/remote');
remote.getCurrentWebContents().downloadURL(url);
} else {

View File

@@ -138,7 +138,7 @@ ws.subscribeToMessages(message => {
appContext.tabManager.activateOrOpenNote(message.noteId);
if (utils.isElectron()) {
const currentWindow = utils.dynamicRequire("electron").remote.getCurrentWindow();
const currentWindow = utils.dynamicRequire('@electron/remote').getCurrentWindow();
currentWindow.show();
}

View File

@@ -279,7 +279,7 @@ function isHtmlEmpty(html) {
async function clearBrowserCache() {
if (isElectron()) {
const win = dynamicRequire('electron').remote.getCurrentWindow();
const win = utils.dynamicRequire('@electron/remote').getCurrentWindow();
await win.webContents.session.clearCache();
}
}

View File

@@ -122,7 +122,7 @@ async function checkOutstandingSyncs() {
if (initialized) {
if (utils.isElectron()) {
const remote = utils.dynamicRequire('electron').remote;
const remote = utils.dynamicRequire('@electron/remote');
remote.app.relaunch();
remote.app.exit(0);
}

View File

@@ -42,8 +42,7 @@ export default class HistoryNavigationWidget extends BasicWidget {
this.$forwardInHistory = this.$widget.find("[data-trigger-command='forwardInNoteHistory']");
this.$forwardInHistory.on('contextmenu', contextMenuHandler);
const electron = utils.dynamicRequire('electron');
this.webContents = electron.remote.getCurrentWindow().webContents;
this.webContents = utils.dynamicRequire('@electron/remote').webContents;
// without this the history is preserved across frontend reloads
this.webContents.clearHistory();

View File

@@ -49,13 +49,13 @@ export default class TitleBarButtonsWidget extends BasicWidget {
$minimizeBtn.on('click', () => {
$minimizeBtn.trigger('blur');
const {remote} = utils.dynamicRequire('electron');
const remote = utils.dynamicRequire('@electron/remote');
remote.BrowserWindow.getFocusedWindow().minimize();
});
$maximizeBtn.on('click', () => {
$maximizeBtn.trigger('blur');
const {remote} = utils.dynamicRequire('electron');
const remote = utils.dynamicRequire('@electron/remote');
const focusedWindow = remote.BrowserWindow.getFocusedWindow();
if (focusedWindow.isMaximized()) {
@@ -67,7 +67,7 @@ export default class TitleBarButtonsWidget extends BasicWidget {
$closeBtn.on('click', () => {
$closeBtn.trigger('blur');
const {remote} = utils.dynamicRequire('electron');
const remote = utils.dynamicRequire('@electron/remote');
remote.BrowserWindow.getFocusedWindow().close();
});
}

View File

@@ -59,7 +59,6 @@ async function createMainWindow() {
height: mainWindowState.height,
title: 'Trilium Notes',
webPreferences: {
enableRemoteModule: true,
nodeIntegration: true,
contextIsolation: false,
spellcheck: spellcheckEnabled
@@ -76,6 +75,8 @@ async function createMainWindow() {
const {webContents} = mainWindow;
require("@electron/remote/main").enable(webContents);
webContents.on('new-window', (e, url) => {
if (url !== webContents.getURL()) {
e.preventDefault();