Skip to content

Build your personal knowledge base with Trilium Notes

chore(react/launch_bar): port script launcher

Elian Doran1f4872f72bd9
diff --git a/apps/client/src/widgets/buttons/launcher/script_launcher.ts b/apps/client/src/widgets/buttons/launcher/script_launcher.ts
deleted file mode 100644
index 8a91e08b1f..0000000000
--- a/apps/client/src/widgets/buttons/launcher/script_launcher.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-import type FNote from "../../../entities/fnote.js";
-import AbstractLauncher from "./abstract_launcher.js";
-
-export default class ScriptLauncher extends AbstractLauncher {
- constructor(launcherNote: FNote) {
- super(launcherNote);
-
- this.title(() => this.launcherNote.title)
- .icon(() => this.launcherNote.getIcon())
- .onClick(() => this.launch());
- }
-
- async launch() {
- if (this.launcherNote.isLabelTruthy("scriptInLauncherContent")) {
- await this.launcherNote.executeScript();
- } else {
- const script = await this.launcherNote.getRelationTarget("script");
- if (script) {
- await script.executeScript();
- }
- }
- }
-}
diff --git a/apps/client/src/widgets/containers/launcher.tsx b/apps/client/src/widgets/containers/launcher.tsx
index 55f518ecad..f30c9ad281 100644
--- a/apps/client/src/widgets/containers/launcher.tsx
+++ b/apps/client/src/widgets/containers/launcher.tsx
@@ -1,7 +1,6 @@
import CalendarWidget from "../buttons/calendar.js";
import SyncStatusWidget from "../sync_status.js";
import BasicWidget, { wrapReactWidgets } from "../basic_widget.js";
-import ScriptLauncher from "../buttons/launcher/script_launcher.js";
import utils, { isMobile } from "../../services/utils.js";
import type FNote from "../../entities/fnote.js";
import BookmarkButtons from "../launch_bar/BookmarkButtons.jsx";
@@ -16,6 +15,7 @@ import { useLegacyWidget } from "../react/hooks.jsx";
import QuickSearchWidget from "../quick_search.js";
import { ParentComponent } from "../react/react_utils.jsx";
import { useContext } from "preact/hooks";
+import { LaunchBarActionButton, useLauncherIconAndTitle } from "../launch_bar/launch_bar_widgets.jsx";
interface InnerWidget extends BasicWidget {
settings?: {
@@ -62,7 +62,7 @@ export default class LauncherWidget extends BasicWidget {
} else if (launcherType === "note") {
widget = wrapReactWidgets<BasicWidget>([ <NoteLauncher launcherNote={note} /> ])[0];
} else if (launcherType === "script") {
- widget = new ScriptLauncher(note).class("launcher-button");
+ widget = wrapReactWidgets<BasicWidget>([ <ScriptLauncher launcherNote={note} /> ])[0];
} else if (launcherType === "customWidget") {
widget = await this.initCustomWidget(note);
} else if (launcherType === "builtinWidget") {
@@ -127,6 +127,26 @@ export default class LauncherWidget extends BasicWidget {
}
}
+function ScriptLauncher({ launcherNote }: { launcherNote: FNote }) {
+ const { icon, title } = useLauncherIconAndTitle(launcherNote);
+ return (
+ <LaunchBarActionButton
+ icon={icon}
+ text={title}
+ onClick={async () => {
+ if (launcherNote.isLabelTruthy("scriptInLauncherContent")) {
+ await launcherNote.executeScript();
+ } else {
+ const script = await launcherNote.getRelationTarget("script");
+ if (script) {
+ await script.executeScript();
+ }
+ }
+ }}
+ />
+ )
+}
+
function TodayLauncher({ launcherNote }: { launcherNote: FNote }) {
return (
<CustomNoteLauncher