From cd69a255dcb4837165cfefe12147a0d8b6695b8b Mon Sep 17 00:00:00 2001 From: bling-yshs <41812674+bling-yshs@users.noreply.github.com> Date: Tue, 16 Sep 2025 10:25:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=80=9A=E7=9F=A5->=E5=85=A8=E5=B1=80?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E8=AE=BE=E7=BD=AE->=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=96=B0=E9=80=89=E9=A1=B9=E2=80=9C=E6=89=8B=E5=8A=A8=E5=81=9C?= =?UTF-8?q?=E6=AD=A2=E6=97=B6=E4=B8=8D=E9=80=9A=E7=9F=A5=E2=80=9D=EF=BC=8C?= =?UTF-8?q?=E5=85=81=E8=AE=B8=E7=94=A8=E6=88=B7=E9=80=89=E6=8B=A9=E6=89=8B?= =?UTF-8?q?=E5=8A=A8=E5=81=9C=E6=AD=A2=E6=97=B6=E6=98=AF=E5=90=A6=E5=8F=91?= =?UTF-8?q?=E9=80=81=E9=80=9A=E7=9F=A5=20(#2195)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Core/Script/CancellationContext.cs | 11 +++++++++++ BetterGenshinImpact/Service/ScriptService.cs | 5 ++++- .../ViewModel/Pages/HotKeyPageViewModel.cs | 2 +- .../ViewModel/Pages/OneDragonFlowViewModel.cs | 10 ++++++++-- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/BetterGenshinImpact/Core/Script/CancellationContext.cs b/BetterGenshinImpact/Core/Script/CancellationContext.cs index 8f7b1986..782e7f57 100644 --- a/BetterGenshinImpact/Core/Script/CancellationContext.cs +++ b/BetterGenshinImpact/Core/Script/CancellationContext.cs @@ -6,15 +6,26 @@ namespace BetterGenshinImpact.Core.Script; public class CancellationContext : Singleton { 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) diff --git a/BetterGenshinImpact/Service/ScriptService.cs b/BetterGenshinImpact/Service/ScriptService.cs index c80c7dee..c8986dc0 100644 --- a/BetterGenshinImpact/Service/ScriptService.cs +++ b/BetterGenshinImpact/Service/ScriptService.cs @@ -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) diff --git a/BetterGenshinImpact/ViewModel/Pages/HotKeyPageViewModel.cs b/BetterGenshinImpact/ViewModel/Pages/HotKeyPageViewModel.cs index 7ed038bd..7cf2ab22 100644 --- a/BetterGenshinImpact/ViewModel/Pages/HotKeyPageViewModel.cs +++ b/BetterGenshinImpact/ViewModel/Pages/HotKeyPageViewModel.cs @@ -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( "暂停当前脚本/独立任务", diff --git a/BetterGenshinImpact/ViewModel/Pages/OneDragonFlowViewModel.cs b/BetterGenshinImpact/ViewModel/Pages/OneDragonFlowViewModel.cs index 47e2f46f..91ce8d79 100644 --- a/BetterGenshinImpact/ViewModel/Pages/OneDragonFlowViewModel.cs +++ b/BetterGenshinImpact/ViewModel/Pages/OneDragonFlowViewModel.cs @@ -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("一条龙和配置组任务结束"); // 执行完成后操作