diff --git a/LICENSE b/LICENSE index dbbe35581..4d3c3b627 100644 --- a/LICENSE +++ b/LICENSE @@ -643,7 +643,7 @@ the "copyright" line and a pointer to where the full notice is found. GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . + along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. @@ -658,4 +658,4 @@ specific requirements. You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU AGPL, see -. +. diff --git a/bin/better-sqlite3/linux-desktop-better_sqlite3.node b/bin/better-sqlite3/linux-desktop-better_sqlite3.node index 180186307..dea5f5722 100644 Binary files a/bin/better-sqlite3/linux-desktop-better_sqlite3.node and b/bin/better-sqlite3/linux-desktop-better_sqlite3.node differ diff --git a/electron.js b/electron.js index 2de1425a4..0d85e06ce 100644 --- a/electron.js +++ b/electron.js @@ -1,17 +1,21 @@ 'use strict'; -const {app, globalShortcut, BrowserWindow} = require('electron'); -const sqlInit = require('./src/services/sql_init'); -const appIconService = require('./src/services/app_icon'); -const windowService = require('./src/services/window'); -const tray = require('./src/services/tray'); +import { app, globalShortcut, BrowserWindow } from 'electron'; +import sqlInit from './src/services/sql_init.js'; +import appIconService from './src/services/app_icon.js'; +import windowService from './src/services/window.js'; +import tray from './src/services/tray.js'; +import electron_debug from "electron-debug"; +import electron_dl from "electron-dl"; + +import './src/www.js'; // Adds debug features like hotkeys for triggering dev tools and reload -require('electron-debug')(); +electron_debug(); appIconService.installLocalAppIcon(); -require('electron-dl')({ saveAs: true }); +electron_dl({ saveAs: true }); // needed for excalidraw export https://github.com/zadam/trilium/issues/4271 app.commandLine.appendSwitch("enable-experimental-web-platform-features"); @@ -58,5 +62,3 @@ app.on('will-quit', () => { // this is to disable electron warning spam in the dev console (local development only) process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true'; - -require('./src/www'); diff --git a/package-lock.json b/package-lock.json index aacf5d057..fffa87653 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "trilium", - "version": "0.62.1-beta", + "version": "0.62.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "trilium", - "version": "0.62.1-beta", + "version": "0.62.2", "hasInstallScript": true, "license": "AGPL-3.0-only", "dependencies": { @@ -16,7 +16,7 @@ "archiver": "6.0.1", "async-mutex": "0.4.0", "axios": "1.6.2", - "better-sqlite3": "8.4.0", + "better-sqlite3": "9.1.1", "chokidar": "3.5.3", "cls-hooked": "4.2.2", "compression": "1.7.4", @@ -77,11 +77,11 @@ "yauzl": "2.10.0" }, "bin": { - "trilium": "src/www" + "trilium": "src/www.js" }, "devDependencies": { "cross-env": "7.0.3", - "electron": "25.9.5", + "electron": "28.0.0-beta.8", "electron-builder": "24.6.4", "electron-packager": "17.1.2", "electron-rebuild": "3.2.9", @@ -2540,13 +2540,13 @@ } }, "node_modules/better-sqlite3": { - "version": "8.4.0", - "resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-8.4.0.tgz", - "integrity": "sha512-NmsNW1CQvqMszu/CFAJ3pLct6NEFlNfuGM6vw72KHkjOD1UDnL96XNN1BMQc1hiHo8vE2GbOWQYIpZ+YM5wrZw==", + "version": "9.1.1", + "resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-9.1.1.tgz", + "integrity": "sha512-FhW7bS7cXwkB2SFnPJrSGPmQerVSCzwBgmQ1cIRcYKxLsyiKjljzCbyEqqhYXo5TTBqt5BISiBj2YE2Sy2ynaA==", "hasInstallScript": true, "dependencies": { "bindings": "^1.5.0", - "prebuild-install": "^7.1.0" + "prebuild-install": "^7.1.1" } }, "node_modules/big-integer": { @@ -4366,9 +4366,9 @@ } }, "node_modules/electron": { - "version": "25.9.5", - "resolved": "https://registry.npmjs.org/electron/-/electron-25.9.5.tgz", - "integrity": "sha512-gM7GXUSd3JVRcYbBnNOtZeNnE5MCJjtZTT8QyIxJvpQ0Dh9dz3hTuEL62dOwnMFW/l47ACQ6es/8qi01P4QGZA==", + "version": "28.0.0-beta.8", + "resolved": "https://registry.npmjs.org/electron/-/electron-28.0.0-beta.8.tgz", + "integrity": "sha512-8SwL743EG3sIdwqvgq+fteYexRGb0qTg8MUSm77IRnw6tOxbCfgd8QztpYS7z8SNDcpAABXD4I1X9nqBVBLshQ==", "hasInstallScript": true, "dependencies": { "@electron/get": "^2.0.0", @@ -15572,12 +15572,12 @@ } }, "better-sqlite3": { - "version": "8.4.0", - "resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-8.4.0.tgz", - "integrity": "sha512-NmsNW1CQvqMszu/CFAJ3pLct6NEFlNfuGM6vw72KHkjOD1UDnL96XNN1BMQc1hiHo8vE2GbOWQYIpZ+YM5wrZw==", + "version": "9.1.1", + "resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-9.1.1.tgz", + "integrity": "sha512-FhW7bS7cXwkB2SFnPJrSGPmQerVSCzwBgmQ1cIRcYKxLsyiKjljzCbyEqqhYXo5TTBqt5BISiBj2YE2Sy2ynaA==", "requires": { "bindings": "^1.5.0", - "prebuild-install": "^7.1.0" + "prebuild-install": "^7.1.1" } }, "big-integer": { @@ -16964,9 +16964,9 @@ } }, "electron": { - "version": "25.9.5", - "resolved": "https://registry.npmjs.org/electron/-/electron-25.9.5.tgz", - "integrity": "sha512-gM7GXUSd3JVRcYbBnNOtZeNnE5MCJjtZTT8QyIxJvpQ0Dh9dz3hTuEL62dOwnMFW/l47ACQ6es/8qi01P4QGZA==", + "version": "28.0.0-beta.8", + "resolved": "https://registry.npmjs.org/electron/-/electron-28.0.0-beta.8.tgz", + "integrity": "sha512-8SwL743EG3sIdwqvgq+fteYexRGb0qTg8MUSm77IRnw6tOxbCfgd8QztpYS7z8SNDcpAABXD4I1X9nqBVBLshQ==", "requires": { "@electron/get": "^2.0.0", "@types/node": "^18.11.18", diff --git a/package.json b/package.json index 00384c537..e098f28b0 100644 --- a/package.json +++ b/package.json @@ -5,21 +5,22 @@ "version": "0.62.2", "license": "AGPL-3.0-only", "main": "electron.js", + "type": "module", "bin": { - "trilium": "./src/www" + "trilium": "src/www.js" }, "repository": { "type": "git", "url": "https://github.com/zadam/trilium.git" }, "scripts": { - "start-server": "cross-env TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon ./src/www", - "start-server-no-dir": "cross-env TRILIUM_SAFE_MODE=1 TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon ./src/www", - "qstart-server": "npm run qswitch-server && TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon ./src/www", + "start-server": "cross-env TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon src/www.js", + "start-server-no-dir": "cross-env TRILIUM_SAFE_MODE=1 TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon src/www.js", + "qstart-server": "npm run qswitch-server && TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon src/www.js", "start-electron": "cross-env TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev electron --inspect=5858 .", "start-electron-no-dir": "cross-env TRILIUM_SAFE_MODE=1 TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 electron --inspect=5858 .", "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", + "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", "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", @@ -42,7 +43,7 @@ "archiver": "6.0.1", "async-mutex": "0.4.0", "axios": "1.6.2", - "better-sqlite3": "8.4.0", + "better-sqlite3": "9.1.1", "chokidar": "3.5.3", "cls-hooked": "4.2.2", "compression": "1.7.4", @@ -104,7 +105,7 @@ }, "devDependencies": { "cross-env": "7.0.3", - "electron": "25.9.5", + "electron": "28.0.0-beta.8", "electron-builder": "24.6.4", "electron-packager": "17.1.2", "electron-rebuild": "3.2.9", diff --git a/spec/etapi/app_info.js b/spec/etapi/app_info.js index dff253a5b..69ae0b6b2 100644 --- a/spec/etapi/app_info.js +++ b/spec/etapi/app_info.js @@ -1,8 +1,6 @@ -const { - describeEtapi, postEtapi, - putEtapiContent -} = require("../support/etapi"); -const {getEtapi} = require("../support/etapi.js"); +import {describeEtapi, postEtapi, putEtapiContent,getEtapi} from "../support/etapi"; + + describeEtapi("app_info", () => { it("get", async () => { diff --git a/spec/etapi/backup.js b/spec/etapi/backup.js index d22625b56..03a9b3d48 100644 --- a/spec/etapi/backup.js +++ b/spec/etapi/backup.js @@ -1,8 +1,4 @@ -const { - describeEtapi, postEtapi, - getEtapi, -} = require("../support/etapi"); -const {putEtapiContent} = require("../support/etapi.js"); +import {describeEtapi, getEtapi, postEtapi,putEtapiContent} from "../support/etapi"; describeEtapi("backup", () => { it("create", async () => { diff --git a/spec/etapi/import.js b/spec/etapi/import.js index 45db2890b..836c1516c 100644 --- a/spec/etapi/import.js +++ b/spec/etapi/import.js @@ -1,10 +1,9 @@ -const { - describeEtapi, postEtapi, - postEtapiContent, -} = require("../support/etapi"); -const fs = require("fs"); -const path = require("path"); -const {getEtapiContent} = require("../support/etapi.js"); +import {describeEtapi, postEtapi, postEtapiContent,getEtapiContent} from "../support/etapi"; +import fs from "fs"; +import path from "path"; +import {fileURLToPath} from "node:url"; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); describeEtapi("import", () => { it("import", async () => { diff --git a/spec/etapi/notes.js b/spec/etapi/notes.js index f63acee0a..7227cf085 100644 --- a/spec/etapi/notes.js +++ b/spec/etapi/notes.js @@ -1,13 +1,14 @@ -const crypto = require('crypto'); -const { +import crypto from "crypto"; + +import { deleteEtapi, - getEtapiResponse, - describeEtapi, postEtapi, + describeEtapi, getEtapi, getEtapiContent, - patchEtapi, putEtapi, - putEtapiContent -} = require("../support/etapi"); + getEtapiResponse, + patchEtapi, + postEtapi, putEtapi, putEtapiContent +} from "../support/etapi"; describeEtapi("notes", () => { it("create", async () => { diff --git a/src/anonymize.js b/src/anonymize.js index 0fa00cda1..f221a5d97 100644 --- a/src/anonymize.js +++ b/src/anonymize.js @@ -1,6 +1,6 @@ -const anonymizationService = require('./services/anonymization'); -const sqlInit = require('./services/sql_init'); -require('./becca/entity_constructor'); +import anonymizationService from './services/anonymization.js' +import sqlInit from './services/sql_init.js' +import './becca/entity_constructor.js'; sqlInit.dbReady.then(async () => { try { diff --git a/src/app.js b/src/app.js index dc3adb7e8..572e21fe7 100644 --- a/src/app.js +++ b/src/app.js @@ -1,14 +1,37 @@ -const express = require('express'); -const path = require('path'); -const favicon = require('serve-favicon'); -const cookieParser = require('cookie-parser'); -const helmet = require('helmet'); -const compression = require('compression'); -const sessionParser = require('./routes/session_parser'); -const utils = require('./services/utils'); +import express from 'express'; +import path from 'path'; +import favicon from 'serve-favicon'; +import cookieParser from 'cookie-parser'; +import helmet from 'helmet'; +import compression from 'compression'; +import sessionParser from './routes/session_parser.js' +import utils from './services/utils.js' +import './services/handlers.js'; +import './becca/becca_loader.js'; -require('./services/handlers'); -require('./becca/becca_loader'); +// triggers sync timer +import './services/sync.js'; + +// triggers backup timer +import './services/backup.js'; + +// trigger consistency checks timer +import './services/consistency_checks.js'; + +import './services/scheduler.js'; + +import assetRoutes from './routes/assets.js' + +import routes from './routes/routes.js' + +import customRoutes from './routes/custom.js' + +import errorHandlerRoutes from './routes/error_handlers.js' + +import {initialize} from "@electron/remote/main/index.js"; +import {fileURLToPath} from "node:url"; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); const app = express(); @@ -37,24 +60,13 @@ app.use(`/robots.txt`, express.static(path.join(__dirname, 'public/robots.txt')) app.use(sessionParser); app.use(favicon(`${__dirname}/../images/app-icons/win/icon.ico`)); -require('./routes/assets').register(app); -require('./routes/routes').register(app); -require('./routes/custom').register(app); -require('./routes/error_handlers').register(app); - -// triggers sync timer -require('./services/sync'); - -// triggers backup timer -require('./services/backup'); - -// trigger consistency checks timer -require('./services/consistency_checks'); - -require('./services/scheduler'); +assetRoutes.register(app); +routes.register(app); +customRoutes.register(app); +errorHandlerRoutes.register(app); if (utils.isElectron()) { - require('@electron/remote/main').initialize(); + initialize(); } -module.exports = app; +export default app; diff --git a/src/becca/becca.js b/src/becca/becca.js index 4b08b7706..b7f6c0e58 100644 --- a/src/becca/becca.js +++ b/src/becca/becca.js @@ -1,8 +1,16 @@ "use strict"; -const sql = require("../services/sql"); -const NoteSet = require("../services/search/note_set"); -const NotFoundError = require("../errors/not_found_error"); +import sql from '../services/sql.js' +import NoteSet from '../services/search/note_set.js' +import NotFoundError from '../errors/not_found_error.js' + +import BRevision from './entities/brevision.js' // avoiding circular dependency problems + +import BAttachment from './entities/battachment.js' // avoiding circular dependency problems + +import BBlob from './entities/bblob.js' // avoiding circular dependency problems + +import BRecentNote from './entities/brecent_note.js' // avoiding circular dependency problems /** * Becca is a backend cache of all notes, branches, and attributes. @@ -147,8 +155,6 @@ class Becca { /** @returns {BRevision|null} */ getRevision(revisionId) { const row = sql.getRow("SELECT * FROM revisions WHERE revisionId = ?", [revisionId]); - - const BRevision = require("./entities/brevision"); // avoiding circular dependency problems return row ? new BRevision(row) : null; } @@ -162,9 +168,6 @@ class Becca { JOIN blobs USING (blobId) WHERE attachmentId = ? AND isDeleted = 0` : `SELECT * FROM attachments WHERE attachmentId = ? AND isDeleted = 0`; - - const BAttachment = require("./entities/battachment"); // avoiding circular dependency problems - return sql.getRows(query, [attachmentId]) .map(row => new BAttachment(row))[0]; } @@ -180,7 +183,7 @@ class Becca { /** @returns {BAttachment[]} */ getAttachments(attachmentIds) { - const BAttachment = require("./entities/battachment"); // avoiding circular dependency problems +// avoiding circular dependency problems return sql.getManyRows("SELECT * FROM attachments WHERE attachmentId IN (???) AND isDeleted = 0", attachmentIds) .map(row => new BAttachment(row)); } @@ -188,8 +191,6 @@ class Becca { /** @returns {BBlob|null} */ getBlob(entity) { const row = sql.getRow("SELECT *, LENGTH(content) AS contentLength FROM blobs WHERE blobId = ?", [entity.blobId]); - - const BBlob = require("./entities/bblob"); // avoiding circular dependency problems return row ? new BBlob(row) : null; } @@ -237,16 +238,12 @@ class Becca { /** @returns {BRecentNote[]} */ getRecentNotesFromQuery(query, params = []) { const rows = sql.getRows(query, params); - - const BRecentNote = require("./entities/brecent_note"); // avoiding circular dependency problems return rows.map(row => new BRecentNote(row)); } /** @returns {BRevision[]} */ getRevisionsFromQuery(query, params = []) { const rows = sql.getRows(query, params); - - const BRevision = require("./entities/brevision"); // avoiding circular dependency problems return rows.map(row => new BRevision(row)); } @@ -279,4 +276,4 @@ class Becca { const becca = new Becca(); -module.exports = becca; +export default becca; diff --git a/src/becca/becca_loader.js b/src/becca/becca_loader.js index 5c5ae8eb4..f2c61c2f2 100644 --- a/src/becca/becca_loader.js +++ b/src/becca/becca_loader.js @@ -1,24 +1,28 @@ "use strict"; -const sql = require('../services/sql'); -const eventService = require('../services/events'); -const becca = require('./becca'); -const sqlInit = require('../services/sql_init'); -const log = require('../services/log'); -const BNote = require('./entities/bnote'); -const BBranch = require('./entities/bbranch'); -const BAttribute = require('./entities/battribute'); -const BOption = require('./entities/boption'); -const BEtapiToken = require("./entities/betapi_token"); -const cls = require("../services/cls"); -const entityConstructor = require("../becca/entity_constructor"); +import sql from '../services/sql.js' +import eventService from '../services/events.js' +import becca from './becca.js' +import sqlInit from '../services/sql_init.js' +import log from '../services/log.js' +import BNote from './entities/bnote.js' +import BBranch from './entities/bbranch.js' +import BAttribute from './entities/battribute.js' +import BOption from './entities/boption.js' +import BEtapiToken from './entities/betapi_token.js' +import cls from '../services/cls.js' +import entityConstructor from '../becca/entity_constructor.js' + +import services from '../services/options_init.js' + +import services0 from '../services/ws.js' const beccaLoaded = new Promise((res, rej) => { sqlInit.dbReady.then(() => { cls.init(() => { load(); - require('../services/options_init').initStartupOptions(); + services.initStartupOptions(); res(); }); @@ -71,7 +75,7 @@ function load() { function reload(reason) { load(); - require('../services/ws').reloadFrontend(reason || "becca reloaded"); + services0.reloadFrontend(reason || "becca reloaded"); } eventService.subscribeBeccaLoader([eventService.ENTITY_CHANGE_SYNCED], ({entityName, entityRow}) => { @@ -282,7 +286,7 @@ eventService.subscribeBeccaLoader(eventService.ENTER_PROTECTED_SESSION, () => { eventService.subscribeBeccaLoader(eventService.LEAVE_PROTECTED_SESSION, load); -module.exports = { +export default { load, reload, beccaLoaded diff --git a/src/becca/becca_service.js b/src/becca/becca_service.js index 15a1c07cc..b813bfbf0 100644 --- a/src/becca/becca_service.js +++ b/src/becca/becca_service.js @@ -1,8 +1,8 @@ "use strict"; -const becca = require('./becca'); -const cls = require('../services/cls'); -const log = require('../services/log'); +import becca from './becca.js' +import cls from '../services/cls.js' +import log from '../services/log.js' function isNotePathArchived(notePath) { const noteId = notePath[notePath.length - 1]; @@ -82,7 +82,7 @@ function getNoteTitleForPath(notePathArray) { return titles.join(' / '); } -module.exports = { +export default { getNoteTitle, getNoteTitleForPath, isNotePathArchived diff --git a/src/becca/entities/abstract_becca_entity.js b/src/becca/entities/abstract_becca_entity.js index 037f935d6..9fea04986 100644 --- a/src/becca/entities/abstract_becca_entity.js +++ b/src/becca/entities/abstract_becca_entity.js @@ -1,14 +1,16 @@ "use strict"; -const utils = require('../../services/utils'); -const sql = require('../../services/sql'); -const entityChangesService = require('../../services/entity_changes'); -const eventService = require("../../services/events"); -const dateUtils = require("../../services/date_utils"); -const cls = require("../../services/cls"); -const log = require("../../services/log"); -const protectedSessionService = require("../../services/protected_session"); -const blobService = require("../../services/blob"); +import utils from '../../services/utils.js' +import sql from '../../services/sql.js' +import entityChangesService from '../../services/entity_changes.js' +import eventService from '../../services/events.js' +import dateUtils from '../../services/date_utils.js' +import cls from '../../services/cls.js' +import log from '../../services/log.js' +import protectedSessionService from '../../services/protected_session.js' +import blobService from '../../services/blob.js' + +import becca0 from '../becca.js' let becca = null; @@ -34,7 +36,7 @@ class AbstractBeccaEntity { */ get becca() { if (!becca) { - becca = require('../becca'); + becca = becca0; } return becca; @@ -306,4 +308,4 @@ class AbstractBeccaEntity { } } -module.exports = AbstractBeccaEntity; +export default AbstractBeccaEntity; diff --git a/src/becca/entities/battachment.js b/src/becca/entities/battachment.js index 6e6e2efca..37b17b339 100644 --- a/src/becca/entities/battachment.js +++ b/src/becca/entities/battachment.js @@ -1,11 +1,13 @@ "use strict"; -const utils = require('../../services/utils'); -const dateUtils = require('../../services/date_utils'); -const AbstractBeccaEntity = require("./abstract_becca_entity"); -const sql = require("../../services/sql"); -const protectedSessionService = require("../../services/protected_session"); -const log = require("../../services/log"); +import utils from '../../services/utils.js' +import dateUtils from '../../services/date_utils.js' +import AbstractBeccaEntity from './abstract_becca_entity.js' +import sql from '../../services/sql.js' +import protectedSessionService from '../../services/protected_session.js' +import log from '../../services/log.js' + +import noteService from '../../services/notes.js' const attachmentRoleToNoteTypeMapping = { 'image': 'image' @@ -37,7 +39,7 @@ class BAttachment extends AbstractBeccaEntity { /** @type {string} */ this.attachmentId = row.attachmentId; - /** + /** * either noteId or revisionId to which this attachment belongs * @type {string} */ @@ -152,9 +154,6 @@ class BAttachment extends AbstractBeccaEntity { if (!this.isContentAvailable()) { // isProtected is the same for attachment throw new Error(`Cannot convert protected attachment outside of protected session`); } - - const noteService = require('../../services/notes'); - const { note, branch } = noteService.createNewNote({ parentNoteId: this.ownerId, title: this.title, @@ -240,4 +239,4 @@ class BAttachment extends AbstractBeccaEntity { } } -module.exports = BAttachment; +export default BAttachment; diff --git a/src/becca/entities/battribute.js b/src/becca/entities/battribute.js index d09020269..9b65945e2 100644 --- a/src/becca/entities/battribute.js +++ b/src/becca/entities/battribute.js @@ -1,11 +1,11 @@ "use strict"; -const BNote = require('./bnote'); -const AbstractBeccaEntity = require("./abstract_becca_entity"); -const sql = require("../../services/sql"); -const dateUtils = require("../../services/date_utils"); -const promotedAttributeDefinitionParser = require("../../services/promoted_attribute_definition_parser"); -const {sanitizeAttributeName} = require("../../services/sanitize_attribute_name"); +import BNote from './bnote.js' +import AbstractBeccaEntity from './abstract_becca_entity.js' +import sql from '../../services/sql.js' +import dateUtils from '../../services/date_utils.js' +import promotedAttributeDefinitionParser from '../../services/promoted_attribute_definition_parser.js' +import { sanitizeAttributeName } from '../../services/sanitize_attribute_name.js'; /** @@ -239,4 +239,4 @@ class BAttribute extends AbstractBeccaEntity { } } -module.exports = BAttribute; +export default BAttribute; diff --git a/src/becca/entities/bblob.js b/src/becca/entities/bblob.js index def5888ee..41d614b11 100644 --- a/src/becca/entities/bblob.js +++ b/src/becca/entities/bblob.js @@ -27,4 +27,4 @@ class BBlob { } } -module.exports = BBlob; +export default BBlob; diff --git a/src/becca/entities/bbranch.js b/src/becca/entities/bbranch.js index 24d2cea79..77541618d 100644 --- a/src/becca/entities/bbranch.js +++ b/src/becca/entities/bbranch.js @@ -1,12 +1,16 @@ "use strict"; -const BNote = require('./bnote'); -const AbstractBeccaEntity = require("./abstract_becca_entity"); -const dateUtils = require("../../services/date_utils"); -const utils = require("../../services/utils"); -const TaskContext = require("../../services/task_context"); -const cls = require("../../services/cls"); -const log = require("../../services/log"); +import BNote from './bnote.js' +import AbstractBeccaEntity from './abstract_becca_entity.js' +import dateUtils from '../../services/date_utils.js' +import utils from '../../services/utils.js' +import TaskContext from '../../services/task_context.js' +import cls from '../../services/cls.js' +import log from '../../services/log.js' + + +// needs to be run before branches and attributes are deleted and thus attached relations disappear +import handlers from '../../services/handlers.js' /** * Branch represents a relationship between a child note and its parent note. Trilium allows a note to have multiple @@ -160,8 +164,6 @@ class BBranch extends AbstractBeccaEntity { const parentBranches = note.getParentBranches(); if (parentBranches.length === 1 && parentBranches[0] === this) { - // needs to be run before branches and attributes are deleted and thus attached relations disappear - const handlers = require("../../services/handlers"); handlers.runAttachedRelations(note, 'runOnNoteDeletion', note); } } @@ -279,4 +281,4 @@ class BBranch extends AbstractBeccaEntity { } } -module.exports = BBranch; +export default BBranch; diff --git a/src/becca/entities/betapi_token.js b/src/becca/entities/betapi_token.js index 05aae9c92..e912f7715 100644 --- a/src/becca/entities/betapi_token.js +++ b/src/becca/entities/betapi_token.js @@ -1,7 +1,7 @@ "use strict"; -const dateUtils = require('../../services/date_utils'); -const AbstractBeccaEntity = require("./abstract_becca_entity"); +import dateUtils from '../../services/date_utils.js' +import AbstractBeccaEntity from './abstract_becca_entity.js' /** * EtapiToken is an entity representing token used to authenticate against Trilium REST API from client applications. @@ -75,4 +75,4 @@ class BEtapiToken extends AbstractBeccaEntity { } } -module.exports = BEtapiToken; +export default BEtapiToken; diff --git a/src/becca/entities/bnote.js b/src/becca/entities/bnote.js index 6886a170d..bb5d53033 100644 --- a/src/becca/entities/bnote.js +++ b/src/becca/entities/bnote.js @@ -1,17 +1,29 @@ "use strict"; -const protectedSessionService = require('../../services/protected_session'); -const log = require('../../services/log'); -const sql = require('../../services/sql'); -const utils = require('../../services/utils'); -const dateUtils = require('../../services/date_utils'); -const AbstractBeccaEntity = require("./abstract_becca_entity"); -const BRevision = require("./brevision"); -const BAttachment = require("./battachment"); -const TaskContext = require("../../services/task_context"); -const dayjs = require("dayjs"); -const utc = require('dayjs/plugin/utc'); -const eventService = require("../../services/events"); +import protectedSessionService from '../../services/protected_session.js' +import log from '../../services/log.js' +import sql from '../../services/sql.js' +import utils from '../../services/utils.js' +import dateUtils from '../../services/date_utils.js' +import AbstractBeccaEntity from './abstract_becca_entity.js' +import BRevision from './brevision.js' +import BAttachment from './battachment.js' +import TaskContext from '../../services/task_context.js' +import dayjs from "dayjs"; +import utc from "dayjs/plugin/utc.js"; +import eventService from '../../services/events.js' +import searchService from '../../services/search/services/search.js' + +import BAttribute from './battribute.js' + +import cloningService from '../../services/cloning.js' + +import noteService from '../../services/notes.js' + + +// needs to be run before branches and attributes are deleted and thus attached relations disappear +import handlers from '../../services/handlers.js' + dayjs.extend(utc); const LABEL = 'label'; @@ -903,7 +915,6 @@ class BNote extends AbstractBeccaEntity { } try { - const searchService = require("../../services/search/services/search"); const {searchResultNoteIds} = searchService.searchFromNote(this); const becca = this.becca; @@ -1303,8 +1314,6 @@ class BNote extends AbstractBeccaEntity { } } else { - const BAttribute = require("./battribute"); - new BAttribute({ noteId: this.noteId, type: type, @@ -1343,8 +1352,6 @@ class BNote extends AbstractBeccaEntity { * @returns {BAttribute} */ addAttribute(type, name, value = "", isInheritable = false, position = null) { - const BAttribute = require("./battribute"); - return new BAttribute({ noteId: this.noteId, type: type, @@ -1448,8 +1455,6 @@ class BNote extends AbstractBeccaEntity { removeRelation(name, value) { return this.removeAttribute(RELATION, name, value); } searchNotesInSubtree(searchString) { - const searchService = require("../../services/search/services/search"); - return searchService.searchNotes(searchString); } @@ -1462,8 +1467,6 @@ class BNote extends AbstractBeccaEntity { * @returns {{success: boolean, message: string, branchId: string, notePath: string}} */ cloneTo(parentNoteId) { - const cloningService = require("../../services/cloning"); - const branch = this.becca.getNote(parentNoteId).getParentBranches()[0]; return cloningService.cloneNoteToBranch(this.noteId, branch.branchId); @@ -1536,8 +1539,6 @@ class BNote extends AbstractBeccaEntity { const fixedContent = utils.replaceAll(parentContent, oldNoteUrl, newAttachmentUrl); parentNote.setContent(fixedContent); - - const noteService = require("../../services/notes"); noteService.asyncPostProcessContent(parentNote, fixedContent); // to mark an unused attachment for deletion this.deleteNote(); @@ -1563,9 +1564,6 @@ class BNote extends AbstractBeccaEntity { if (!taskContext) { taskContext = new TaskContext('no-progress-reporting'); } - - // needs to be run before branches and attributes are deleted and thus attached relations disappear - const handlers = require("../../services/handlers"); handlers.runAttachedRelations(this, 'runOnNoteDeletion', this); taskContext.noteDeletionHandlerTriggered = true; @@ -1725,4 +1723,4 @@ class BNote extends AbstractBeccaEntity { } } -module.exports = BNote; +export default BNote; diff --git a/src/becca/entities/boption.js b/src/becca/entities/boption.js index 1d876e6a2..3b43f5e69 100644 --- a/src/becca/entities/boption.js +++ b/src/becca/entities/boption.js @@ -1,7 +1,7 @@ "use strict"; -const dateUtils = require('../../services/date_utils'); -const AbstractBeccaEntity = require("./abstract_becca_entity"); +import dateUtils from '../../services/date_utils.js' +import AbstractBeccaEntity from './abstract_becca_entity.js' /** * Option represents a name-value pair, either directly configurable by the user or some system property. @@ -47,4 +47,4 @@ class BOption extends AbstractBeccaEntity { } } -module.exports = BOption; +export default BOption; diff --git a/src/becca/entities/brecent_note.js b/src/becca/entities/brecent_note.js index b2e1c3ba4..889471591 100644 --- a/src/becca/entities/brecent_note.js +++ b/src/becca/entities/brecent_note.js @@ -1,7 +1,7 @@ "use strict"; -const dateUtils = require('../../services/date_utils'); -const AbstractBeccaEntity = require("./abstract_becca_entity"); +import dateUtils from '../../services/date_utils.js' +import AbstractBeccaEntity from './abstract_becca_entity.js' /** * RecentNote represents recently visited note. @@ -32,4 +32,4 @@ class BRecentNote extends AbstractBeccaEntity { } } -module.exports = BRecentNote; +export default BRecentNote; diff --git a/src/becca/entities/brevision.js b/src/becca/entities/brevision.js index de9bfbd82..82931902f 100644 --- a/src/becca/entities/brevision.js +++ b/src/becca/entities/brevision.js @@ -1,12 +1,12 @@ "use strict"; -const protectedSessionService = require('../../services/protected_session'); -const utils = require('../../services/utils'); -const dateUtils = require('../../services/date_utils'); -const becca = require('../becca'); -const AbstractBeccaEntity = require("./abstract_becca_entity"); -const sql = require("../../services/sql"); -const BAttachment = require("./battachment"); +import protectedSessionService from '../../services/protected_session.js' +import utils from '../../services/utils.js' +import dateUtils from '../../services/date_utils.js' +import becca from '../becca.js' +import AbstractBeccaEntity from './abstract_becca_entity.js' +import sql from '../../services/sql.js' +import BAttachment from './battachment.js' /** * Revision represents a snapshot of note's title and content at some point in the past. @@ -205,4 +205,4 @@ class BRevision extends AbstractBeccaEntity { } } -module.exports = BRevision; +export default BRevision; diff --git a/src/becca/entity_constructor.js b/src/becca/entity_constructor.js index 287a5fd81..b7fd34fb8 100644 --- a/src/becca/entity_constructor.js +++ b/src/becca/entity_constructor.js @@ -1,12 +1,12 @@ -const BAttachment = require("./entities/battachment"); -const BAttribute = require('./entities/battribute'); -const BBlob = require("./entities/bblob"); -const BBranch = require('./entities/bbranch'); -const BEtapiToken = require('./entities/betapi_token'); -const BNote = require('./entities/bnote'); -const BOption = require('./entities/boption'); -const BRecentNote = require('./entities/brecent_note'); -const BRevision = require('./entities/brevision'); +import BAttachment from './entities/battachment.js' +import BAttribute from './entities/battribute.js' +import BBlob from './entities/bblob.js' +import BBranch from './entities/bbranch.js' +import BEtapiToken from './entities/betapi_token.js' +import BNote from './entities/bnote.js' +import BOption from './entities/boption.js' +import BRecentNote from './entities/brecent_note.js' +import BRevision from './entities/brevision.js' const ENTITY_NAME_TO_ENTITY = { "attachments": BAttachment, @@ -28,6 +28,6 @@ function getEntityFromEntityName(entityName) { return ENTITY_NAME_TO_ENTITY[entityName]; } -module.exports = { +export default { getEntityFromEntityName }; diff --git a/src/becca/similarity.js b/src/becca/similarity.js index b0ed39e13..17bc75dde 100644 --- a/src/becca/similarity.js +++ b/src/becca/similarity.js @@ -1,8 +1,8 @@ -const becca = require('./becca'); -const log = require('../services/log'); -const beccaService = require('./becca_service'); -const dateUtils = require('../services/date_utils'); -const {JSDOM} = require("jsdom"); +import becca from './becca.js' +import log from '../services/log.js' +import beccaService from './becca_service.js' +import dateUtils from '../services/date_utils.js' +import { JSDOM } from 'jsdom'; const DEBUG = false; @@ -35,7 +35,7 @@ const IGNORED_ATTR_NAMES = [ function filterUrlValue(value) { return value .replace(/https?:\/\//ig, "") - .replace(/www\./ig, "") + .replace(/www.js\./ig, "") .replace(/(\.net|\.com|\.org|\.info|\.edu)/ig, ""); } @@ -456,6 +456,6 @@ function setImmediatePromise() { }); } -module.exports = { +export default { findSimilarNotes }; diff --git a/src/errors/not_found_error.js b/src/errors/not_found_error.js index af746b82c..cd5bb6679 100644 --- a/src/errors/not_found_error.js +++ b/src/errors/not_found_error.js @@ -4,4 +4,4 @@ class NotFoundError { } } -module.exports = NotFoundError; \ No newline at end of file +export default NotFoundError; \ No newline at end of file diff --git a/src/errors/validation_error.js b/src/errors/validation_error.js index 1c9425669..392c931e1 100644 --- a/src/errors/validation_error.js +++ b/src/errors/validation_error.js @@ -4,4 +4,4 @@ class ValidationError { } } -module.exports = ValidationError; \ No newline at end of file +export default ValidationError; \ No newline at end of file diff --git a/src/etapi/app_info.js b/src/etapi/app_info.js index 3dc4481ac..e63ae1233 100644 --- a/src/etapi/app_info.js +++ b/src/etapi/app_info.js @@ -1,5 +1,5 @@ -const appInfo = require('../services/app_info'); -const eu = require("./etapi_utils"); +import appInfo from '../services/app_info.js' +import eu from './etapi_utils.js' function register(router) { eu.route(router, 'get', '/etapi/app-info', (req, res, next) => { @@ -7,6 +7,6 @@ function register(router) { }); } -module.exports = { +export default { register }; diff --git a/src/etapi/attachments.js b/src/etapi/attachments.js index 64fbb9964..bd849f26c 100644 --- a/src/etapi/attachments.js +++ b/src/etapi/attachments.js @@ -1,8 +1,8 @@ -const becca = require("../becca/becca"); -const eu = require("./etapi_utils"); -const mappers = require("./mappers"); -const v = require("./validators"); -const utils = require("../services/utils"); +import becca from '../becca/becca.js' +import eu from './etapi_utils.js' +import mappers from './mappers.js' +import v from './validators.js' +import utils from '../services/utils.js' function register(router) { const ALLOWED_PROPERTIES_FOR_CREATE_ATTACHMENT = { @@ -98,6 +98,6 @@ function register(router) { }); } -module.exports = { +export default { register }; diff --git a/src/etapi/attributes.js b/src/etapi/attributes.js index 1ecd42888..d5ae0f156 100644 --- a/src/etapi/attributes.js +++ b/src/etapi/attributes.js @@ -1,8 +1,8 @@ -const becca = require("../becca/becca"); -const eu = require("./etapi_utils"); -const mappers = require("./mappers"); -const attributeService = require("../services/attributes"); -const v = require("./validators"); +import becca from '../becca/becca.js' +import eu from './etapi_utils.js' +import mappers from './mappers.js' +import attributeService from '../services/attributes.js' +import v from './validators.js' function register(router) { eu.route(router, 'get', '/etapi/attributes/:attributeId', (req, res, next) => { @@ -78,6 +78,6 @@ function register(router) { }); } -module.exports = { +export default { register }; diff --git a/src/etapi/auth.js b/src/etapi/auth.js index 7f25bbe46..2c97aca4c 100644 --- a/src/etapi/auth.js +++ b/src/etapi/auth.js @@ -1,7 +1,7 @@ -const becca = require("../becca/becca"); -const eu = require("./etapi_utils"); -const passwordEncryptionService = require("../services/encryption/password_encryption"); -const etapiTokenService = require("../services/etapi_tokens"); +import becca from '../becca/becca.js' +import eu from './etapi_utils.js' +import passwordEncryptionService from '../services/encryption/password_encryption.js' +import etapiTokenService from '../services/etapi_tokens.js' function register(router, loginMiddleware) { eu.NOT_AUTHENTICATED_ROUTE(router, 'post', '/etapi/auth/login', loginMiddleware, (req, res, next) => { @@ -38,6 +38,6 @@ function register(router, loginMiddleware) { }); } -module.exports = { +export default { register -} +}; diff --git a/src/etapi/backup.js b/src/etapi/backup.js index 8dc7f8ed1..2a69bb03e 100644 --- a/src/etapi/backup.js +++ b/src/etapi/backup.js @@ -1,5 +1,5 @@ -const eu = require("./etapi_utils"); -const backupService = require("../services/backup"); +import eu from './etapi_utils.js' +import backupService from '../services/backup.js' function register(router) { eu.route(router, 'put', '/etapi/backup/:backupName', async (req, res, next) => { @@ -9,6 +9,6 @@ function register(router) { }); } -module.exports = { +export default { register }; diff --git a/src/etapi/branches.js b/src/etapi/branches.js index a0141bd40..d3050b2e8 100644 --- a/src/etapi/branches.js +++ b/src/etapi/branches.js @@ -1,9 +1,9 @@ -const becca = require("../becca/becca"); -const eu = require("./etapi_utils"); -const mappers = require("./mappers"); -const BBranch = require("../becca/entities/bbranch"); -const entityChangesService = require("../services/entity_changes"); -const v = require("./validators"); +import becca from '../becca/becca.js' +import eu from './etapi_utils.js' +import mappers from './mappers.js' +import BBranch from '../becca/entities/bbranch.js' +import entityChangesService from '../services/entity_changes.js' +import v from './validators.js' function register(router) { eu.route(router, 'get', '/etapi/branches/:branchId', (req, res, next) => { @@ -81,6 +81,6 @@ function register(router) { }); } -module.exports = { +export default { register }; diff --git a/src/etapi/etapi_utils.js b/src/etapi/etapi_utils.js index 64dc77191..e501b3bdf 100644 --- a/src/etapi/etapi_utils.js +++ b/src/etapi/etapi_utils.js @@ -1,9 +1,9 @@ -const cls = require("../services/cls"); -const sql = require("../services/sql"); -const log = require("../services/log"); -const becca = require("../becca/becca"); -const etapiTokenService = require("../services/etapi_tokens"); -const config = require("../services/config"); +import cls from '../services/cls.js' +import sql from '../services/sql.js' +import log from '../services/log.js' +import becca from '../becca/becca.js' +import etapiTokenService from '../services/etapi_tokens.js' +import config from '../services/config.js' const GENERIC_CODE = "GENERIC"; const noAuthentication = config.General && config.General.noAuthentication === true; @@ -136,7 +136,7 @@ function validateAndPatch(target, source, allowedProperties) { } } -module.exports = { +export default { EtapiError, sendError, route, @@ -147,4 +147,4 @@ module.exports = { getAndCheckBranch, getAndCheckAttribute, getAndCheckAttachment -} +}; diff --git a/src/etapi/mappers.js b/src/etapi/mappers.js index d94cf2e69..6954338b4 100644 --- a/src/etapi/mappers.js +++ b/src/etapi/mappers.js @@ -63,7 +63,7 @@ function mapAttachmentToPojo(attachment) { }; } -module.exports = { +export default { mapNoteToPojo, mapBranchToPojo, mapAttributeToPojo, diff --git a/src/etapi/notes.js b/src/etapi/notes.js index dcd0c6504..4750b22d8 100644 --- a/src/etapi/notes.js +++ b/src/etapi/notes.js @@ -1,14 +1,14 @@ -const becca = require("../becca/becca"); -const utils = require("../services/utils"); -const eu = require("./etapi_utils"); -const mappers = require("./mappers"); -const noteService = require("../services/notes"); -const TaskContext = require("../services/task_context"); -const v = require("./validators"); -const searchService = require("../services/search/services/search"); -const SearchContext = require("../services/search/search_context"); -const zipExportService = require("../services/export/zip"); -const zipImportService = require("../services/import/zip"); +import becca from '../becca/becca.js' +import utils from '../services/utils.js' +import eu from './etapi_utils.js' +import mappers from './mappers.js' +import noteService from '../services/notes.js' +import TaskContext from '../services/task_context.js' +import v from './validators.js' +import searchService from '../services/search/services/search.js' +import SearchContext from '../services/search/search_context.js' +import zipExportService from '../services/export/zip.js' +import zipImportService from '../services/import/zip.js' function register(router) { eu.route(router, 'get', '/etapi/notes', (req, res, next) => { @@ -251,6 +251,6 @@ function parseInteger(obj, name) { return integer; } -module.exports = { +export default { register }; diff --git a/src/etapi/spec.js b/src/etapi/spec.js index 83ac93a4b..3a8b7606e 100644 --- a/src/etapi/spec.js +++ b/src/etapi/spec.js @@ -1,5 +1,8 @@ -const fs = require('fs'); -const path = require('path'); +import fs from 'fs'; +import path from 'path'; +import {fileURLToPath} from "node:url"; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); const specPath = path.join(__dirname, 'etapi.openapi.yaml'); let spec = null; @@ -15,6 +18,6 @@ function register(router) { }); } -module.exports = { +export default { register }; diff --git a/src/etapi/special_notes.js b/src/etapi/special_notes.js index 7e1e2a6f5..9c29f5e3e 100644 --- a/src/etapi/special_notes.js +++ b/src/etapi/special_notes.js @@ -1,7 +1,7 @@ -const specialNotesService = require("../services/special_notes"); -const dateNotesService = require("../services/date_notes"); -const eu = require("./etapi_utils"); -const mappers = require("./mappers"); +import specialNotesService from '../services/special_notes.js' +import dateNotesService from '../services/date_notes.js' +import eu from './etapi_utils.js' +import mappers from './mappers.js' const getDateInvalidError = date => new eu.EtapiError(400, "DATE_INVALID", `Date "${date}" is not valid.`); const getMonthInvalidError = month => new eu.EtapiError(400, "MONTH_INVALID", `Month "${month}" is not valid.`); @@ -72,6 +72,6 @@ function register(router) { }); } -module.exports = { +export default { register -}; \ No newline at end of file +}; diff --git a/src/etapi/validators.js b/src/etapi/validators.js index 343812600..585f564f3 100644 --- a/src/etapi/validators.js +++ b/src/etapi/validators.js @@ -1,5 +1,7 @@ -const noteTypeService = require("../services/note_types"); -const dateUtils = require("../services/date_utils"); +import noteTypeService from '../services/note_types.js' +import dateUtils from '../services/date_utils.js' + +import becca from '../becca/becca.js' function mandatory(obj) { if (obj === undefined ) { @@ -63,9 +65,6 @@ function isNoteId(obj) { if (obj === undefined || obj === null) { return; } - - const becca = require('../becca/becca'); - if (typeof obj !== 'string') { return `'${obj}' is not a valid noteId`; } @@ -107,7 +106,7 @@ function isValidEntityId(obj) { } } -module.exports = { +export default { mandatory, notNull, isString, diff --git a/src/public/app/components/entrypoints.js b/src/public/app/components/entrypoints.js index 6b281911f..f4e1ef98a 100644 --- a/src/public/app/components/entrypoints.js +++ b/src/public/app/components/entrypoints.js @@ -10,6 +10,10 @@ import bundleService from "../services/bundle.js"; import froca from "../services/froca.js"; import linkService from "../services/link.js"; +import {getCurrentWebContents, getCurrentWindow} from "@electron/remote"; + +import {ipcRenderer} from "electron"; + export default class Entrypoints extends Component { constructor() { super(); @@ -24,7 +28,7 @@ export default class Entrypoints extends Component { openDevToolsCommand() { if (utils.isElectron()) { - utils.dynamicRequire('@electron/remote').getCurrentWindow().toggleDevTools(); + getCurrentWindow().toggleDevTools(); } } @@ -78,7 +82,7 @@ export default class Entrypoints extends Component { toggleFullscreenCommand() { if (utils.isElectron()) { - const win = utils.dynamicRequire('@electron/remote').getCurrentWindow(); + const win = getCurrentWindow(); if (win.isFullScreenable()) { win.setFullScreen(!win.isFullScreen()); @@ -101,7 +105,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 = getCurrentWebContents(); const activeIndex = parseInt(webContents.getActiveIndex()); webContents.goToIndex(activeIndex - 1); @@ -114,7 +118,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 = getCurrentWebContents(); const activeIndex = parseInt(webContents.getActiveIndex()); webContents.goToIndex(activeIndex + 1); @@ -140,8 +144,6 @@ export default class Entrypoints extends Component { const extraWindowHash = linkService.calculateHash({notePath, hoistedNoteId, viewScope}); if (utils.isElectron()) { - const {ipcRenderer} = utils.dynamicRequire('electron'); - ipcRenderer.send('create-extra-window', { extraWindowHash }); } else { diff --git a/src/public/app/components/note_context.js b/src/public/app/components/note_context.js index 559e534bb..5e475523b 100644 --- a/src/public/app/components/note_context.js +++ b/src/public/app/components/note_context.js @@ -158,7 +158,7 @@ class NoteContext extends Component { return; } - if (await hoistedNoteService.checkNoteAccess(resolvedNotePath, this) === false) { + if ((await hoistedNoteService.checkNoteAccess(resolvedNotePath, this)) === false) { return; // note is outside of hoisted subtree and user chose not to unhoist } diff --git a/src/public/app/components/root_command_executor.js b/src/public/app/components/root_command_executor.js index 6d65d5c80..89f1333ed 100644 --- a/src/public/app/components/root_command_executor.js +++ b/src/public/app/components/root_command_executor.js @@ -8,6 +8,8 @@ import options from "../services/options.js"; import froca from "../services/froca.js"; import utils from "../services/utils.js"; +import {BrowserWindow} from "@electron/remote"; + export default class RootCommandExecutor extends Component { editReadOnlyNoteCommand() { const noteContext = appContext.tabManager.getActiveContext(); @@ -158,7 +160,6 @@ export default class RootCommandExecutor extends Component { toggleTrayCommand() { if (!utils.isElectron()) return; - const {BrowserWindow} = utils.dynamicRequire('@electron/remote'); const windows = BrowserWindow.getAllWindows(); const isVisible = windows.every(w => w.isVisible()); const action = isVisible ? "hide" : "show" diff --git a/src/public/app/components/tab_manager.js b/src/public/app/components/tab_manager.js index 57c9c8c5c..695530ae9 100644 --- a/src/public/app/components/tab_manager.js +++ b/src/public/app/components/tab_manager.js @@ -248,7 +248,7 @@ export default class TabManager extends Component { async switchToNoteContext(ntxId, notePath, viewScope = {}, hoistedNoteId = null) { const noteContext = this.noteContexts.find(nc => nc.ntxId === ntxId) - || await this.openEmptyTab(); + || (await this.openEmptyTab()); await this.activateNoteContext(noteContext.ntxId); diff --git a/src/public/app/components/zoom.js b/src/public/app/components/zoom.js index 4a0816aae..5bdc5e434 100644 --- a/src/public/app/components/zoom.js +++ b/src/public/app/components/zoom.js @@ -2,6 +2,8 @@ import options from "../services/options.js"; import Component from "./component.js"; import utils from "../services/utils.js"; +import {webFrame} from "electron"; + const MIN_ZOOM = 0.5; const MAX_ZOOM = 2.0; @@ -24,8 +26,6 @@ class ZoomComponent extends Component { setZoomFactor(zoomFactor) { zoomFactor = parseFloat(zoomFactor); - - const webFrame = utils.dynamicRequire('electron').webFrame; webFrame.setZoomFactor(zoomFactor); } @@ -43,7 +43,7 @@ class ZoomComponent extends Component { } getCurrentZoom() { - return utils.dynamicRequire('electron').webFrame.getZoomFactor(); + return webFrame.getZoomFactor(); } zoomOutEvent() { @@ -56,7 +56,7 @@ class ZoomComponent extends Component { zoomResetEvent() { this.setZoomFactorAndSave(1); } - + setZoomFactorAndSaveEvent({zoomFactor}) { this.setZoomFactorAndSave(zoomFactor); } diff --git a/src/public/app/desktop.js b/src/public/app/desktop.js index eb0ac2c21..afc74799d 100644 --- a/src/public/app/desktop.js +++ b/src/public/app/desktop.js @@ -8,6 +8,8 @@ import electronContextMenu from "./menus/electron_context_menu.js"; import DesktopLayout from "./layouts/desktop_layout.js"; import glob from "./services/glob.js"; +import {ipcRenderer} from "electron"; + bundleService.getWidgetBundlesByParent().then(widgetBundles => { appContext.setLayout(new DesktopLayout(widgetBundles)); appContext.start(); @@ -16,7 +18,7 @@ bundleService.getWidgetBundlesByParent().then(widgetBundles => { glob.setupGlobs(); if (utils.isElectron()) { - utils.dynamicRequire('electron').ipcRenderer.on('globalShortcut', + ipcRenderer.on('globalShortcut', async (event, actionName) => appContext.triggerCommand(actionName)); } diff --git a/src/public/app/menus/electron_context_menu.js b/src/public/app/menus/electron_context_menu.js index a74691508..40d4fe277 100644 --- a/src/public/app/menus/electron_context_menu.js +++ b/src/public/app/menus/electron_context_menu.js @@ -3,10 +3,11 @@ import options from "../services/options.js"; import zoomService from "../components/zoom.js"; import contextMenu from "./context_menu.js"; -function setupContextMenu() { - const electron = utils.dynamicRequire('electron'); +import electron from "electron"; - const remote = utils.dynamicRequire('@electron/remote'); +import remote from "@electron/remote"; + +function setupContextMenu() { const {webContents} = remote.getCurrentWindow(); webContents.on('context-menu', (event, params) => { diff --git a/src/public/app/menus/tree_context_menu.js b/src/public/app/menus/tree_context_menu.js index 38c245251..7f1889fb2 100644 --- a/src/public/app/menus/tree_context_menu.js +++ b/src/public/app/menus/tree_context_menu.js @@ -134,7 +134,7 @@ export default class TreeContextMenu { this.treeWidget.triggerCommand("openNewNoteSplit", {ntxId, notePath}); } else if (command === 'convertNoteToAttachment') { - if (!await dialogService.confirm(`Are you sure you want to convert note selected notes into attachments of their parent notes?`)) { + if (!(await dialogService.confirm(`Are you sure you want to convert note selected notes into attachments of their parent notes?`))) { return; } diff --git a/src/public/app/services/clipboard.js b/src/public/app/services/clipboard.js index 424784285..b909e666f 100644 --- a/src/public/app/services/clipboard.js +++ b/src/public/app/services/clipboard.js @@ -4,6 +4,10 @@ import froca from "./froca.js"; import linkService from "./link.js"; import utils from "./utils.js"; + +// https://github.com/zadam/trilium/issues/2401 +import {clipboard} from "electron"; + let clipboardBranchIds = []; let clipboardMode = null; @@ -66,8 +70,6 @@ async function copy(branchIds) { clipboardMode = 'copy'; if (utils.isElectron()) { - // https://github.com/zadam/trilium/issues/2401 - const {clipboard} = require('electron'); const links = []; for (const branch of froca.getBranches(clipboardBranchIds)) { diff --git a/src/public/app/services/hoisted_note.js b/src/public/app/services/hoisted_note.js index f0accda7f..29e4e36f2 100644 --- a/src/public/app/services/hoisted_note.js +++ b/src/public/app/services/hoisted_note.js @@ -53,7 +53,7 @@ async function checkNoteAccess(notePath, noteContext) { const hoistedNote = await froca.getNote(hoistedNoteId); if (!hoistedNote.hasAncestor('_hidden') - && !await dialogService.confirm(`Requested note '${requestedNote.title}' is outside of hoisted note '${hoistedNote.title}' subtree and you must unhoist to access the note. Do you want to proceed with unhoisting?`)) { + && !(await dialogService.confirm(`Requested note '${requestedNote.title}' is outside of hoisted note '${hoistedNote.title}' subtree and you must unhoist to access the note. Do you want to proceed with unhoisting?`))) { return false; } diff --git a/src/public/app/services/link.js b/src/public/app/services/link.js index 73ad58704..69d292ff5 100644 --- a/src/public/app/services/link.js +++ b/src/public/app/services/link.js @@ -4,6 +4,8 @@ import appContext from "../components/app_context.js"; import froca from "./froca.js"; import utils from "./utils.js"; +import electron from "electron"; + function getNotePathFromUrl(url) { const notePathMatch = /#(root[A-Za-z0-9_/]*)$/.exec(url); @@ -242,8 +244,6 @@ function goToLinkExt(evt, hrefLink, $link) { if (hrefLink.toLowerCase().startsWith('http') || hrefLink.startsWith("api/")) { window.open(hrefLink, '_blank'); } else if (hrefLink.toLowerCase().startsWith('file:') && utils.isElectron()) { - const electron = utils.dynamicRequire('electron'); - electron.shell.openPath(hrefLink); } } diff --git a/src/public/app/services/open.js b/src/public/app/services/open.js index b3a1ae08b..6f4b7a321 100644 --- a/src/public/app/services/open.js +++ b/src/public/app/services/open.js @@ -1,6 +1,12 @@ import utils from "./utils.js"; import server from "./server.js"; +import remote from "@electron/remote"; + +import {exec} from "child_process"; + +import electron from "electron"; + function checkType(type) { if (type !== 'notes' && type !== 'attachments') { throw new Error(`Unrecognized type '${type}', should be 'notes' or 'attachments'`); @@ -21,8 +27,6 @@ function getOpenFileUrl(type, noteId) { function download(url) { if (utils.isElectron()) { - const remote = utils.dynamicRequire('@electron/remote'); - remote.getCurrentWebContents().downloadURL(url); } else { window.location.href = url; @@ -49,7 +53,6 @@ async function openCustom(type, entityId, mime) { const resp = await server.post(`${type}/${entityId}/save-to-tmp-dir`); let filePath = resp.tmpFilePath; - const {exec} = utils.dynamicRequire('child_process'); const platform = process.platform; if (platform === 'linux') { @@ -139,8 +142,6 @@ async function openExternally(type, entityId, mime) { if (utils.isElectron()) { const resp = await server.post(`${type}/${entityId}/save-to-tmp-dir`); - - const electron = utils.dynamicRequire('electron'); const res = await electron.shell.openPath(resp.tmpFilePath); if (res) { diff --git a/src/public/app/services/server.js b/src/public/app/services/server.js index b8a1d29fb..59c9dac4a 100644 --- a/src/public/app/services/server.js +++ b/src/public/app/services/server.js @@ -1,6 +1,8 @@ import utils from './utils.js'; import ValidationError from "./validation_error.js"; +import {ipcRenderer as ipc} from "electron"; + async function getHeaders(headers) { const appContext = (await import('../components/app_context.js')).default; const activeNoteContext = appContext.tabManager ? appContext.tabManager.getActiveContext() : null; @@ -81,7 +83,6 @@ async function call(method, url, componentId, options = {}) { const {data} = options; if (utils.isElectron()) { - const ipc = utils.dynamicRequire('electron').ipcRenderer; const requestId = idCounter++; resp = await new Promise((resolve, reject) => { @@ -159,8 +160,6 @@ function ajax(url, method, data, headers, silentNotFound) { } if (utils.isElectron()) { - const ipc = utils.dynamicRequire('electron').ipcRenderer; - ipc.on('server-response', async (event, arg) => { if (arg.statusCode >= 200 && arg.statusCode < 300) { handleSuccessfulResponse(arg); diff --git a/src/public/app/services/tree.js b/src/public/app/services/tree.js index 3a3907585..3a92d18c5 100644 --- a/src/public/app/services/tree.js +++ b/src/public/app/services/tree.js @@ -4,6 +4,8 @@ import froca from './froca.js'; import hoistedNoteService from '../services/hoisted_note.js'; import appContext from "../components/app_context.js"; +import {getCurrentWindow} from "@electron/remote"; + /** * @returns {string|null} */ @@ -121,7 +123,7 @@ ws.subscribeToMessages(message => { appContext.tabManager.activateOrOpenNote(message.noteId); if (utils.isElectron()) { - const currentWindow = utils.dynamicRequire('@electron/remote').getCurrentWindow(); + const currentWindow = getCurrentWindow(); currentWindow.show(); } diff --git a/src/public/app/setup.js b/src/public/app/setup.js index c40d0fb8e..a17d577e6 100644 --- a/src/public/app/setup.js +++ b/src/public/app/setup.js @@ -1,6 +1,8 @@ import utils from "./services/utils.js"; import macInit from './services/mac_init.js'; +import remote from "@electron/remote"; + macInit.init(); function SetupModel() { @@ -84,7 +86,6 @@ async function checkOutstandingSyncs() { if (initialized) { if (utils.isElectron()) { - const remote = utils.dynamicRequire('@electron/remote'); remote.app.relaunch(); remote.app.exit(0); } diff --git a/src/public/app/widgets/buttons/attachments_actions.js b/src/public/app/widgets/buttons/attachments_actions.js index c62030171..d1d4878a5 100644 --- a/src/public/app/widgets/buttons/attachments_actions.js +++ b/src/public/app/widgets/buttons/attachments_actions.js @@ -123,7 +123,7 @@ export default class AttachmentActionsWidget extends BasicWidget { } async deleteAttachmentCommand() { - if (!await dialogService.confirm(`Are you sure you want to delete attachment '${this.attachment.title}'?`)) { + if (!(await dialogService.confirm(`Are you sure you want to delete attachment '${this.attachment.title}'?`))) { return; } @@ -132,7 +132,7 @@ export default class AttachmentActionsWidget extends BasicWidget { } async convertAttachmentIntoNoteCommand() { - if (!await dialogService.confirm(`Are you sure you want to convert attachment '${this.attachment.title}' into a separate note?`)) { + if (!(await dialogService.confirm(`Are you sure you want to convert attachment '${this.attachment.title}' into a separate note?`))) { return; } diff --git a/src/public/app/widgets/buttons/global_menu.js b/src/public/app/widgets/buttons/global_menu.js index 35b88923f..2b1974c8a 100644 --- a/src/public/app/widgets/buttons/global_menu.js +++ b/src/public/app/widgets/buttons/global_menu.js @@ -3,6 +3,8 @@ import utils from "../../services/utils.js"; import UpdateAvailableWidget from "./update_available.js"; import options from "../../services/options.js"; +import {webFrame} from "electron"; + const TPL = `