feat: 优化触发器配置体验
- 根据触发器类型动态展示对应配置区域,减少无关字段干扰。 - 将单次、每日、每周、每月和生效时间范围改为日期选择器与时分秒下拉选择,避免手动输入时间格式。 - 为单次执行增加延后执行快捷设置,支持常用快捷按钮和自定义分钟、小时、天后执行。 - 移除开机自启设置、注册表写入逻辑和相关配置字段,降低对用户系统的影响。 - 同步优化部分任务状态、触发摘要和设置界面文案。
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
using Microsoft.Win32;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
@@ -54,8 +53,9 @@ public sealed class StateStore
|
||||
{
|
||||
var task = new ScheduledTask
|
||||
{
|
||||
IsEnabled = false,
|
||||
Name = "OmniNotify 连通性测试",
|
||||
Description = "可克隆此任务作为新消息模板。",
|
||||
Description = "可克隆此任务作为新消息模板。默认禁用,避免首次启动自动发送。",
|
||||
Channel = "default",
|
||||
Title = "OmniScheduler 测试",
|
||||
Body = "来自 {TaskName} 的测试消息,触发时间 {CurrentTime}。"
|
||||
@@ -138,7 +138,7 @@ public sealed class NotifyClient
|
||||
private static string BuildErrorMessage(string response, string fallback)
|
||||
=> response.Contains("IllegalChannel", StringComparison.OrdinalIgnoreCase)
|
||||
? "ERROR: IllegalChannel,请检查频道名配置"
|
||||
: $"发送失败: {fallback}";
|
||||
: $"发送失败 {fallback}";
|
||||
}
|
||||
|
||||
public sealed class SchedulerService
|
||||
@@ -180,7 +180,7 @@ public sealed class SchedulerService
|
||||
|
||||
public async Task FireNowAsync(ScheduledTask task)
|
||||
{
|
||||
await ExecuteAsync(task, "Manual");
|
||||
await ExecuteAsync(task, "手动触发");
|
||||
task.NextRunAt = FindNext(task, DateTime.Now);
|
||||
}
|
||||
|
||||
@@ -214,7 +214,7 @@ public sealed class SchedulerService
|
||||
{
|
||||
task.LastRunAt = DateTime.Now;
|
||||
var log = await _client.SendAsync(task, triggerType, _state.Settings.OmniNotifyUrl);
|
||||
task.LastStatus = log.Level == "INFO" ? "Success" : "Failed";
|
||||
task.LastStatus = log.Level == "INFO" ? "成功" : "失败";
|
||||
_logSink(log);
|
||||
}
|
||||
|
||||
@@ -223,7 +223,7 @@ public sealed class SchedulerService
|
||||
var trigger = task.Triggers
|
||||
.OrderBy(t => Math.Abs(((NextRunCalculator.NextRun(t, DateTime.Now.AddDays(-1)) ?? dueAt) - dueAt).TotalSeconds))
|
||||
.FirstOrDefault();
|
||||
return trigger?.Kind.ToString() ?? "Scheduled";
|
||||
return trigger?.Summary ?? "计划触发";
|
||||
}
|
||||
|
||||
private static DateTime? FindNext(ScheduledTask task, DateTime from)
|
||||
@@ -294,7 +294,12 @@ public static class NextRunCalculator
|
||||
_ => TimeSpan.FromMinutes(trigger.IntervalValue)
|
||||
};
|
||||
|
||||
var start = trigger.StartsAt ?? DateTime.Now;
|
||||
if (!trigger.StartsAt.HasValue)
|
||||
{
|
||||
return from.Add(interval);
|
||||
}
|
||||
|
||||
var start = trigger.StartsAt.Value;
|
||||
if (from <= start)
|
||||
{
|
||||
return start;
|
||||
@@ -424,26 +429,3 @@ public static class NextRunCalculator
|
||||
return date.Day;
|
||||
}
|
||||
}
|
||||
|
||||
public static class StartupRegistration
|
||||
{
|
||||
private const string RunKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run";
|
||||
|
||||
public static void Apply(bool enabled)
|
||||
{
|
||||
using var key = Registry.CurrentUser.OpenSubKey(RunKey, true);
|
||||
if (key is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (enabled)
|
||||
{
|
||||
key.SetValue("OmniScheduler", $"\"{Environment.ProcessPath}\" --tray");
|
||||
}
|
||||
else
|
||||
{
|
||||
key.DeleteValue("OmniScheduler", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user