From 1f4872f72bd94fdf2349c45c68931e9ce49ee803 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Thu, 4 Dec 2025 17:16:47 +0200 Subject: [PATCH] chore(react/launch_bar): port script launcher --- .../buttons/launcher/script_launcher.ts | 23 ------------------ .../src/widgets/containers/launcher.tsx | 24 +++++++++++++++++-- 2 files changed, 22 insertions(+), 25 deletions(-) delete mode 100644 apps/client/src/widgets/buttons/launcher/script_launcher.ts 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 8a91e08b1..000000000 --- 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 55f518eca..f30c9ad28 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([ ])[0]; } else if (launcherType === "script") { - widget = new ScriptLauncher(note).class("launcher-button"); + widget = wrapReactWidgets([ ])[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 ( + { + 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 (