mirror of
https://github.com/babalae/better-genshin-impact.git
synced 2026-05-25 10:05:49 +08:00
* 新增图片作为email附件发送功能 * feat(notification): 为 WebhookNotifier 添加 send_to 功能 - 在 WebhookNotifier 类中添加 send_to 属性 - 修改 TransformData 方法,增加 send_to 字段 - 在 NotificationConfig 中添加 webhook_endpoint 和 websocket_endpoint 属性 * refactor(WebhookNotifier): 添加 send_to 属性并调整访问修饰符 * refactor(notification): 重构 WebhookNotifier 并更新 NotificationConfig - 在 NotificationConfig 中添加 WebhookSendTo 属性 - 重构 WebhookNotifier 构造函数,使用 NotificationConfig 对象进行初始化 - 更新 WebhookNotifier 发送逻辑,使用新的配置属性 * feat: add webhook ui. * refactor(WebhookNotifier): 重构 TransformData 方法以优化数据结构- 将 notification_data 的内容合并到外层字典,以便于 webhook 接收端获取数据- 新增 event、result、timestamp 等字段,使数据结构 * fix(WebSocketNotifier): 添加消息发送后关闭连接的功能 - 在 SendAsync 方法中添加了 CloseAsync() 调用,确保消息发送后关闭 WebSocket 连接 - 此修改解决了消息发送后未关闭连接的问题,提高了资源利用率和系统稳定性 * fix: implement unified webhook ui * fix: typos. * 优化通知前端显示 * feat(notification): 添加钉钉 Webhook 通知支持 - 实现了钉钉 Webhook 通知的发送功能 - 在通知配置中添加了钉钉 Webhook URL 和密钥的设置选项 - 在通知服务中集成了钉钉通知的初始化和注册 - 优化了 WebhookNotifier 类的代码结构 * 新增钉钉通知ui Signed-off-by: DR-lin-eng <@DR-lin-eng> * 修正图标 Signed-off-by: DR-lin-eng <@DR-lin-eng> --------- Signed-off-by: DR-lin-eng <@DR-lin-eng> Co-authored-by: DR-lin-eng <@DR-lin-eng> Co-authored-by: 秋云 <physligl@gmail.com> Co-authored-by: DR-lin-eng <52230594+DR-lin-eng@users.noreply.github.com> Co-authored-by: 辉鸭蛋 <huiyadanli@gmail.com>
239 lines
6.0 KiB
C#
239 lines
6.0 KiB
C#
using System.Threading.Tasks;
|
||
using BetterGenshinImpact.Core.Config;
|
||
using BetterGenshinImpact.Service.Interface;
|
||
using BetterGenshinImpact.Service.Notification;
|
||
using BetterGenshinImpact.Service.Notifier;
|
||
using CommunityToolkit.Mvvm.ComponentModel;
|
||
using CommunityToolkit.Mvvm.Input;
|
||
using Wpf.Ui.Violeta.Controls;
|
||
|
||
namespace BetterGenshinImpact.ViewModel.Pages;
|
||
|
||
public partial class NotificationSettingsPageViewModel : ObservableObject, IViewModel
|
||
{
|
||
private readonly NotificationService _notificationService;
|
||
|
||
[ObservableProperty] private string _barkStatus = string.Empty;
|
||
|
||
/// <summary>
|
||
/// 钉钉通知测试状态
|
||
/// </summary>
|
||
[ObservableProperty] private string _dingDingStatus = string.Empty;
|
||
|
||
[ObservableProperty] private string _emailStatus = string.Empty;
|
||
|
||
[ObservableProperty] private string _feishuStatus = string.Empty;
|
||
|
||
[ObservableProperty] private bool _isLoading;
|
||
|
||
[ObservableProperty] private string _telegramStatus = string.Empty;
|
||
|
||
[ObservableProperty] private string _webhookStatus = string.Empty;
|
||
|
||
[ObservableProperty] private string _webSocketStatus = string.Empty;
|
||
|
||
[ObservableProperty] private string _windowsUwpStatus = string.Empty;
|
||
|
||
[ObservableProperty] private string _workWeixinStatus = string.Empty;
|
||
|
||
[ObservableProperty] private string _xxtuiStatus = string.Empty;
|
||
|
||
public NotificationSettingsPageViewModel(IConfigService configService, NotificationService notificationService)
|
||
{
|
||
Config = configService.Get();
|
||
_notificationService = notificationService;
|
||
}
|
||
|
||
public AllConfig Config { get; set; }
|
||
|
||
[RelayCommand]
|
||
private async Task OnTestWebhook()
|
||
{
|
||
IsLoading = true;
|
||
WebhookStatus = string.Empty;
|
||
|
||
var res = await _notificationService.TestNotifierAsync<WebhookNotifier>();
|
||
|
||
WebhookStatus = res.Message;
|
||
|
||
// 添加Toast提示
|
||
if (res.IsSuccess)
|
||
Toast.Success(res.Message);
|
||
else
|
||
Toast.Error(res.Message);
|
||
|
||
IsLoading = false;
|
||
}
|
||
|
||
[RelayCommand]
|
||
private async Task OnTestWindowsUwpNotification()
|
||
{
|
||
IsLoading = true;
|
||
WindowsUwpStatus = string.Empty;
|
||
|
||
var res = await _notificationService.TestNotifierAsync<WindowsUwpNotifier>();
|
||
|
||
WindowsUwpStatus = res.Message;
|
||
|
||
// 添加Toast提示
|
||
if (res.IsSuccess)
|
||
Toast.Success(res.Message);
|
||
else
|
||
Toast.Error(res.Message);
|
||
|
||
IsLoading = false;
|
||
}
|
||
|
||
[RelayCommand]
|
||
private async Task OnTestFeishuNotification()
|
||
{
|
||
IsLoading = true;
|
||
FeishuStatus = string.Empty;
|
||
|
||
var res = await _notificationService.TestNotifierAsync<FeishuNotifier>();
|
||
|
||
FeishuStatus = res.Message;
|
||
|
||
// 添加Toast提示
|
||
if (res.IsSuccess)
|
||
Toast.Success(res.Message);
|
||
else
|
||
Toast.Error(res.Message);
|
||
|
||
IsLoading = false;
|
||
}
|
||
|
||
[RelayCommand]
|
||
private async Task OnTestWorkWeixinNotification()
|
||
{
|
||
IsLoading = true;
|
||
WorkWeixinStatus = string.Empty;
|
||
|
||
var res = await _notificationService.TestNotifierAsync<WorkWeixinNotifier>();
|
||
|
||
WorkWeixinStatus = res.Message;
|
||
|
||
// 添加Toast提示
|
||
if (res.IsSuccess)
|
||
Toast.Success(res.Message);
|
||
else
|
||
Toast.Error(res.Message);
|
||
|
||
IsLoading = false;
|
||
}
|
||
|
||
[RelayCommand]
|
||
private async Task OnTestWebSocketNotification()
|
||
{
|
||
IsLoading = true;
|
||
WebSocketStatus = string.Empty;
|
||
|
||
var res = await _notificationService.TestNotifierAsync<WebSocketNotifier>();
|
||
|
||
WebSocketStatus = res.Message;
|
||
|
||
// 添加Toast提示
|
||
if (res.IsSuccess)
|
||
Toast.Success(res.Message);
|
||
else
|
||
Toast.Error(res.Message);
|
||
|
||
IsLoading = false;
|
||
}
|
||
|
||
[RelayCommand]
|
||
private async Task OnTestEmailNotification()
|
||
{
|
||
IsLoading = true;
|
||
EmailStatus = string.Empty;
|
||
|
||
var res = await _notificationService.TestNotifierAsync<EmailNotifier>();
|
||
|
||
EmailStatus = res.Message;
|
||
|
||
// 添加Toast提示
|
||
if (res.IsSuccess)
|
||
Toast.Success(res.Message);
|
||
else
|
||
Toast.Error(res.Message);
|
||
|
||
IsLoading = false;
|
||
}
|
||
|
||
[RelayCommand]
|
||
private async Task OnTestBarkNotification()
|
||
{
|
||
IsLoading = true;
|
||
BarkStatus = string.Empty;
|
||
|
||
var res = await _notificationService.TestNotifierAsync<BarkNotifier>();
|
||
|
||
BarkStatus = res.Message;
|
||
|
||
// 添加Toast提示
|
||
if (res.IsSuccess)
|
||
Toast.Success(res.Message);
|
||
else
|
||
Toast.Error(res.Message);
|
||
|
||
IsLoading = false;
|
||
}
|
||
|
||
[RelayCommand]
|
||
private async Task OnTestTelegramNotification()
|
||
{
|
||
IsLoading = true;
|
||
TelegramStatus = string.Empty;
|
||
|
||
var res = await _notificationService.TestNotifierAsync<TelegramNotifier>();
|
||
|
||
TelegramStatus = res.Message;
|
||
|
||
// 添加Toast提示
|
||
if (res.IsSuccess)
|
||
Toast.Success(res.Message);
|
||
else
|
||
Toast.Error(res.Message);
|
||
|
||
IsLoading = false;
|
||
}
|
||
|
||
[RelayCommand]
|
||
private async Task OnTestXxtuiNotification()
|
||
{
|
||
IsLoading = true;
|
||
XxtuiStatus = string.Empty;
|
||
|
||
var res = await _notificationService.TestNotifierAsync<XxtuiNotifier>();
|
||
|
||
XxtuiStatus = res.Message;
|
||
|
||
// 添加Toast提示
|
||
if (res.IsSuccess)
|
||
Toast.Success(res.Message);
|
||
else
|
||
Toast.Error(res.Message);
|
||
|
||
IsLoading = false;
|
||
}
|
||
|
||
|
||
[RelayCommand]
|
||
private async Task OnTestDingDingWebhookNotification()
|
||
{
|
||
IsLoading = true;
|
||
DingDingStatus = string.Empty; // 使用专门的状态变量,与xxtui保持一致
|
||
|
||
var res = await _notificationService.TestNotifierAsync<DingDingWebhook>();
|
||
|
||
DingDingStatus = res.Message;
|
||
|
||
// 添加Toast提示
|
||
if (res.IsSuccess)
|
||
Toast.Success(res.Message);
|
||
else
|
||
Toast.Error(res.Message);
|
||
|
||
IsLoading = false;
|
||
}
|
||
} |