Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

refactor(plugins): move schedule setup into plugins

tianma-if4348239748ef
diff --git a/apps/web/src/components/settings/PluginManagerCard.tsx b/apps/web/src/components/settings/PluginManagerCard.tsx
index f449cd74..782c997a 100644
--- a/apps/web/src/components/settings/PluginManagerCard.tsx
+++ b/apps/web/src/components/settings/PluginManagerCard.tsx
@@ -16,24 +16,15 @@ import { PluginUpdateDialog } from "@/components/plugins/PluginUpdateDialog";
import { PluginSettingsSection } from "@/components/plugins/PluginSettingsSection";
import { getPluginDetailPage, getPluginDetailPath, hasPluginSettings, type PluginDetailPage } from "@/lib/plugins/plugin-navigation";
import type { ScheduledTask } from "@edgeever/shared";
-import { Cron } from "croner";
import { api, getOrCreateClientDeviceId } from "@/lib/api";
import { ScheduledTaskRunHistoryDialog } from "@/components/execution/ScheduledTaskRunHistoryDialog";
const permissionLabel = (permission: string) => permission.replace(":", " · ");
-const commandKey = (command: RegisteredPluginCommand) => JSON.stringify([command.pluginId, command.id]);
-
-const ScheduledPluginTasksSection = ({ commands }: { commands: RegisteredPluginCommand[] }) => {
+const LegacyManualScheduledTasksSection = () => {
const { t } = useTranslation();
const queryClient = useQueryClient();
const deviceId = window.edgeeverDesktop?.isAvailable ? getOrCreateClientDeviceId() : null;
- const [selectedCommandKey, setSelectedCommandKey] = useState("");
- const [name, setName] = useState("");
- const [cronExpression, setCronExpression] = useState("0 9 * * *");
- const [timezone, setTimezone] = useState(() => Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC");
- const [missedRunPolicy, setMissedRunPolicy] = useState<"run-once" | "skip">("run-once");
- const [pending, setPending] = useState(false);
const [message, setMessage] = useState<string | null>(null);
const [historyTask, setHistoryTask] = useState<ScheduledTask | null>(null);
const tasksQuery = useQuery({
@@ -45,7 +36,6 @@ const ScheduledPluginTasksSection = ({ commands }: { commands: RegisteredPluginC
if (!deviceId) return null;
- const selectedCommand = commands.find((command) => commandKey(command) === selectedCommandKey);
const refresh = async () => {
await queryClient.invalidateQueries({ queryKey: ["scheduled-tasks"] });
};
@@ -67,153 +57,63 @@ const ScheduledPluginTasksSection = ({ commands }: { commands: RegisteredPluginC
setMessage(error instanceof Error ? error.message : String(error));
}
};
- const createTask = async () => {
- if (!selectedCommand) return;
- setPending(true);
- setMessage(null);
- let validator: Cron | null = null;
- try {
- validator = new Cron(cronExpression.trim(), { timezone: timezone.trim(), paused: true });
- if (!validator.nextRun()) throw new Error(t("plugins.schedules.noNextRun"));
- await api.createScheduledTask({
- name: name.trim() || selectedCommand.title,
- taskType: "plugin-command",
- taskPayload: { pluginId: selectedCommand.pluginId, commandId: selectedCommand.id },
- cronExpression: cronExpression.trim(),
- timezone: timezone.trim(),
- executorDeviceId: deviceId,
- missedRunPolicy,
- });
- setName("");
- setMessage(t("plugins.schedules.created"));
- await refresh();
- } catch (error) {
- setMessage(error instanceof Error ? error.message : String(error));
- } finally {
- validator?.stop();
- setPending(false);
- }
- };
- const tasks = tasksQuery.data?.tasks ?? [];
+ const tasks = (tasksQuery.data?.tasks ?? []).filter((task) => !task.ownerPluginId);
+ if (tasks.length === 0) return null;
+
return (
- <section className="rounded-lg border border-emerald-100 bg-emerald-50/20 p-4">
+ <section className="rounded-lg border border-amber-200 bg-amber-50/40 p-4">
<div className="flex items-start gap-2">
- <CalendarClock className="mt-0.5 h-4 w-4 shrink-0 text-emerald-700" />
+ <CalendarClock className="mt-0.5 h-4 w-4 shrink-0 text-amber-700" />
<div>
- <h3 className="text-xs font-semibold text-slate-800">{t("plugins.schedules.title")}</h3>
- <p className="mt-1 text-xs leading-5 text-slate-500">{t("plugins.schedules.description")}</p>
+ <h3 className="text-xs font-semibold text-slate-800">{t("plugins.schedules.legacyTitle")}</h3>
+ <p className="mt-1 text-xs leading-5 text-slate-500">{t("plugins.schedules.legacyDescription")}</p>
</div>
</div>
- <div className="mt-4 grid gap-3 md:grid-cols-2">
- <label className="grid gap-1.5 text-xs font-medium text-slate-700">
- {t("plugins.schedules.command")}
- <select
- className="h-9 rounded-md border border-slate-200 bg-white px-3 text-sm font-normal text-slate-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-emerald-500/70"
- value={selectedCommandKey}
- onChange={(event) => {
- const nextKey = event.target.value;
- setSelectedCommandKey(nextKey);
- const command = commands.find((candidate) => commandKey(candidate) === nextKey);
- if (command && !name.trim()) setName(command.title);
- }}
- >
- <option value="">{t("plugins.schedules.chooseCommand")}</option>
- {commands.map((command) => (
- <option key={commandKey(command)} value={commandKey(command)}>{command.title} · {command.pluginId}</option>
- ))}
- </select>
- </label>
- <label className="grid gap-1.5 text-xs font-medium text-slate-700">
- {t("plugins.schedules.name")}
- <Input value={name} maxLength={120} onChange={(event) => setName(event.target.value)} />
- </label>
- <label className="grid gap-1.5 text-xs font-medium text-slate-700">
- {t("plugins.schedules.cron")}
- <Input className="font-mono" value={cronExpression} maxLength={160} onChange={(event) => setCronExpression(event.target.value)} />
- </label>
- <label className="grid gap-1.5 text-xs font-medium text-slate-700">
- {t("plugins.schedules.timezone")}
- <Input value={timezone} maxLength={80} onChange={(event) => setTimezone(event.target.value)} />
- </label>
- <label className="grid gap-1.5 text-xs font-medium text-slate-700">
- {t("plugins.schedules.missedRun")}
- <select
- className="h-9 rounded-md border border-slate-200 bg-white px-3 text-sm font-normal text-slate-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-emerald-500/70"
- value={missedRunPolicy}
- onChange={(event) => setMissedRunPolicy(event.target.value as "run-once" | "skip")}
- >
- <option value="run-once">{t("plugins.schedules.runOnce")}</option>
- <option value="skip">{t("plugins.schedules.skip")}</option>
- </select>
- </label>
- <div className="flex items-end">
- <Button className="h-9 gap-1.5" disabled={pending || !selectedCommand || !cronExpression.trim() || !timezone.trim()} onClick={() => void createTask()}>
- <CalendarClock className="h-3.5 w-3.5" />
- {pending ? t("common.saving") : t("plugins.schedules.create")}
- </Button>
- </div>
- </div>
{message ? <p className="mt-3 text-xs text-slate-600">{message}</p> : null}
- {tasks.length > 0 ? (
- <div className="mt-4 grid gap-2">
- {tasks.map((task) => {
- const command = commands.find((candidate) =>
- candidate.pluginId === task.taskPayload.pluginId && candidate.id === task.taskPayload.commandId);
- return (
- <div key={task.id} className="flex flex-wrap items-center gap-3 rounded-md border border-slate-200 bg-white px-3 py-2">
- <div className="min-w-0 flex-1">
- <div className="truncate text-xs font-semibold text-slate-800">{task.name}</div>
- <div className="mt-0.5 truncate font-mono text-[10px] text-slate-400">
- {task.cronExpression} · {task.timezone} · {command?.title ?? `${task.taskPayload.pluginId}:${task.taskPayload.commandId}`}
- </div>
- {task.ownerPluginId && task.pluginScheduleKey ? (
- <div className="mt-1 truncate text-[10px] text-emerald-700/80">
- {t("plugins.schedules.pluginManaged", {
- plugin: task.ownerPluginId,
- key: task.pluginScheduleKey,
- })}
- </div>
- ) : null}
- {task.lastRun ? (
- <div className={`mt-1 text-[10px] ${task.lastRun.status === "failed" ? "text-rose-600" : "text-slate-400"}`}>
- {t(`plugins.schedules.status.${task.lastRun.status}`)} · {new Date(task.lastRun.startedAt).toLocaleString()}
- </div>
- ) : null}
- </div>
- <Switch
- aria-label={t("plugins.schedules.toggle", { name: task.name })}
- checked={task.isEnabled}
- onCheckedChange={(isEnabled) => void updateTask(task.id, isEnabled)}
- />
- <Button
- size="sm"
- variant="ghost"
- className="h-8 gap-1.5 px-2 text-slate-600"
- aria-label={t("plugins.schedules.historyFor", { name: task.name })}
- onClick={() => setHistoryTask(task)}
- >
- <History className="h-3.5 w-3.5" />
- <span>{t("plugins.schedules.history")}</span>
- </Button>
- <Button
- size="sm"
- variant="ghost"
- className="h-8 px-2 text-rose-600 hover:bg-rose-50 hover:text-rose-700"
- aria-label={t("plugins.schedules.delete", { name: task.name })}
- onClick={() => void deleteTask(task.id)}
- >
- <Trash2 className="h-3.5 w-3.5" />
- </Button>
+ <div className="mt-4 grid gap-2">
+ {tasks.map((task) => (
+ <div key={task.id} className="flex flex-wrap items-center gap-3 rounded-md border border-slate-200 bg-white px-3 py-2">
+ <div className="min-w-0 flex-1">
+ <div className="truncate text-xs font-semibold text-slate-800">{task.name}</div>
+ <div className="mt-0.5 truncate font-mono text-[10px] text-slate-400">
+ {task.cronExpression} · {task.timezone} · {task.taskPayload.pluginId}:{task.taskPayload.commandId}
</div>
- );
- })}
- </div>
- ) : (
- <p className="mt-4 text-xs text-slate-400">{t("plugins.schedules.empty")}</p>
- )}
+ {task.lastRun ? (
+ <div className={`mt-1 text-[10px] ${task.lastRun.status === "failed" ? "text-rose-600" : "text-slate-400"}`}>
+ {t(`plugins.schedules.status.${task.lastRun.status}`)} · {new Date(task.lastRun.startedAt).toLocaleString()}
+ </div>
+ ) : null}
+ </div>
+ <Switch
+ aria-label={t("plugins.schedules.toggle", { name: task.name })}
+ checked={task.isEnabled}
+ onCheckedChange={(isEnabled) => void updateTask(task.id, isEnabled)}
+ />
+ <Button
+ size="sm"
+ variant="ghost"
+ className="h-8 gap-1.5 px-2 text-slate-600"
+ aria-label={t("plugins.schedules.historyFor", { name: task.name })}
+ onClick={() => setHistoryTask(task)}
+ >
+ <History className="h-3.5 w-3.5" />
+ <span>{t("plugins.schedules.history")}</span>
+ </Button>
+ <Button
+ size="sm"
+ variant="ghost"
+ className="h-8 px-2 text-rose-600 hover:bg-rose-50 hover:text-rose-700"
+ aria-label={t("plugins.schedules.delete", { name: task.name })}
+ onClick={() => void deleteTask(task.id)}
+ >
+ <Trash2 className="h-3.5 w-3.5" />
+ </Button>
+ </div>
+ ))}
+ </div>
<ScheduledTaskRunHistoryDialog
task={historyTask}
currentDeviceId={deviceId}
@@ -225,7 +125,6 @@ const ScheduledPluginTasksSection = ({ commands }: { commands: RegisteredPluginC
);
};
-
const PluginDetailView = ({
page,
commands,
@@ -500,6 +399,9 @@ export const PluginManagerCard = ({
<CardTitle className="flex items-center gap-2 text-sm">
<Puzzle className="h-4 w-4 text-emerald-700" />
{selectedPluginId ? t("plugins.details.title") : t("plugins.title")}
+ <span className="inline-flex items-center rounded-full border border-emerald-200/80 bg-emerald-50 px-2 py-0.5 text-[10px] font-semibold tracking-wide text-emerald-700 dark:border-emerald-800/60 dark:bg-emerald-950/50 dark:text-emerald-300">
+ Beta
+ </span>
</CardTitle>
<div className="flex items-center gap-1">
{snapshot.extensions.length > 0 ? (
@@ -539,7 +441,7 @@ export const PluginManagerCard = ({
<CardContent className="grid gap-4 p-4 pt-0 sm:px-5 sm:pb-5">
{error ? <div role="alert" className="rounded-lg border border-rose-200 bg-rose-50 p-3 text-xs text-rose-700">{error}</div> : null}
- <ScheduledPluginTasksSection commands={snapshot.commands} />
+ {!selectedPluginId ? <LegacyManualScheduledTasksSection /> : null}
{selectedPluginId ? (
selectedExtension ? (
diff --git a/packages/shared/src/i18n/en-US.ts b/packages/shared/src/i18n/en-US.ts
index 1be25f43..7fdf6de2 100644
--- a/packages/shared/src/i18n/en-US.ts
+++ b/packages/shared/src/i18n/en-US.ts
@@ -579,23 +579,10 @@ export const enUS = {
manage: "Manage plugins and themes",
},
schedules: {
- title: "Plugin schedules",
- description: "Plugins can register schedules themselves, or you can add one manually. Runs on the assigned desktop while EdgeEver is open.",
- command: "Plugin command",
- chooseCommand: "Choose a command",
- name: "Task name",
- cron: "Cron expression",
- timezone: "Time zone",
- missedRun: "When a run is missed",
- runOnce: "Run once after recovery",
- skip: "Skip it",
- create: "Create schedule",
- created: "Scheduled task created.",
- empty: "No scheduled plugin commands are assigned to this device.",
- noNextRun: "This schedule has no future run.",
+ legacyTitle: "Legacy manual tasks",
+ legacyDescription: "These tasks were created manually in an earlier version. Configure new schedules in the relevant plugin settings; you can still disable or delete legacy tasks here.",
toggle: "Enable or disable {{name}}",
delete: "Delete {{name}}",
- pluginManaged: "Registered by {{plugin}} · {{key}}",
history: "Run history",
historyFor: "View run history for {{name}}",
historyTitle: "{{name}} · Run history",
diff --git a/packages/shared/src/i18n/zh-CN.ts b/packages/shared/src/i18n/zh-CN.ts
index 0f3c005f..106febae 100644
--- a/packages/shared/src/i18n/zh-CN.ts
+++ b/packages/shared/src/i18n/zh-CN.ts
@@ -579,23 +579,10 @@ export const zhCN = {
manage: "管理插件与主题",
},
schedules: {
- title: "插件定时任务",
- description: "插件可以自行注册计划,你也可以手动添加。EdgeEver 在绑定的桌面设备运行时执行。",
- command: "插件命令",
- chooseCommand: "选择一个命令",
- name: "任务名称",
- cron: "Cron 表达式",
- timezone: "时区",
- missedRun: "错过计划时",
- runOnce: "恢复后补跑一次",
- skip: "直接跳过",
- create: "创建定时任务",
- created: "定时任务已创建。",
- empty: "当前设备尚未绑定定时插件命令。",
- noNextRun: "这个计划没有下一次执行时间。",
+ legacyTitle: "旧版手动任务",
+ legacyDescription: "这些任务由旧版本手动创建。新的定时任务请在对应插件的设置中配置;你仍可在这里停用或删除旧任务。",
toggle: "启用或停用 {{name}}",
delete: "删除 {{name}}",
- pluginManaged: "由插件 {{plugin}} 注册 · {{key}}",
history: "执行记录",
historyFor: "查看 {{name}} 的执行记录",
historyTitle: "{{name}} · 执行记录",