mirror of
https://github.com/zadam/trilium.git
synced 2025-11-01 02:45:54 +01:00
basic executor / command mechanism
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import server from "./server.js";
|
||||
import treeCache from "./tree_cache.js";
|
||||
import bundleService from "./bundle.js";
|
||||
import DialogEventComponent from "./dialog_events.js";
|
||||
import DialogCommandExecutor from "./dialog_command_executor.js";
|
||||
import Entrypoints from "./entrypoints.js";
|
||||
import options from "./options.js";
|
||||
import utils from "./utils.js";
|
||||
@@ -15,6 +15,7 @@ class AppContext {
|
||||
this.layout = layout;
|
||||
this.tabManager = new TabManager(this);
|
||||
this.components = [];
|
||||
this.executors = [];
|
||||
}
|
||||
|
||||
async start() {
|
||||
@@ -42,8 +43,11 @@ class AppContext {
|
||||
this.components = [
|
||||
this.tabManager,
|
||||
rootContainer,
|
||||
new Entrypoints(this),
|
||||
new DialogEventComponent(this)
|
||||
new Entrypoints(this)
|
||||
];
|
||||
|
||||
this.executors = [
|
||||
new DialogCommandExecutor(this, this)
|
||||
];
|
||||
|
||||
if (utils.isElectron()) {
|
||||
@@ -80,6 +84,30 @@ class AppContext {
|
||||
|
||||
this.trigger('treeCacheReloaded');
|
||||
}
|
||||
|
||||
async triggerCommand(name, data) {
|
||||
for (const executor of this.executors) {
|
||||
const fun = executor[name + 'Command'];
|
||||
|
||||
const called = await this.callMethod(executor, fun, data);
|
||||
|
||||
if (called) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
console.error(`Unhandled command ${name}`);
|
||||
}
|
||||
|
||||
async callMethod(thiz, fun, data) {
|
||||
if (typeof fun !== 'function') {
|
||||
return false;
|
||||
}
|
||||
|
||||
await fun.call(thiz, data);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
const layout = new Layout();
|
||||
|
||||
Reference in New Issue
Block a user