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
refactor(client): load app-wide services on demand from FNote, froca and i18n
Elian Doran57199dca796f
diff --git a/apps/client/src/entities/fnote.ts b/apps/client/src/entities/fnote.tsindex 4ef1a39797..5765267837 100644--- a/apps/client/src/entities/fnote.ts+++ b/apps/client/src/entities/fnote.ts@@ -1,12 +1,9 @@import { getNoteIcon, HighlightedTokenInfo } from "@triliumnext/commons";-import { runBackendScript } from "../services/backend_scripting.js";-import bundleService from "../services/bundle.js";import cssClassManager from "../services/css_class_manager.js";import type { Froca } from "../services/froca-interface.js";import noteAttributeCache from "../services/note_attribute_cache.js";import protectedSessionHolder from "../services/protected_session_holder.js";-import search from "../services/search.js";import server from "../services/server.js";import utils from "../services/utils.js";import type FAttachment from "./fattachment.js";@@ -262,6 +259,7 @@ export default class FNote {const isHiddenNote = this.noteId.startsWith("_");const isSearchNote = this.type === "search";if (!includeArchived && !isHiddenNote && !isSearchNote) {+ const { default: search } = await import("../services/search.js");const unorderedIds = new Set(await search.searchForNoteIds(`note.parents.noteId="${this.noteId}" #!archived`));const results: string[] = [];for (const id of this.children) {@@ -1135,8 +1133,10 @@ export default class FNote {const env = this.getScriptEnv();if (env === "frontend") {+ const { default: bundleService } = await import("../services/bundle.js");return await bundleService.getAndExecuteBundle(this.noteId);} else if (env === "backend") {+ const { runBackendScript } = await import("../services/backend_scripting.js");await runBackendScript(this.noteId);} else {throw new Error(`Unrecognized env type ${env} for note ${this.noteId}`);diff --git a/apps/client/src/services/froca.ts b/apps/client/src/services/froca.tsindex 8fad9a40c5..2a3fd998fc 100644--- a/apps/client/src/services/froca.ts+++ b/apps/client/src/services/froca.ts@@ -1,6 +1,5 @@import type { HighlightedTokenInfo } from "@triliumnext/commons";-import appContext from "../components/app_context.js";import FAttachment, { type FAttachmentRow } from "../entities/fattachment.js";import FAttribute, { type FAttributeRow } from "../entities/fattribute.js";import FBlob, { type FBlobRow } from "../entities/fblob.js";@@ -194,6 +193,7 @@ class FrocaImpl implements Froca {this.addResp(resp);+ const { default: appContext } = await import("../components/app_context.js");appContext.triggerEvent("notesReloaded", { noteIds });}@@ -243,6 +243,7 @@ class FrocaImpl implements Froca {?? highlightedTokens.map((token) => ({ token, type: "plain" as const }));// The tree and embedded collections also load search notes, so `SearchResult` needs telling.+ const { default: appContext } = await import("../components/app_context.js");appContext.triggerEvent("notesReloaded", { noteIds: [ note.noteId ] });return { error };diff --git a/apps/client/src/services/i18n.ts b/apps/client/src/services/i18n.tsindex 936a1b456a..b9318b528c 100644--- a/apps/client/src/services/i18n.ts+++ b/apps/client/src/services/i18n.ts@@ -6,7 +6,10 @@ import { initReactI18next } from "react-i18next";/*** A deferred promise that resolves when translations are initialized.*/-export const translationsInitializedPromise = $.Deferred();+let resolveTranslationsInitialized = () => {};+export const translationsInitializedPromise = new Promise<void>((resolve) => {+ resolveTranslationsInitialized = resolve;+});/** Every string in the app proper: 200-300 KB depending on the language. */const APP_NAMESPACE = "translation";@@ -48,7 +51,7 @@ export async function initLocale(locale: LOCALE_IDS = "en", scope: "app" | "entr});await setDayjsLocale(locale);- translationsInitializedPromise.resolve();+ resolveTranslationsInitialized();}/**