mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-10 18:39:22 +08:00
77 lines
2.3 KiB
JavaScript
77 lines
2.3 KiB
JavaScript
import FlexContainer from "./flex_container.js";
|
|
import froca from "../../services/froca.js";
|
|
import appContext from "../../components/app_context.js";
|
|
import LauncherWidget from "./launcher.js";
|
|
|
|
export default class LauncherContainer extends FlexContainer {
|
|
constructor(isHorizontalLayout) {
|
|
super(isHorizontalLayout ? "row" : "column");
|
|
|
|
this.id('launcher-container');
|
|
this.css(isHorizontalLayout ? "width" : 'height', '100%');
|
|
this.filling();
|
|
this.isHorizontalLayout = isHorizontalLayout;
|
|
|
|
this.load();
|
|
}
|
|
|
|
async load() {
|
|
await froca.initializedPromise;
|
|
|
|
const visibleLaunchersRoot = await froca.getNote('_lbVisibleLaunchers', true);
|
|
|
|
if (!visibleLaunchersRoot) {
|
|
console.log("Visible launchers root note doesn't exist.");
|
|
|
|
return;
|
|
}
|
|
|
|
const newChildren = [];
|
|
|
|
for (const launcherNote of await visibleLaunchersRoot.getChildNotes()) {
|
|
try {
|
|
const launcherWidget = new LauncherWidget(this.isHorizontalLayout);
|
|
const success = await launcherWidget.initLauncher(launcherNote);
|
|
|
|
if (success) {
|
|
newChildren.push(launcherWidget);
|
|
}
|
|
}
|
|
catch (e) {
|
|
console.error(e);
|
|
}
|
|
}
|
|
|
|
this.children = [];
|
|
this.child(...newChildren);
|
|
|
|
this.$widget.empty();
|
|
this.renderChildren();
|
|
|
|
await this.handleEventInChildren('initialRenderComplete');
|
|
|
|
const activeContext = appContext.tabManager.getActiveContext();
|
|
|
|
if (activeContext) {
|
|
await this.handleEvent('setNoteContext', {
|
|
noteContext: activeContext
|
|
});
|
|
|
|
if (activeContext.notePath) {
|
|
await this.handleEvent('noteSwitched', {
|
|
noteContext: activeContext,
|
|
notePath: activeContext.notePath
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
entitiesReloadedEvent({loadResults}) {
|
|
if (loadResults.getBranchRows().find(branch => froca.getNoteFromCache(branch.parentNoteId)?.isLaunchBarConfig())) {
|
|
// changes in note placement require reload of all launchers, all other changes are handled by individual
|
|
// launchers
|
|
this.load();
|
|
}
|
|
}
|
|
}
|