Skip to content

Build your personal knowledge base with Trilium Notes

refactor(core): use different mechanism for shared bootstrap items

Elian Doranef8db52ebebc
diff --git a/apps/client-standalone/src/lightweight/browser_routes.ts b/apps/client-standalone/src/lightweight/browser_routes.ts
index 6cc13e9653..35edc02a0a 100644
--- a/apps/client-standalone/src/lightweight/browser_routes.ts
+++ b/apps/client-standalone/src/lightweight/browser_routes.ts
@@ -5,7 +5,6 @@
import { BootstrapDefinition } from '@triliumnext/commons';
import { entity_changes, getContext, getSharedBootstrapItems, getSql, routes, sql_init } from '@triliumnext/core';
-import { getIconConfig } from '@triliumnext/core/src/services/bootstrap_utils';
import packageJson from '../../package.json' with { type: 'json' };
import { type BrowserRequest, BrowserRouter } from './browser_router';
@@ -241,20 +240,23 @@ export function registerRoutes(router: BrowserRouter): void {
function bootstrapRoute(): BootstrapDefinition {
const assetPath = ".";
- if (!sql_init.isDbInitialized()) {
+ const isDbInitialized = sql_init.isDbInitialized();
+ const commonItems = getSharedBootstrapItems(assetPath, isDbInitialized);
+
+ if (!isDbInitialized) {
return {
+ ...commonItems,
dbInitialized: false,
baseApiUrl: "../api/",
assetPath,
themeCssUrl: false,
- themeUseNextAsBase: "next",
- ...getIconConfig(assetPath)
+ themeUseNextAsBase: "next"
};
}
return {
+ ...commonItems,
dbInitialized: true,
- ...getSharedBootstrapItems(assetPath),
appPath: assetPath,
device: false, // Let the client detect device type.
csrfToken: "dummy-csrf-token",
diff --git a/apps/server/src/routes/index.ts b/apps/server/src/routes/index.ts
index 4a0b20e280..8b73a2bfda 100644
--- a/apps/server/src/routes/index.ts
+++ b/apps/server/src/routes/index.ts
@@ -1,6 +1,5 @@
import { BootstrapDefinition } from "@triliumnext/commons";
import { getSharedBootstrapItems, getSql, icon_packs as iconPackService, sql_init } from "@triliumnext/core";
-import { getIconConfig } from "@triliumnext/core/src/services/bootstrap_utils";
import type { Request, Response } from "express";
import packageJson from "../../package.json" with { type: "json" };
@@ -28,14 +27,16 @@ export function bootstrap(req: Request, res: Response) {
req.session.csrfInitialized = true;
}
- if (!sql_init.isDbInitialized()) {
+ const isDbInitialized = sql_init.isDbInitialized();
+ const commonItems = getSharedBootstrapItems(assetPath, isDbInitialized);
+ if (!isDbInitialized) {
return {
+ ...commonItems,
dbInitialized: false,
baseApiUrl: "../api/",
assetPath,
themeCssUrl: false,
themeUseNextAsBase: "next",
- ...getIconConfig(assetPath)
};
}
@@ -53,7 +54,7 @@ export function bootstrap(req: Request, res: Response) {
const sql = getSql();
res.send({
- ...getSharedBootstrapItems(assetPath),
+ ...commonItems,
dbInitialized: true,
device: view,
csrfToken,
diff --git a/packages/commons/src/lib/server_api.ts b/packages/commons/src/lib/server_api.ts
index e1d5c48a6f..58e408972b 100644
--- a/packages/commons/src/lib/server_api.ts
+++ b/packages/commons/src/lib/server_api.ts
@@ -315,7 +315,7 @@ export interface DefinitionObject {
/**
* Subset of bootstrap items that are available both in the main client and in the setup page.
*/
-interface BootstrapCommonItems {
+export interface BootstrapCommonItems {
baseApiUrl: string;
assetPath: string;
themeCssUrl: string | false;
diff --git a/packages/trilium-core/src/services/bootstrap_utils.ts b/packages/trilium-core/src/services/bootstrap_utils.ts
index fdd4bac43a..d592c91042 100644
--- a/packages/trilium-core/src/services/bootstrap_utils.ts
+++ b/packages/trilium-core/src/services/bootstrap_utils.ts
@@ -1,16 +1,25 @@
-import { BootstrapDefinition } from "@triliumnext/commons";
+import { BootstrapCommonItems, BootstrapDefinition } from "@triliumnext/commons";
import { getSql } from "./sql";
import protected_session from "./protected_session";
import { generateCss, generateIconRegistry, getIconPacks, MIME_TO_EXTENSION_MAPPINGS } from "./icon_packs";
import options from "./options";
import { getCurrentLocale } from "./i18n";
-export default function getSharedBootstrapItems(assetPath: string): Pick<BootstrapDefinition, "assetPath" | "headingStyle" | "layoutOrientation" | "maxEntityChangeIdAtLoad" | "maxEntityChangeSyncIdAtLoad" | "isProtectedSessionAvailable" | "iconRegistry" | "iconPackCss" | "currentLocale" | "isRtl"> {
+export default function getSharedBootstrapItems(assetPath: string, dbInitialized: boolean) {
const sql = getSql();
const currentLocale = getCurrentLocale();
- return {
+ const commonItems: Partial<BootstrapCommonItems> = {
assetPath,
+ ...getIconConfig(assetPath)
+ };
+
+ if (!dbInitialized) {
+ return commonItems;
+ }
+
+ return {
+ ...commonItems,
headingStyle: options.getOption("headingStyle") as "plain" | "underline" | "markdown",
layoutOrientation: options.getOption("layoutOrientation") as "vertical" | "horizontal",
maxEntityChangeIdAtLoad: sql.getValue("SELECT COALESCE(MAX(id), 0) FROM entity_changes"),
@@ -18,7 +27,6 @@ export default function getSharedBootstrapItems(assetPath: string): Pick<Bootstr
isProtectedSessionAvailable: protected_session.isProtectedSessionAvailable(),
currentLocale,
isRtl: !!currentLocale.rtl,
- ...getIconConfig(assetPath)
}
}