mirror of
https://github.com/babalae/better-genshin-impact.git
synced 2026-05-21 09:45:48 +08:00
Add notification to task
This commit is contained in:
@@ -8,6 +8,7 @@ using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Exception;
|
||||
using BetterGenshinImpact.GameTask.AutoPick.Assets;
|
||||
using BetterGenshinImpact.GameTask.Common;
|
||||
using BetterGenshinImpact.GameTask.Model.Enum;
|
||||
using BetterGenshinImpact.Service.Notification;
|
||||
using BetterGenshinImpact.Helpers;
|
||||
using BetterGenshinImpact.View.Drawable;
|
||||
using BetterGenshinImpact.ViewModel.Pages;
|
||||
@@ -55,6 +56,17 @@ public class AutoDomainTask
|
||||
_config = TaskContext.Instance().Config.AutoDomainConfig;
|
||||
}
|
||||
|
||||
private void Notify(NotificationAction action, NotificationConclusion? conclusion)
|
||||
{
|
||||
NotificationManager.Instance().NotifyObservers(new TaskNotificationData
|
||||
{
|
||||
Event = NotificationEvent.Domain,
|
||||
Action = action,
|
||||
Conclusion = conclusion,
|
||||
Task = _taskParam
|
||||
});
|
||||
}
|
||||
|
||||
public async void Start()
|
||||
{
|
||||
var hasLock = false;
|
||||
@@ -68,6 +80,7 @@ public class AutoDomainTask
|
||||
}
|
||||
|
||||
Init();
|
||||
Notify(NotificationAction.Started, null);
|
||||
var combatScenes = new CombatScenes().InitializeTeam(GetContentFromDispatcher());
|
||||
|
||||
// 前置进入秘境
|
||||
@@ -111,19 +124,22 @@ public class AutoDomainTask
|
||||
{
|
||||
Logger.LogInformation("体力已经耗尽,结束自动秘境");
|
||||
}
|
||||
|
||||
Notify(NotificationAction.Completed, NotificationConclusion.Success);
|
||||
break;
|
||||
}
|
||||
Notify(NotificationAction.Progress, null);
|
||||
}
|
||||
}
|
||||
catch (NormalEndException e)
|
||||
{
|
||||
Logger.LogInformation("自动秘境中断:" + e.Message);
|
||||
Notify(NotificationAction.Completed, NotificationConclusion.Cancelled);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogError(e.Message);
|
||||
Logger.LogDebug(e.StackTrace);
|
||||
Notify(NotificationAction.Completed, NotificationConclusion.Failure);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using BetterGenshinImpact.Core.Recognition.OpenCv;
|
||||
using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Exception;
|
||||
using BetterGenshinImpact.GameTask.Common;
|
||||
using BetterGenshinImpact.Service.Notification;
|
||||
using BetterGenshinImpact.View.Drawable;
|
||||
using BetterGenshinImpact.ViewModel.Pages;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -52,6 +53,16 @@ public class Duel
|
||||
|
||||
private int _keqingECount = 0;
|
||||
|
||||
private static void Notify(NotificationAction action, NotificationConclusion? conclusion)
|
||||
{
|
||||
NotificationManager.Instance().NotifyObservers(new TaskNotificationData
|
||||
{
|
||||
Event = NotificationEvent.GeniusInvocation,
|
||||
Action = action,
|
||||
Conclusion = conclusion
|
||||
});
|
||||
}
|
||||
|
||||
public async Task RunAsync(GeniusInvokationTaskParam taskParam)
|
||||
{
|
||||
await Task.Run(() => { Run(taskParam); });
|
||||
@@ -73,6 +84,7 @@ public class Duel
|
||||
LogScreenResolution();
|
||||
_logger.LogInformation("========================================");
|
||||
_logger.LogInformation("→ {Text}", "全自动七圣召唤,启动!");
|
||||
Notify(NotificationAction.Started, null);
|
||||
|
||||
GeniusInvokationControl.GetInstance().Init(taskParam);
|
||||
SystemControl.ActivateWindow();
|
||||
@@ -299,11 +311,13 @@ public class Duel
|
||||
catch (TaskCanceledException ex)
|
||||
{
|
||||
_logger.LogInformation(ex.Message);
|
||||
Notify(NotificationAction.Completed, NotificationConclusion.Cancelled);
|
||||
}
|
||||
catch (NormalEndException ex)
|
||||
{
|
||||
_logger.LogInformation(ex.Message);
|
||||
_logger.LogInformation("对局结束");
|
||||
Notify(NotificationAction.Completed, NotificationConclusion.Success);
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
@@ -313,6 +327,7 @@ public class Duel
|
||||
{
|
||||
_logger.LogError(ex.StackTrace);
|
||||
}
|
||||
Notify(NotificationAction.Completed, NotificationConclusion.Failure);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user