feat(badges/content): configurable backend run options

This commit is contained in:
Elian Doran
2026-02-14 11:30:05 +02:00
parent ef75de63fe
commit bd1f0909a2
2 changed files with 54 additions and 4 deletions

View File

@@ -2295,6 +2295,11 @@
"toggle_tooltip_enable_tooltip": "Click to enable this {{type}}.",
"toggle_tooltip_disable_tooltip": "Click to disable this {{type}}.",
"menu_docs": "Open documentation",
"menu_execute_now": "Execute script now"
"menu_execute_now": "Execute script now",
"menu_run": "Run automatically",
"menu_run_disabled": "Manually",
"menu_run_backend_startup": "When the backend starts up",
"menu_run_hourly": "Hourly",
"menu_run_daily": "Daily"
}
}

View File

@@ -1,4 +1,5 @@
import { BUILTIN_ATTRIBUTES } from "@triliumnext/commons";
import { note } from "mermaid/dist/rendering-util/rendering-elements/shapes/note.js";
import { useEffect, useState } from "preact/hooks";
import FNote from "../../entities/fnote";
@@ -6,9 +7,9 @@ import attributes from "../../services/attributes";
import { t } from "../../services/i18n";
import { openInAppHelpFromUrl } from "../../services/utils";
import { BadgeWithDropdown } from "../react/Badge";
import { FormDropdownDivider, FormListItem } from "../react/FormList";
import { FormDropdownDivider, FormDropdownSubmenu, FormListItem } from "../react/FormList";
import FormToggle from "../react/FormToggle";
import { useNoteContext, useTriliumEvent } from "../react/hooks";
import { useNoteContext, useNoteLabel, useTriliumEvent, useTriliumOption } from "../react/hooks";
const DANGEROUS_ATTRIBUTES = BUILTIN_ATTRIBUTES.filter(a => a.isDangerous);
const activeContentLabels = [ "iconPack" ] as const;
@@ -49,7 +50,7 @@ export function ActiveContentBadges() {
);
}
function ActiveContentBadge({ info }: { note: FNote, info: ActiveContentInfo }) {
function ActiveContentBadge({ info, note }: { note: FNote, info: ActiveContentInfo }) {
const { icon, helpPage, apiDocsPage, isExecutable } = typeMappings[info.type];
return (
<BadgeWithDropdown
@@ -63,6 +64,7 @@ function ActiveContentBadge({ info }: { note: FNote, info: ActiveContentInfo })
icon="bx bx-play"
triggerCommand="runActiveNote"
>{t("active_content_badges.menu_execute_now")}</FormListItem>
<ScriptRunOptions note={note} />
<FormDropdownDivider />
</>
)}
@@ -80,6 +82,49 @@ function ActiveContentBadge({ info }: { note: FNote, info: ActiveContentInfo })
);
}
function ScriptRunOptions({ note }: { note: FNote }) {
const [ run, setRun ] = useNoteLabel(note, "run");
const options: {
title: string;
value: string | null;
type: "backendScript" | "frontendScript";
}[] = [
{
title: t("active_content_badges.menu_run_disabled"),
value: null,
type: "backendScript"
},
{
title: t("active_content_badges.menu_run_backend_startup"),
value: "backendStartup",
type: "backendScript"
},
{
title: t("active_content_badges.menu_run_daily"),
value: "daily",
type: "backendScript"
},
{
title: t("active_content_badges.menu_run_hourly"),
value: "hourly",
type: "backendScript"
},
];
return (
<FormDropdownSubmenu title={t("active_content_badges.menu_run")} icon="bx bx-rss" dropStart>
{options.map(({ title, value }) => (
<FormListItem
key={value}
onClick={() => setRun(value)}
checked={run ? run === value : value === null }
>{title}</FormListItem>
))}
</FormDropdownSubmenu>
);
}
function getTranslationForType(type: ActiveContentInfo["type"]) {
switch (type) {
case "iconPack":