新增工具/组合随软件启动自动运行功能
- ToolItem 模型新增 AutoRunOnStart 属性,持久化到配置文件 - App.OnStartup 启动后自动执行标记为自启动的工具/组合(间隔500ms) - 工具编辑窗口和组合编辑窗口新增「随软件启动自动运行」CheckBox - 主界面工具卡片左上角 Rocket 角标标识已启用自启的项目
This commit is contained in:
@@ -35,6 +35,9 @@ public partial class GroupEditViewModel : ObservableObject
|
||||
[ObservableProperty]
|
||||
private IconProvider.IconOption? _selectedIcon;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _autoRunOnStart;
|
||||
|
||||
/// <summary>
|
||||
/// 可供勾选的普通工具列表(IsGroup == false)
|
||||
/// </summary>
|
||||
@@ -85,6 +88,7 @@ public partial class GroupEditViewModel : ObservableObject
|
||||
Name = groupToEdit.Name;
|
||||
HotKey = groupToEdit.HotKey;
|
||||
SelectedCategory = Categories.FirstOrDefault(c => c.Id == groupToEdit.CategoryId);
|
||||
AutoRunOnStart = groupToEdit.AutoRunOnStart;
|
||||
|
||||
if (!string.IsNullOrEmpty(groupToEdit.IconCode))
|
||||
{
|
||||
@@ -119,6 +123,7 @@ public partial class GroupEditViewModel : ObservableObject
|
||||
_editingGroup.CategoryId = SelectedCategory?.Id ?? string.Empty;
|
||||
_editingGroup.SubToolIds = selectedIds;
|
||||
_editingGroup.IsValid = true;
|
||||
_editingGroup.AutoRunOnStart = AutoRunOnStart;
|
||||
_logService.Info($"已更新组合: {Name.Trim()}(包含 {selectedIds.Count} 个工具)");
|
||||
}
|
||||
else
|
||||
@@ -131,7 +136,8 @@ public partial class GroupEditViewModel : ObservableObject
|
||||
CategoryId = SelectedCategory?.Id ?? string.Empty,
|
||||
IsGroup = true,
|
||||
SubToolIds = selectedIds,
|
||||
IsValid = true
|
||||
IsValid = true,
|
||||
AutoRunOnStart = AutoRunOnStart
|
||||
});
|
||||
_logService.Info($"已添加组合: {Name.Trim()}(包含 {selectedIds.Count} 个工具)");
|
||||
}
|
||||
|
||||
@@ -257,6 +257,24 @@ public partial class MainViewModel : ObservableObject
|
||||
RefreshData();
|
||||
}
|
||||
|
||||
// ───────────────────────────── 自动运行 ─────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// 启动时自动运行标记为 AutoRunOnStart 的工具和组合
|
||||
/// </summary>
|
||||
public async Task ExecuteAutoRunToolsAsync()
|
||||
{
|
||||
var autoTools = _dataService.Config.Tools.Where(t => t.AutoRunOnStart).ToList();
|
||||
if (autoTools.Count == 0) return;
|
||||
|
||||
_logService.Info($"正在启动 {autoTools.Count} 个自启动工具...");
|
||||
foreach (var tool in autoTools)
|
||||
{
|
||||
await _processService.ExecuteAsync(tool);
|
||||
await Task.Delay(500);
|
||||
}
|
||||
}
|
||||
|
||||
// ───────────────────────────── 数据刷新 ─────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -43,6 +43,9 @@ public partial class ToolEditViewModel : ObservableObject
|
||||
[ObservableProperty]
|
||||
private IconProvider.IconOption? _selectedIcon;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _autoRunOnStart;
|
||||
|
||||
/// <summary>
|
||||
/// 分类下拉列表
|
||||
/// </summary>
|
||||
@@ -87,6 +90,7 @@ public partial class ToolEditViewModel : ObservableObject
|
||||
Arguments = toolToEdit.Arguments;
|
||||
HotKey = toolToEdit.HotKey;
|
||||
SelectedCategory = Categories.FirstOrDefault(c => c.Id == toolToEdit.CategoryId);
|
||||
AutoRunOnStart = toolToEdit.AutoRunOnStart;
|
||||
|
||||
if (!string.IsNullOrEmpty(toolToEdit.IconCode))
|
||||
{
|
||||
@@ -149,6 +153,7 @@ public partial class ToolEditViewModel : ObservableObject
|
||||
_editingTool.HotKey = HotKey.Trim();
|
||||
_editingTool.CategoryId = SelectedCategory?.Id ?? string.Empty;
|
||||
_editingTool.IsValid = IsExecutablePathValid(ExecutablePath.Trim());
|
||||
_editingTool.AutoRunOnStart = AutoRunOnStart;
|
||||
|
||||
_logService.Info($"已更新工具: {Name.Trim()}");
|
||||
}
|
||||
@@ -163,7 +168,8 @@ public partial class ToolEditViewModel : ObservableObject
|
||||
Arguments = Arguments.Trim(),
|
||||
HotKey = HotKey.Trim(),
|
||||
CategoryId = SelectedCategory?.Id ?? string.Empty,
|
||||
IsValid = IsExecutablePathValid(ExecutablePath.Trim())
|
||||
IsValid = IsExecutablePathValid(ExecutablePath.Trim()),
|
||||
AutoRunOnStart = AutoRunOnStart
|
||||
};
|
||||
|
||||
_dataService.Config.Tools.Add(newTool);
|
||||
|
||||
Reference in New Issue
Block a user