diff --git a/package.json b/package.json index 714fbb645..9a91c6734 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "qstart-electron": "npm run qswitch-electron && TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev electron --inspect=5858 .", "start-test-server": "npm run qswitch-server; rm -rf ./data-test; cross-env TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data-test TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev TRILIUM_PORT=9999 node src/www.js", "switch-server": "rm -rf ./node_modules/better-sqlite3 && npm install", - "switch-electron": "./node_modules/.bin/electron-rebuild", + "switch-electron": "npx electron-rebuild", "qswitch-server": "rm -rf ./node_modules/better-sqlite3/bin ; mkdir -p ./node_modules/better-sqlite3/build ; cp ./bin/better-sqlite3/linux-server-better_sqlite3.node ./node_modules/better-sqlite3/build/better_sqlite3.node", "qswitch-electron": "rm -rf ./node_modules/better-sqlite3/bin ; mkdir -p ./node_modules/better-sqlite3/build ; cp ./bin/better-sqlite3/linux-desktop-better_sqlite3.node ./node_modules/better-sqlite3/build/better_sqlite3.node", "build-backend-docs": "rm -rf ./docs/backend_api && ./node_modules/.bin/jsdoc -c jsdoc-conf.json -d ./docs/backend_api src/becca/entities/*.js src/services/backend_script_api.js src/services/sql.js", @@ -31,7 +31,8 @@ "test-jasmine": "TRILIUM_DATA_DIR=~/trilium/data-test jasmine", "test-es6": "node -r esm spec-es6/attribute_parser.spec.js ", "test": "npm run test-jasmine && npm run test-es6", - "postinstall": "rimraf ./node_modules/canvas" + "postinstall": "rimraf ./node_modules/canvas", + "electron-rebuild": "npx electron-rebuild" }, "dependencies": { "@braintree/sanitize-url": "6.0.4", @@ -40,7 +41,7 @@ "archiver": "7.0.0", "async-mutex": "0.4.1", "axios": "1.6.7", - "better-sqlite3": "8.7.0", + "better-sqlite3": "9.2.2", "boxicons": "2.1.4", "chokidar": "3.6.0", "cls-hooked": "4.2.2", @@ -109,11 +110,11 @@ "yauzl": "3.1.2" }, "devDependencies": { + "@electron/rebuild": "^3.6.2", "cross-env": "7.0.3", - "electron": "25.9.8", + "electron": "28.2.7", "electron-builder": "24.13.3", "electron-packager": "17.1.2", - "electron-rebuild": "3.2.9", "esm": "3.2.25", "jasmine": "5.1.0", "jsdoc": "4.0.2", diff --git a/src/app.js b/src/app.js index 45451f0cc..733e43544 100644 --- a/src/app.js +++ b/src/app.js @@ -26,10 +26,10 @@ app.use(helmet({ crossOriginEmbedderPolicy: false })); -app.use(express.text({limit: '500mb'})); -app.use(express.json({limit: '500mb'})); -app.use(express.raw({limit: '500mb'})); -app.use(express.urlencoded({extended: false})); +app.use(express.text({ limit: '500mb' })); +app.use(express.json({ limit: '500mb' })); +app.use(express.raw({ limit: '500mb' })); +app.use(express.urlencoded({ extended: false })); app.use(cookieParser()); app.use(express.static(path.join(__dirname, 'public/root'))); app.use(`/manifest.webmanifest`, express.static(path.join(__dirname, 'public/manifest.webmanifest'))); @@ -54,7 +54,8 @@ require('./services/consistency_checks.js'); require('./services/scheduler.js'); if (utils.isElectron()) { - require('@electron/remote/main').initialize(); + const { initialize } = require('@electron/remote/main'); + initialize(); } module.exports = app; diff --git a/src/services/window.js b/src/services/window.js index 68f70010a..7c5bf9d94 100644 --- a/src/services/window.js +++ b/src/services/window.js @@ -7,7 +7,8 @@ const log = require('./log.js'); const sqlInit = require('./sql_init.js'); const cls = require('./cls.js'); const keyboardActionsService = require('./keyboard_actions.js'); -const {ipcMain} = require('electron'); +const { ipcMain } = require('electron'); +const { enable: enableRemote } = require('@electron/remote/main'); // Prevent the window being garbage collected /** @type {Electron.BrowserWindow} */ @@ -18,17 +19,17 @@ let setupWindow; async function createExtraWindow(extraWindowHash) { const spellcheckEnabled = optionService.getOptionBool('spellCheckEnabled'); - const {BrowserWindow} = require('electron'); + const { BrowserWindow } = require('electron'); const win = new BrowserWindow({ width: 1000, height: 800, title: 'Trilium Notes', webPreferences: { - enableRemoteModule: true, nodeIntegration: true, contextIsolation: false, - spellcheck: spellcheckEnabled + spellcheck: spellcheckEnabled, + webviewTag: true }, frame: optionService.getOptionBool('nativeTitleBarVisible'), icon: getIcon() @@ -55,7 +56,7 @@ async function createMainWindow(app) { const spellcheckEnabled = optionService.getOptionBool('spellCheckEnabled'); - const {BrowserWindow} = require('electron'); // should not be statically imported + const { BrowserWindow } = require('electron'); // should not be statically imported mainWindow = new BrowserWindow({ x: mainWindowState.x, @@ -64,7 +65,6 @@ async function createMainWindow(app) { height: mainWindowState.height, title: 'Trilium Notes', webPreferences: { - enableRemoteModule: true, nodeIntegration: true, contextIsolation: false, spellcheck: spellcheckEnabled, @@ -96,9 +96,9 @@ async function createMainWindow(app) { } function configureWebContents(webContents, spellcheckEnabled) { - require("@electron/remote/main").enable(webContents); + enableRemote(webContents); - mainWindow.webContents.setWindowOpenHandler((details) => { + webContents.setWindowOpenHandler((details) => { require("electron").shell.openExternal(details.url); return { action: 'deny' } }); @@ -128,7 +128,7 @@ function getIcon() { } async function createSetupWindow() { - const {BrowserWindow} = require('electron'); // should not be statically imported + const { BrowserWindow } = require('electron'); // should not be statically imported setupWindow = new BrowserWindow({ width: 800, height: 800, @@ -136,13 +136,17 @@ async function createSetupWindow() { icon: getIcon(), webPreferences: { // necessary for e.g. utils.isElectron() - nodeIntegration: true + nodeIntegration: true, + contextIsolation: false } }); setupWindow.setMenuBarVisibility(false); setupWindow.loadURL(`http://127.0.0.1:${port}`); setupWindow.on('closed', () => setupWindow = null); + + // Enable remote for setup window + configureWebContents(setupWindow.webContents, false); } function closeSetupWindow() { @@ -152,7 +156,7 @@ function closeSetupWindow() { } async function registerGlobalShortcuts() { - const {globalShortcut} = require('electron'); + const { globalShortcut } = require('electron'); await sqlInit.dbReady;