mirror of
https://github.com/babalae/better-genshin-impact.git
synced 2026-03-15 07:43:20 +08:00
feat: 通知->全局通知设置->添加新选项“手动停止时不通知”,允许用户选择手动停止时是否发送通知 (#2195)
This commit is contained in:
@@ -6,15 +6,26 @@ namespace BetterGenshinImpact.Core.Script;
|
||||
public class CancellationContext : Singleton<CancellationContext>
|
||||
{
|
||||
public CancellationTokenSource Cts { get; set; } = new();
|
||||
public bool IsManualStop { get; private set; }
|
||||
|
||||
private bool disposed;
|
||||
|
||||
public void Set()
|
||||
{
|
||||
Cts = new CancellationTokenSource();
|
||||
IsManualStop = false;
|
||||
disposed = false;
|
||||
}
|
||||
|
||||
public void ManualCancel()
|
||||
{
|
||||
if (!disposed)
|
||||
{
|
||||
IsManualStop = true;
|
||||
Cts.Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
public void Cancel()
|
||||
{
|
||||
if (!disposed)
|
||||
|
||||
@@ -429,7 +429,10 @@ public partial class ScriptService : IScriptService
|
||||
|
||||
if (!fisrt&&!RunnerContext.Instance.IsPreExecution)
|
||||
{
|
||||
Notify.Event(NotificationEvent.GroupEnd).Success($"配置组{groupName}结束");
|
||||
if (CancellationContext.Instance.IsManualStop is false)
|
||||
{
|
||||
Notify.Event(NotificationEvent.GroupEnd).Success($"配置组{groupName}结束");
|
||||
}
|
||||
}
|
||||
|
||||
if (taskProgress != null)
|
||||
|
||||
@@ -218,7 +218,7 @@ public partial class HotKeyPageViewModel : ObservableObject, IViewModel
|
||||
nameof(Config.HotKeyConfig.CancelTaskHotkey),
|
||||
Config.HotKeyConfig.CancelTaskHotkey,
|
||||
Config.HotKeyConfig.CancelTaskHotkeyType,
|
||||
(_, _) => { CancellationContext.Instance.Cancel(); }
|
||||
(_, _) => { CancellationContext.Instance.ManualCancel(); }
|
||||
));
|
||||
systemDirectory.Children.Add(new HotKeySettingModel(
|
||||
"暂停当前脚本/独立任务",
|
||||
|
||||
@@ -665,7 +665,10 @@ public partial class OneDragonFlowViewModel : ViewModel
|
||||
if (CancellationContext.Instance.Cts.IsCancellationRequested)
|
||||
{
|
||||
_logger.LogInformation("任务被取消,退出执行");
|
||||
Notify.Event(NotificationEvent.DragonEnd).Success("一条龙和配置组任务结束");
|
||||
if (CancellationContext.Instance.IsManualStop is false)
|
||||
{
|
||||
Notify.Event(NotificationEvent.DragonEnd).Success("一条龙和配置组任务结束");
|
||||
}
|
||||
return; // 后续的检查任务也不执行
|
||||
}
|
||||
}
|
||||
@@ -676,7 +679,10 @@ public partial class OneDragonFlowViewModel : ViewModel
|
||||
{
|
||||
await new CheckRewardsTask().Start(CancellationContext.Instance.Cts.Token);
|
||||
await Task.Delay(500);
|
||||
Notify.Event(NotificationEvent.DragonEnd).Success("一条龙和配置组任务结束");
|
||||
if (CancellationContext.Instance.IsManualStop is false)
|
||||
{
|
||||
Notify.Event(NotificationEvent.DragonEnd).Success("一条龙和配置组任务结束");
|
||||
}
|
||||
_logger.LogInformation("一条龙和配置组任务结束");
|
||||
|
||||
// 执行完成后操作
|
||||
|
||||
Reference in New Issue
Block a user