2022-08-04 23:00:32 +02:00
|
|
|
import FlexContainer from "./flex_container.js";
|
|
|
|
import froca from "../../services/froca.js";
|
2022-12-01 13:07:23 +01:00
|
|
|
import appContext from "../../components/app_context.js";
|
2022-12-01 16:22:04 +01:00
|
|
|
import LauncherWidget from "./launcher.js";
|
2022-08-04 23:00:32 +02:00
|
|
|
|
2022-12-01 10:16:57 +01:00
|
|
|
export default class LauncherContainer extends FlexContainer {
|
2022-08-04 23:00:32 +02:00
|
|
|
constructor() {
|
|
|
|
super('column');
|
|
|
|
|
2022-12-01 10:16:57 +01:00
|
|
|
this.id('launcher-container');
|
2022-08-04 23:00:32 +02:00
|
|
|
this.css('height', '100%');
|
|
|
|
this.filling();
|
|
|
|
|
|
|
|
this.load();
|
|
|
|
}
|
|
|
|
|
|
|
|
async load() {
|
2022-12-11 22:26:18 +01:00
|
|
|
await froca.initializedPromise;
|
|
|
|
|
2022-08-04 23:00:32 +02:00
|
|
|
this.children = [];
|
|
|
|
|
2022-12-06 23:48:44 +01:00
|
|
|
const visibleLaunchersRoot = await froca.getNote('lbVisibleLaunchers', true);
|
2022-08-06 15:00:56 +02:00
|
|
|
|
2022-12-01 10:16:57 +01:00
|
|
|
if (!visibleLaunchersRoot) {
|
|
|
|
console.log("Visible launchers root note doesn't exist.");
|
2022-08-06 15:00:56 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2022-08-04 23:00:32 +02:00
|
|
|
|
2022-11-28 23:39:23 +01:00
|
|
|
await Promise.allSettled(
|
2022-12-01 10:16:57 +01:00
|
|
|
(await visibleLaunchersRoot.getChildNotes())
|
2022-12-01 16:22:04 +01:00
|
|
|
.map(async launcherNote => {
|
|
|
|
try {
|
2022-12-02 16:46:14 +01:00
|
|
|
const launcherWidget = new LauncherWidget();
|
|
|
|
await launcherWidget.initLauncher(launcherNote);
|
2022-12-01 16:22:04 +01:00
|
|
|
this.child(launcherWidget);
|
|
|
|
}
|
|
|
|
catch (e) {
|
2022-12-02 16:46:14 +01:00
|
|
|
console.error(e);
|
2022-12-01 16:22:04 +01:00
|
|
|
}
|
|
|
|
})
|
2022-11-28 23:39:23 +01:00
|
|
|
);
|
2022-08-04 23:00:32 +02:00
|
|
|
|
|
|
|
this.$widget.empty();
|
|
|
|
this.renderChildren();
|
|
|
|
|
2022-11-27 23:43:25 +01:00
|
|
|
await this.handleEventInChildren('initialRenderComplete');
|
|
|
|
|
|
|
|
const activeContext = appContext.tabManager.getActiveContext();
|
|
|
|
|
2022-11-28 23:39:23 +01:00
|
|
|
if (activeContext) {
|
|
|
|
await this.handleEvent('setNoteContext', {
|
|
|
|
noteContext: activeContext
|
|
|
|
});
|
|
|
|
|
|
|
|
if (activeContext.notePath) {
|
|
|
|
await this.handleEvent('noteSwitched', {
|
|
|
|
noteContext: activeContext,
|
|
|
|
notePath: activeContext.notePath
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2022-11-27 23:43:25 +01:00
|
|
|
}
|
|
|
|
|
2022-08-04 23:00:32 +02:00
|
|
|
entitiesReloadedEvent({loadResults}) {
|
2022-12-06 23:48:44 +01:00
|
|
|
if (loadResults.getBranches().find(branch => froca.getNoteFromCache(branch.parentNoteId)?.isLaunchBarConfig())) {
|
2022-12-03 21:11:49 +01:00
|
|
|
// changes in note placement requires reload of all launchers, all other changes are handled by individual
|
|
|
|
// launchers
|
2022-08-04 23:00:32 +02:00
|
|
|
this.load();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|