Skip to content

Build your personal knowledge base with Trilium Notes

refactor(core): deduplicate some bootstrap items

Elian Doranb880d811041f
diff --git a/apps/client-standalone/src/lightweight/browser_routes.ts b/apps/client-standalone/src/lightweight/browser_routes.ts
index 35edc02a0a..a0ee5caa94 100644
--- a/apps/client-standalone/src/lightweight/browser_routes.ts
+++ b/apps/client-standalone/src/lightweight/browser_routes.ts
@@ -246,17 +246,12 @@ function bootstrapRoute(): BootstrapDefinition {
if (!isDbInitialized) {
return {
...commonItems,
- dbInitialized: false,
baseApiUrl: "../api/",
- assetPath,
- themeCssUrl: false,
- themeUseNextAsBase: "next"
};
}
return {
...commonItems,
- dbInitialized: true,
appPath: assetPath,
device: false, // Let the client detect device type.
csrfToken: "dummy-csrf-token",
diff --git a/apps/client/src/services/ws.ts b/apps/client/src/services/ws.ts
index c94425b13b..d22292d719 100644
--- a/apps/client/src/services/ws.ts
+++ b/apps/client/src/services/ws.ts
@@ -1,13 +1,14 @@
-import utils from "./utils.js";
-import toastService from "./toast.js";
-import server from "./server.js";
-import options from "./options.js";
-import frocaUpdater from "./froca_updater.js";
+import { WebSocketMessage } from "@triliumnext/commons";
+
import appContext from "../components/app_context.js";
-import { t } from "./i18n.js";
import type { EntityChange } from "../server_types.js";
-import { WebSocketMessage } from "@triliumnext/commons";
+import frocaUpdater from "./froca_updater.js";
+import { t } from "./i18n.js";
+import options from "./options.js";
+import server from "./server.js";
+import toastService from "./toast.js";
import toast from "./toast.js";
+import utils from "./utils.js";
type MessageHandler = (message: WebSocketMessage) => void;
let messageHandlers: MessageHandler[] = [];
@@ -179,7 +180,7 @@ function waitForEntityChangeId(desiredEntityChangeId: number) {
return new Promise<void>((res, rej) => {
entityChangeIdReachedListeners.push({
- desiredEntityChangeId: desiredEntityChangeId,
+ desiredEntityChangeId,
resolvePromise: res,
start: Date.now()
});
@@ -253,6 +254,7 @@ function connectWebSocket() {
}
async function sendPing() {
+ console.log("Got ws", ws);
if (!ws) {
// In standalone mode, there's no WebSocket — nothing to ping.
return;
diff --git a/apps/server/src/routes/index.ts b/apps/server/src/routes/index.ts
index 8b73a2bfda..899156b3e2 100644
--- a/apps/server/src/routes/index.ts
+++ b/apps/server/src/routes/index.ts
@@ -32,11 +32,7 @@ export function bootstrap(req: Request, res: Response) {
if (!isDbInitialized) {
return {
...commonItems,
- dbInitialized: false,
- baseApiUrl: "../api/",
- assetPath,
- themeCssUrl: false,
- themeUseNextAsBase: "next",
+ baseApiUrl: "../api/"
};
}
@@ -55,7 +51,6 @@ export function bootstrap(req: Request, res: Response) {
res.send({
...commonItems,
- dbInitialized: true,
device: view,
csrfToken,
themeCssUrl: getThemeCssUrl(theme, themeNote),
diff --git a/packages/commons/src/lib/server_api.ts b/packages/commons/src/lib/server_api.ts
index 58e408972b..e55d22d1a2 100644
--- a/packages/commons/src/lib/server_api.ts
+++ b/packages/commons/src/lib/server_api.ts
@@ -316,6 +316,7 @@ export interface DefinitionObject {
* Subset of bootstrap items that are available both in the main client and in the setup page.
*/
export interface BootstrapCommonItems {
+ dbInitialized: boolean;
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 d592c91042..302bafa2b6 100644
--- a/packages/trilium-core/src/services/bootstrap_utils.ts
+++ b/packages/trilium-core/src/services/bootstrap_utils.ts
@@ -11,11 +11,16 @@ export default function getSharedBootstrapItems(assetPath: string, dbInitialized
const commonItems: Partial<BootstrapCommonItems> = {
assetPath,
+ dbInitialized,
...getIconConfig(assetPath)
};
if (!dbInitialized) {
- return commonItems;
+ return {
+ ...commonItems,
+ themeCssUrl: false,
+ themeUseNextAsBase: "next"
+ };
}
return {