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
fix(client/print): circular dependency affecting ws
Elian Doran1514432f7751
diff --git a/apps/client/src/entities/fnote.ts b/apps/client/src/entities/fnote.tsindex dcb768dd71..bcb6c408e6 100644--- a/apps/client/src/entities/fnote.ts+++ b/apps/client/src/entities/fnote.ts@@ -1,6 +1,5 @@import server from "../services/server.js";import noteAttributeCache from "../services/note_attribute_cache.js";-import ws from "../services/ws.js";import protectedSessionHolder from "../services/protected_session_holder.js";import cssClassManager from "../services/css_class_manager.js";import type { Froca } from "../services/froca-interface.js";@@ -586,7 +585,7 @@ export default class FNote {let childBranches = this.getChildBranches();if (!childBranches) {- ws.logError(`No children for '${this.noteId}'. This shouldn't happen.`);+ console.error(`No children for '${this.noteId}'. This shouldn't happen.`);return [];}diff --git a/apps/client/src/services/protected_session.ts b/apps/client/src/services/protected_session.tsindex a2f04a9f00..1e1984ae5d 100644--- a/apps/client/src/services/protected_session.ts+++ b/apps/client/src/services/protected_session.ts@@ -70,26 +70,26 @@ async function setupProtectedSession(password: string) {protectedSessionHolder.enableProtectedSession();}-// ws.subscribeToMessages(async (message) => {-// if (message.type === "protectedSessionLogin") {-// await reloadData();+ws.subscribeToMessages(async (message) => {+ if (message.type === "protectedSessionLogin") {+ await reloadData();-// await appContext.triggerEvent("frocaReloaded", {});+ await appContext.triggerEvent("frocaReloaded", {});-// appContext.triggerEvent("protectedSessionStarted", {});+ appContext.triggerEvent("protectedSessionStarted", {});-// appContext.triggerCommand("closeProtectedSessionPasswordDialog");+ appContext.triggerCommand("closeProtectedSessionPasswordDialog");-// if (protectedSessionDeferred !== null) {-// protectedSessionDeferred.resolve(true);-// protectedSessionDeferred = null;-// }+ if (protectedSessionDeferred !== null) {+ protectedSessionDeferred.resolve(true);+ protectedSessionDeferred = null;+ }-// toastService.showMessage(t("protected_session.started"));-// } else if (message.type === "protectedSessionLogout") {-// utils.reloadFrontendApp(`Protected session logout`);-// }-// });+ toastService.showMessage(t("protected_session.started"));+ } else if (message.type === "protectedSessionLogout") {+ utils.reloadFrontendApp(`Protected session logout`);+ }+});async function protectNote(noteId: string, protect: boolean, includingSubtree: boolean) {await enterProtectedSession();@@ -106,29 +106,29 @@ function makeToast(message: Message, title: string, text: string): ToastOptions};}-// ws.subscribeToMessages(async (message) => {-// if (!("taskType" in message) || message.taskType !== "protectNotes") {-// return;-// }--// const isProtecting = message.data?.protect;-// const title = isProtecting ? t("protected_session.protecting-title") : t("protected_session.unprotecting-title");--// if (message.type === "taskError") {-// toastService.closePersistent(message.taskId);-// toastService.showError(message.message);-// } else if (message.type === "taskProgressCount") {-// const count = message.progressCount;-// const text = isProtecting ? t("protected_session.protecting-in-progress", { count }) : t("protected_session.unprotecting-in-progress-count", { count });-// toastService.showPersistent(makeToast(message, title, text));-// } else if (message.type === "taskSucceeded") {-// const text = isProtecting ? t("protected_session.protecting-finished-successfully") : t("protected_session.unprotecting-finished-successfully");-// const toast = makeToast(message, title, text);-// toast.closeAfter = 3000;--// toastService.showPersistent(toast);-// }-// });+ws.subscribeToMessages(async (message) => {+ if (!("taskType" in message) || message.taskType !== "protectNotes") {+ return;+ }++ const isProtecting = message.data?.protect;+ const title = isProtecting ? t("protected_session.protecting-title") : t("protected_session.unprotecting-title");++ if (message.type === "taskError") {+ toastService.closePersistent(message.taskId);+ toastService.showError(message.message);+ } else if (message.type === "taskProgressCount") {+ const count = message.progressCount;+ const text = isProtecting ? t("protected_session.protecting-in-progress", { count }) : t("protected_session.unprotecting-in-progress-count", { count });+ toastService.showPersistent(makeToast(message, title, text));+ } else if (message.type === "taskSucceeded") {+ const text = isProtecting ? t("protected_session.protecting-finished-successfully") : t("protected_session.unprotecting-finished-successfully");+ const toast = makeToast(message, title, text);+ toast.closeAfter = 3000;++ toastService.showPersistent(toast);+ }+});export default {protectNote,diff --git a/apps/client/src/services/tree.ts b/apps/client/src/services/tree.tsindex 75715a3776..c508654f5a 100644--- a/apps/client/src/services/tree.ts+++ b/apps/client/src/services/tree.ts@@ -122,17 +122,17 @@ async function resolveNotePathToSegments(notePath: string, hoistedNoteId = "root}}-// ws.subscribeToMessages((message) => {-// if (message.type === "openNote") {-// appContext.tabManager.activateOrOpenNote(message.noteId);+ws.subscribeToMessages((message) => {+ if (message.type === "openNote") {+ appContext.tabManager.activateOrOpenNote(message.noteId);-// if (utils.isElectron()) {-// const currentWindow = utils.dynamicRequire("@electron/remote").getCurrentWindow();+ if (utils.isElectron()) {+ const currentWindow = utils.dynamicRequire("@electron/remote").getCurrentWindow();-// currentWindow.show();-// }-// }-// });+ currentWindow.show();+ }+ }+});function getParentProtectedStatus(node: Fancytree.FancytreeNode) {return hoistedNoteService.isHoistedNode(node) ? false : node.getParent().data.isProtected;