rft: rename ExternalNotificationDataContext to ExternalNotificationSettings

This commit is contained in:
status102
2024-11-18 17:02:21 +08:00
parent 37bf2841b4
commit 6435d700a9
9 changed files with 22 additions and 22 deletions

View File

@@ -29,14 +29,14 @@ namespace MaaWpfGui.Services.Notification
public async Task<bool> SendAsync(string title, string content)
{
var sendKey = SettingsViewModel.ExternalNotificationDataContext.BarkSendKey;
var sendKey = SettingsViewModel.ExternalNotificationSettings.BarkSendKey;
if (string.IsNullOrWhiteSpace(sendKey))
{
_logger.Warning("Failed to send Bark notification, Bark send key is empty");
return false;
}
var apiBase = SettingsViewModel.ExternalNotificationDataContext.BarkServer;
var apiBase = SettingsViewModel.ExternalNotificationSettings.BarkServer;
if (string.IsNullOrWhiteSpace(apiBase))
{
_logger.Warning("Failed to send Bark notification, Bark server address is empty");

View File

@@ -32,8 +32,8 @@ public class DiscordNotificationProvider(IHttpService httpService) : IExternalNo
public async Task<bool> SendAsync(string title, string content)
{
var botToken = SettingsViewModel.ExternalNotificationDataContext.DiscordBotToken;
var userId = SettingsViewModel.ExternalNotificationDataContext.DiscordUserId;
var botToken = SettingsViewModel.ExternalNotificationSettings.DiscordBotToken;
var userId = SettingsViewModel.ExternalNotificationSettings.DiscordUserId;
var channelId = await CreateDmChannel(botToken, userId);

View File

@@ -28,7 +28,7 @@ namespace MaaWpfGui.Services.Notification
private static async Task SendAsync(string title, string content, bool isTest = false)
{
var enabledProviders = SettingsViewModel.ExternalNotificationDataContext.EnabledExternalNotificationProviderList;
var enabledProviders = SettingsViewModel.ExternalNotificationSettings.EnabledExternalNotificationProviderList;
foreach (var enabledProvider in enabledProviders)
{

View File

@@ -37,10 +37,10 @@ namespace MaaWpfGui.Services.Notification
public async Task<bool> SendAsync(string title, string content)
{
var server = SettingsViewModel.ExternalNotificationDataContext.QmsgServer;
var key = SettingsViewModel.ExternalNotificationDataContext.QmsgKey;
var receiveUser = SettingsViewModel.ExternalNotificationDataContext.QmsgUser;
var sendBot = SettingsViewModel.ExternalNotificationDataContext.QmsgBot;
var server = SettingsViewModel.ExternalNotificationSettings.QmsgServer;
var key = SettingsViewModel.ExternalNotificationSettings.QmsgKey;
var receiveUser = SettingsViewModel.ExternalNotificationSettings.QmsgUser;
var sendBot = SettingsViewModel.ExternalNotificationSettings.QmsgBot;
var uri = $"{server}/jsend/{key}";

View File

@@ -45,7 +45,7 @@ namespace MaaWpfGui.Services.Notification
title = title[..32]; // 截取前 32 个字符
}
var sendKey = SettingsViewModel.ExternalNotificationDataContext.ServerChanSendKey;
var sendKey = SettingsViewModel.ExternalNotificationSettings.ServerChanSendKey;
try
{

View File

@@ -30,12 +30,12 @@ namespace MaaWpfGui.Services.Notification
public async Task<bool> SendAsync(string title, string content)
{
var smtpServer = SettingsViewModel.ExternalNotificationDataContext.SmtpServer;
var smtpPortValid = int.TryParse(SettingsViewModel.ExternalNotificationDataContext.SmtpPort, out var smtpPort);
var smtpUser = SettingsViewModel.ExternalNotificationDataContext.SmtpUser;
var smtpPassword = SettingsViewModel.ExternalNotificationDataContext.SmtpPassword;
var smtpUseSsl = SettingsViewModel.ExternalNotificationDataContext.SmtpUseSsl;
var smtpRequiresAuthentication = SettingsViewModel.ExternalNotificationDataContext.SmtpRequireAuthentication;
var smtpServer = SettingsViewModel.ExternalNotificationSettings.SmtpServer;
var smtpPortValid = int.TryParse(SettingsViewModel.ExternalNotificationSettings.SmtpPort, out var smtpPort);
var smtpUser = SettingsViewModel.ExternalNotificationSettings.SmtpUser;
var smtpPassword = SettingsViewModel.ExternalNotificationSettings.SmtpPassword;
var smtpUseSsl = SettingsViewModel.ExternalNotificationSettings.SmtpUseSsl;
var smtpRequiresAuthentication = SettingsViewModel.ExternalNotificationSettings.SmtpRequireAuthentication;
if (string.IsNullOrEmpty(smtpServer) || smtpPortValid is false)
{
@@ -56,8 +56,8 @@ namespace MaaWpfGui.Services.Notification
Email.DefaultRenderer = new LiquidRenderer(new OptionsWrapper<LiquidRendererOptions>(new LiquidRendererOptions()));
var emailFrom = SettingsViewModel.ExternalNotificationDataContext.SmtpFrom;
var emailTo = SettingsViewModel.ExternalNotificationDataContext.SmtpTo;
var emailFrom = SettingsViewModel.ExternalNotificationSettings.SmtpFrom;
var emailTo = SettingsViewModel.ExternalNotificationSettings.SmtpTo;
title = Regex.Replace(title, "\r(?!\n)", "\r\n");
content = Regex.Replace(content, "\r(?!\n)", "\r\n");

View File

@@ -29,8 +29,8 @@ public class TelegramNotificationProvider(IHttpService httpService) : IExternalN
public async Task<bool> SendAsync(string title, string content)
{
var botToken = SettingsViewModel.ExternalNotificationDataContext.TelegramBotToken;
var chatId = SettingsViewModel.ExternalNotificationDataContext.TelegramChatId;
var botToken = SettingsViewModel.ExternalNotificationSettings.TelegramBotToken;
var chatId = SettingsViewModel.ExternalNotificationSettings.TelegramChatId;
var uri = $"https://api.telegram.org/bot{botToken}/sendMessage";

View File

@@ -115,7 +115,7 @@ namespace MaaWpfGui.ViewModels.UI
/// <summary>
/// Gets 外部通知model
/// </summary>
public static ExternalNotificationSettingsUserControlModel ExternalNotificationDataContext { get; } = new();
public static ExternalNotificationSettingsUserControlModel ExternalNotificationSettings { get; } = new();
#endregion Model

View File

@@ -84,7 +84,7 @@
<settingsViews:ExternalNotificationSettingsUserControl
Margin="0,20"
HorizontalAlignment="Center"
DataContext="{Binding ExternalNotificationDataContext}" />
DataContext="{Binding ExternalNotificationSettings}" />
<hc:Divider Content="{Binding ListTitle[9]}" />
<userControl:HotKeySettingsUserControl Margin="0,20" HorizontalAlignment="Center" />