mirror of
https://github.com/zadam/trilium.git
synced 2025-12-05 06:54:23 +01:00
chore(react/launch_bar): port script launcher
This commit is contained in:
parent
f89c40cde6
commit
1f4872f72b
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,7 +1,6 @@
|
|||||||
import CalendarWidget from "../buttons/calendar.js";
|
import CalendarWidget from "../buttons/calendar.js";
|
||||||
import SyncStatusWidget from "../sync_status.js";
|
import SyncStatusWidget from "../sync_status.js";
|
||||||
import BasicWidget, { wrapReactWidgets } from "../basic_widget.js";
|
import BasicWidget, { wrapReactWidgets } from "../basic_widget.js";
|
||||||
import ScriptLauncher from "../buttons/launcher/script_launcher.js";
|
|
||||||
import utils, { isMobile } from "../../services/utils.js";
|
import utils, { isMobile } from "../../services/utils.js";
|
||||||
import type FNote from "../../entities/fnote.js";
|
import type FNote from "../../entities/fnote.js";
|
||||||
import BookmarkButtons from "../launch_bar/BookmarkButtons.jsx";
|
import BookmarkButtons from "../launch_bar/BookmarkButtons.jsx";
|
||||||
@ -16,6 +15,7 @@ import { useLegacyWidget } from "../react/hooks.jsx";
|
|||||||
import QuickSearchWidget from "../quick_search.js";
|
import QuickSearchWidget from "../quick_search.js";
|
||||||
import { ParentComponent } from "../react/react_utils.jsx";
|
import { ParentComponent } from "../react/react_utils.jsx";
|
||||||
import { useContext } from "preact/hooks";
|
import { useContext } from "preact/hooks";
|
||||||
|
import { LaunchBarActionButton, useLauncherIconAndTitle } from "../launch_bar/launch_bar_widgets.jsx";
|
||||||
|
|
||||||
interface InnerWidget extends BasicWidget {
|
interface InnerWidget extends BasicWidget {
|
||||||
settings?: {
|
settings?: {
|
||||||
@ -62,7 +62,7 @@ export default class LauncherWidget extends BasicWidget {
|
|||||||
} else if (launcherType === "note") {
|
} else if (launcherType === "note") {
|
||||||
widget = wrapReactWidgets<BasicWidget>([ <NoteLauncher launcherNote={note} /> ])[0];
|
widget = wrapReactWidgets<BasicWidget>([ <NoteLauncher launcherNote={note} /> ])[0];
|
||||||
} else if (launcherType === "script") {
|
} else if (launcherType === "script") {
|
||||||
widget = new ScriptLauncher(note).class("launcher-button");
|
widget = wrapReactWidgets<BasicWidget>([ <ScriptLauncher launcherNote={note} /> ])[0];
|
||||||
} else if (launcherType === "customWidget") {
|
} else if (launcherType === "customWidget") {
|
||||||
widget = await this.initCustomWidget(note);
|
widget = await this.initCustomWidget(note);
|
||||||
} else if (launcherType === "builtinWidget") {
|
} 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 }) {
|
function TodayLauncher({ launcherNote }: { launcherNote: FNote }) {
|
||||||
return (
|
return (
|
||||||
<CustomNoteLauncher
|
<CustomNoteLauncher
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user