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
removed dependency on note tree widget from app context
zadam6d912c4897cd
diff --git a/src/public/javascripts/desktop.js b/src/public/javascripts/desktop.jsindex f9bc52396f..23640906f9 100644--- a/src/public/javascripts/desktop.js+++ b/src/public/javascripts/desktop.js@@ -36,6 +36,7 @@ window.glob.isDesktop = utils.isDesktop;window.glob.isMobile = utils.isMobile;// required for CKEditor image upload plugin+// FIXMEwindow.glob.getActiveNode = () => appContext.getMainNoteTree().getActiveNode();window.glob.getHeaders = server.getHeaders;window.glob.showAddLinkDialog = () => import('./dialogs/add_link.js').then(d => d.showDialog());diff --git a/src/public/javascripts/dialogs/move_to.js b/src/public/javascripts/dialogs/move_to.jsindex 4fde498025..345fb184a5 100644--- a/src/public/javascripts/dialogs/move_to.js+++ b/src/public/javascripts/dialogs/move_to.js@@ -36,6 +36,7 @@ export async function showDialog(nodes) {}async function moveNotesTo(notePath) {+ // FIXMEconst targetNode = await appContext.getMainNoteTree().getNodeFromPath(notePath);await treeChangesService.moveToParentNote(movedNodes, targetNode);diff --git a/src/public/javascripts/mobile.js b/src/public/javascripts/mobile.jsindex 273713ab14..9d3cf4d745 100644--- a/src/public/javascripts/mobile.js+++ b/src/public/javascripts/mobile.js@@ -90,6 +90,7 @@ async function showTree() {}$detail.on("click", ".note-menu-button", async e => {+ // FIXMEconst node = appContext.getMainNoteTree().getActiveNode();const branch = treeCache.getBranch(node.data.branchId);const note = await treeCache.getNote(node.data.noteId);diff --git a/src/public/javascripts/services/app_context.js b/src/public/javascripts/services/app_context.jsindex 39b84c3841..0bbdbd695e 100644--- a/src/public/javascripts/services/app_context.js+++ b/src/public/javascripts/services/app_context.js@@ -1,4 +1,3 @@-import NoteTreeWidget from "../widgets/note_tree.js";import TabContext from "./tab_context.js";import server from "./server.js";import treeCache from "./tree_cache.js";@@ -10,6 +9,7 @@ import utils from "./utils.js";import treeService from "./tree.js";import ZoomService from "./zoom.js";import Layout from "../widgets/layout.js";+import SpacedUpdate from "./spaced_update.js";class AppContext {constructor(layout) {@@ -17,8 +17,17 @@ class AppContext {this.components = [];/** @type {TabContext[]} */this.tabContexts = [];- this.tabsChangedTaskId = null;this.activeTabId = null;++ this.tabsUpdate = new SpacedUpdate(async () => {+ const openTabs = this.tabContexts+ .map(tc => tc.getTabState())+ .filter(t => !!t);++ await server.put('options', {+ openTabs: JSON.stringify(openTabs)+ });+ });}async start() {@@ -88,18 +97,16 @@ class AppContext {filteredTabs[0].active = true;}- for (const tab of filteredTabs) {- const tabContext = this.openEmptyTab();- tabContext.setNote(tab.notePath);+ this.tabsUpdate.allowUpdateWithoutChange(() => {+ for (const tab of filteredTabs) {+ const tabContext = this.openEmptyTab();+ tabContext.setNote(tab.notePath);- if (tab.active) {- this.activateTab(tabContext.tabId);+ if (tab.active) {+ this.activateTab(tabContext.tabId);+ }}- }-- // previous opening triggered task to save tab changes but these are bogus changes (this is init)- // so we'll cancel it- this.clearOpenTabsTask();+ });}showWidgets() {@@ -201,13 +208,6 @@ class AppContext {await tabContext.setNote(notePath);}- /**- * @return {NoteTreeWidget}- */- getMainNoteTree() {- return this.noteTreeWidget;- }-getTab(newTab, state) {if (!this.getActiveTabContext() || newTab) {// if it's a new tab explicitly by user then it's in background@@ -266,35 +266,8 @@ class AppContext {this.saveOpenTabs();}- async saveOpenTabs() {- const openTabs = [];-- for (const tabContext of this.tabContexts) {- const tabState = tabContext.getTabState();-- if (tabState) {- openTabs.push(tabState);- }- }-- await server.put('options', {- openTabs: JSON.stringify(openTabs)- });- }-- clearOpenTabsTask() {- if (this.tabsChangedTaskId) {- clearTimeout(this.tabsChangedTaskId);- }- }-openTabsChangedListener() {- // we don't want to send too many requests with tab changes so we always schedule task to do this in 1 seconds,- // but if there's any change in between, we cancel the old one and schedule new one- // so effectively we kind of wait until user stopped e.g. quickly switching tabs- this.clearOpenTabsTask();-- this.tabsChangedTaskId = setTimeout(() => this.saveOpenTabs(), 1000);+ this.tabsUpdate.scheduleUpdate();}activateTab(tabId) {diff --git a/src/public/javascripts/services/dialog_events.js b/src/public/javascripts/services/dialog_events.jsindex 51f484bf7a..2aebb3a873 100644--- a/src/public/javascripts/services/dialog_events.js+++ b/src/public/javascripts/services/dialog_events.js@@ -34,7 +34,7 @@ export default class DialogEventComponent extends Component {}async cloneNotesToListener() {- // probably should not happen here+ // FIXMEconst selectedOrActiveNodes = this.appContext.getMainNoteTree().getSelectedOrActiveNodes();const noteIds = selectedOrActiveNodes.map(node => node.data.noteId);@@ -44,6 +44,7 @@ export default class DialogEventComponent extends Component {}async moveNotesToListener() {+ // FIXMEconst selectedOrActiveNodes = this.appContext.getMainNoteTree().getSelectedOrActiveNodes();const d = await import("../dialogs/move_to.js");@@ -51,6 +52,7 @@ export default class DialogEventComponent extends Component {}async editBranchPrefixListener() {+ // FIXMEconst node = this.appContext.getMainNoteTree().getActiveNode();const editBranchPrefixDialog = await import("../dialogs/branch_prefix.js");diff --git a/src/public/javascripts/services/entrypoints.js b/src/public/javascripts/services/entrypoints.jsindex e82edc3c72..c1f33f21f6 100644--- a/src/public/javascripts/services/entrypoints.js+++ b/src/public/javascripts/services/entrypoints.js@@ -78,17 +78,17 @@ export default class Entrypoints extends Component {}toggleNoteHoistingListener() {- const node = appContext.getMainNoteTree().getActiveNode();+ const note = appContext.getActiveTabNote();hoistedNoteService.getHoistedNoteId().then(async hoistedNoteId => {- if (node.data.noteId === hoistedNoteId) {+ if (note.noteId === hoistedNoteId) {hoistedNoteService.unhoist();}else {- const note = await treeCache.getNote(node.data.noteId);+ const note = await treeCache.getNote(note.noteId);if (note.type !== 'search') {- hoistedNoteService.setHoistedNoteId(node.data.noteId);+ hoistedNoteService.setHoistedNoteId(note.noteId);}}});diff --git a/src/public/javascripts/services/search_notes.js b/src/public/javascripts/services/search_notes.jsindex de67ececa9..2c001e623f 100644--- a/src/public/javascripts/services/search_notes.js+++ b/src/public/javascripts/services/search_notes.js@@ -17,6 +17,7 @@ const helpText = `</p>`;async function refreshSearch() {+ // FIXMEconst activeNode = appContext.getMainNoteTree().getActiveNode();activeNode.load(true);diff --git a/src/public/javascripts/widgets/note_tree.js b/src/public/javascripts/widgets/note_tree.jsindex d5f2b93497..567eff5f60 100644--- a/src/public/javascripts/widgets/note_tree.js+++ b/src/public/javascripts/widgets/note_tree.js@@ -35,8 +35,6 @@ export default class NoteTreeWidget extends TabAwareWidget {window.glob.cutIntoNote = () => this.cutIntoNoteListener();- this.appContext.noteTreeWidget = this;-this.tree = null;}diff --git a/src/public/javascripts/widgets/search_box.js b/src/public/javascripts/widgets/search_box.jsindex 432601411b..eb35120e8e 100644--- a/src/public/javascripts/widgets/search_box.js+++ b/src/public/javascripts/widgets/search_box.js@@ -107,6 +107,7 @@ export default class SearchBoxWidget extends BasicWidget {return;}+ // FIXMElet activeNode = appContext.getMainNoteTree().getActiveNode();const parentNote = await treeCache.getNote(activeNode.data.noteId);