Notes/src/public/app/widgets/buttons/launcher/script_launcher.ts

24 lines
743 B
TypeScript
Raw Normal View History

import type FNote from "../../../entities/fnote.js";
2022-12-02 16:46:14 +01:00
import AbstractLauncher from "./abstract_launcher.js";
export default class ScriptLauncher extends AbstractLauncher {
constructor(launcherNote: FNote) {
2022-12-02 16:46:14 +01:00
super(launcherNote);
this.title(() => this.launcherNote.title)
.icon(() => this.launcherNote.getIcon())
.onClick(() => this.launch());
2022-12-02 16:46:14 +01:00
}
async launch() {
2025-01-09 18:07:02 +02:00
if (this.launcherNote.isLabelTruthy("scriptInLauncherContent")) {
await this.launcherNote.executeScript();
} else {
2025-01-09 18:07:02 +02:00
const script = await this.launcherNote.getRelationTarget("script");
if (script) {
await script.executeScript();
}
}
2022-12-02 16:46:14 +01:00
}
}