Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
server-esm: Solve a few straightforward cases
Elian Doranfe385bf2e413
diff --git a/src/etapi/validators.ts b/src/etapi/validators.tsindex 81ab051d0f..37aafecefb 100644--- a/src/etapi/validators.ts+++ b/src/etapi/validators.ts@@ -1,5 +1,6 @@import noteTypeService from "../services/note_types.js";import dateUtils from "../services/date_utils.js";+import becca from "../becca/becca.js";function mandatory(obj: unknown) {if (obj === undefined) {@@ -64,8 +65,6 @@ function isNoteId(obj: unknown) {return;}- const becca = require('../becca/becca');-if (typeof obj !== 'string') {return `'${obj}' is not a valid noteId`;}diff --git a/src/routes/electron.ts b/src/routes/electron.tsindex be78d13ece..358c49e318 100644--- a/src/routes/electron.ts+++ b/src/routes/electron.ts@@ -1,7 +1,6 @@+import { ipcMain } from "electron";import { Application } from "express";-const ipcMain = require('electron').ipcMain;-interface Response {statusCode: number;getHeader: (name: string) => string;diff --git a/src/routes/setup.ts b/src/routes/setup.tsindex 2d6c43e0df..b38f95a305 100644--- a/src/routes/setup.ts+++ b/src/routes/setup.ts@@ -7,11 +7,11 @@ import assetPath from "../services/asset_path.js";import appPath from "../services/app_path.js";import { Request, Response } from 'express';-function setupPage(req: Request, res: Response) {+async function setupPage(req: Request, res: Response) {if (sqlInit.isDbInitialized()) {if (utils.isElectron()) {- const windowService = require('../services/window');- const { app } = require('electron');+ const windowService = (await import("../services/window")).default;+ const { app } = await import("electron");windowService.createMainWindow(app);windowService.closeSetupWindow();}diff --git a/src/services/consistency_checks.ts b/src/services/consistency_checks.tsindex 82e4e22165..a36b4490da 100644--- a/src/services/consistency_checks.ts+++ b/src/services/consistency_checks.ts@@ -16,6 +16,7 @@ import sanitizeAttributeName from "./sanitize_attribute_name.js";import noteTypesService from "../services/note_types.js";import { BranchRow } from '../becca/entities/rows';import { EntityChange } from './entity_changes_interface';+import becca_loader from "../becca/becca_loader.js";const noteTypes = noteTypesService.getNoteTypeNames();class ConsistencyChecks {@@ -825,7 +826,7 @@ class ConsistencyChecks {}if (this.reloadNeeded) {- require('../becca/becca_loader').reload("consistency checks need becca reload");+ becca_loader.reload("consistency checks need becca reload");}return !this.unrecoveredConsistencyErrors;diff --git a/src/services/options_init.ts b/src/services/options_init.tsindex 4edaa70d71..b06bf0afd4 100644--- a/src/services/options_init.ts+++ b/src/services/options_init.ts@@ -16,7 +16,7 @@ interface NotSyncedOpts {syncProxy?: string;}-function initNotSyncedOptions(initialized: boolean, opts: NotSyncedOpts = {}) {+async function initNotSyncedOptions(initialized: boolean, opts: NotSyncedOpts = {}) {optionService.createOption('openNoteContexts', JSON.stringify([{notePath: 'root',@@ -37,7 +37,7 @@ function initNotSyncedOptions(initialized: boolean, opts: NotSyncedOpts = {}) {let theme = 'dark'; // default based on the poll in https://github.com/zadam/trilium/issues/2516if (utils.isElectron()) {- const {nativeTheme} = require('electron');+ const {nativeTheme} = await import("electron");theme = nativeTheme.shouldUseDarkColors ? 'dark' : 'light';}diff --git a/src/services/protected_session.ts b/src/services/protected_session.tsindex f29b73d179..b24b971d46 100644--- a/src/services/protected_session.ts+++ b/src/services/protected_session.ts@@ -2,6 +2,8 @@import log from "./log.js";import dataEncryptionService from "./encryption/data_encryption.js";+import options from "./options.js";+import ws from "./ws.js";let dataKey: Buffer | null = null;@@ -56,7 +58,6 @@ function touchProtectedSession() {}function checkProtectedSessionExpiration() {- const options = require('./options');const protectedSessionTimeout = options.getOptionInt('protectedSessionTimeout');if (isProtectedSessionAvailable()&& lastProtectedSessionOperationDate@@ -66,7 +67,7 @@ function checkProtectedSessionExpiration() {log.info("Expiring protected session");- require('./ws').reloadFrontend("leaving protected session");+ ws.reloadFrontend("leaving protected session");}}diff --git a/src/services/window.ts b/src/services/window.tsindex bf84081fc0..c343460698 100644--- a/src/services/window.ts+++ b/src/services/window.ts@@ -17,7 +17,7 @@ let setupWindow: BrowserWindow | null;async function createExtraWindow(extraWindowHash: string) {const spellcheckEnabled = optionService.getOptionBool('spellCheckEnabled');- const { BrowserWindow } = require('electron');+ const { BrowserWindow } = await import('electron');const win = new BrowserWindow({width: 1000,@@ -43,7 +43,7 @@ ipcMain.on('create-extra-window', (event, arg) => {});async function createMainWindow(app: App) {- const windowStateKeeper = require('electron-window-state'); // should not be statically imported+ const windowStateKeeper = (await import('electron-window-state')).default; // should not be statically importedconst mainWindowState = windowStateKeeper({// default window width & height, so it's usable on a 1600 * 900 display (including some extra panels etc.)@@ -53,7 +53,7 @@ async function createMainWindow(app: App) {const spellcheckEnabled = optionService.getOptionBool('spellCheckEnabled');- const { BrowserWindow } = require('electron'); // should not be statically imported+ const { BrowserWindow } = (await import('electron')); // should not be statically importedmainWindow = new BrowserWindow({x: mainWindowState.x,@@ -100,7 +100,11 @@ function configureWebContents(webContents: WebContents, spellcheckEnabled: booleremoteMain.enable(webContents);mainWindow.webContents.setWindowOpenHandler((details) => {- require('electron').shell.openExternal(details.url);+ async function openExternal() {+ (await import('electron')).shell.openExternal(details.url);+ }++ openExternal();return { action: 'deny' }});