mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-19 02:23:01 +08:00
feat: 外部通知 (ServerChan 和 SMTP) (#6332)
fix #6257 接入外部通知,SMTP 和 ServerChan ~~还没有做哪些通知会往外部通知发。~~ 仅所有任务完成后会发送通知。 发通知:`public static async Task ExternalNotificationService.SendAsync(string title, string content);`
This commit is contained in:
@@ -168,6 +168,17 @@ namespace MaaWpfGui.Constants
|
||||
public const string DropsItemName = "MainFunction.Drops.ItemName";
|
||||
public const string DropsQuantity = "MainFunction.Drops.Quantity";
|
||||
|
||||
public const string ExternalNotificationEnabled = "ExternalNotification.Enabled";
|
||||
public const string ExternalNotificationSmtpServer = "ExternalNotification.Smtp.Server";
|
||||
public const string ExternalNotificationSmtpPort = "ExternalNotification.Smtp.Port";
|
||||
public const string ExternalNotificationSmtpUser = "ExternalNotification.Smtp.User";
|
||||
public const string ExternalNotificationSmtpPassword = "ExternalNotification.Smtp.Password";
|
||||
public const string ExternalNotificationSmtpUseSsl = "ExternalNotification.Smtp.UseSsl";
|
||||
public const string ExternalNotificationSmtpRequiresAuthentication = "ExternalNotification.Smtp.RequiresAuthentication";
|
||||
public const string ExternalNotificationSmtpFrom = "ExternalNotification.Smtp.From";
|
||||
public const string ExternalNotificationSmtpTo = "ExternalNotification.Smtp.To";
|
||||
public const string ExternalNotificationServerChanSendKey = "ExternalNotification.ServerChan.SendKey";
|
||||
|
||||
// The following should not be modified manually
|
||||
public const string VersionName = "VersionUpdate.name";
|
||||
|
||||
|
||||
@@ -66,6 +66,12 @@
|
||||
<Version>5.7.0</Version>
|
||||
<PrivateAssets>All</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="FluentEmail.Liquid">
|
||||
<Version>3.0.2</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="FluentEmail.MailKit">
|
||||
<Version>3.0.2</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="GlobalHotKey">
|
||||
<Version>1.1.0</Version>
|
||||
</PackageReference>
|
||||
|
||||
@@ -27,6 +27,7 @@ using HandyControl.Tools.Extension;
|
||||
using MaaWpfGui.Constants;
|
||||
using MaaWpfGui.Extensions;
|
||||
using MaaWpfGui.Helper;
|
||||
using MaaWpfGui.Services.Notification;
|
||||
using MaaWpfGui.States;
|
||||
using MaaWpfGui.ViewModels.UI;
|
||||
using Newtonsoft.Json;
|
||||
@@ -613,7 +614,17 @@ namespace MaaWpfGui.Main
|
||||
if (isMainTaskQueueAllCompleted)
|
||||
{
|
||||
Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("AllTasksComplete"));
|
||||
using (var toast = new ToastNotification(LocalizationHelper.GetString("AllTasksComplete")))
|
||||
var allTaskCompleteTitle = LocalizationHelper.GetString("AllTasksComplete");
|
||||
var allTaskCompleteMessage = LocalizationHelper.GetString("AllTaskCompleteContent");
|
||||
|
||||
var configurationPreset = ConfigurationHelper.GetValue(ConfigurationKeys.CurrentConfiguration, "Default");
|
||||
|
||||
allTaskCompleteMessage = allTaskCompleteMessage
|
||||
.Replace("{Datetime}", DateTime.Now.ToString("U"))
|
||||
.Replace("{Preset}", configurationPreset);
|
||||
|
||||
ExternalNotificationService.SendAsync(allTaskCompleteTitle, allTaskCompleteMessage).Wait();
|
||||
using (var toast = new ToastNotification(allTaskCompleteTitle))
|
||||
{
|
||||
toast.Show();
|
||||
}
|
||||
|
||||
@@ -19,11 +19,13 @@ using System.Security.Principal;
|
||||
using System.Windows;
|
||||
using System.Windows.Threading;
|
||||
using GlobalHotKey;
|
||||
using MaaWpfGui.Constants;
|
||||
using MaaWpfGui.Helper;
|
||||
using MaaWpfGui.Models;
|
||||
using MaaWpfGui.Services;
|
||||
using MaaWpfGui.Services.HotKeys;
|
||||
using MaaWpfGui.Services.Managers;
|
||||
using MaaWpfGui.Services.Notification;
|
||||
using MaaWpfGui.Services.Web;
|
||||
using MaaWpfGui.ViewModels.UI;
|
||||
using MaaWpfGui.Views.UI;
|
||||
|
||||
@@ -21,6 +21,24 @@
|
||||
<system:String x:Key="UpdateSettings">软件更新</system:String>
|
||||
<system:String x:Key="AboutUs">关于我们</system:String>
|
||||
<system:String x:Key="Version">版本号</system:String>
|
||||
<system:String x:Key="Off">关闭</system:String>
|
||||
<system:String x:Key="ExternalNotificationTips">请注意:外部通知功能目前仅会发送“所有任务完成”的通知。</system:String>
|
||||
<system:String x:Key="ExternalNotificationSettings">外部通知</system:String>
|
||||
<system:String x:Key="ExternalNotificationEnabled">启用的通知配置</system:String>
|
||||
<system:String x:Key="ExternalNotificationSendSuccess">发送成功</system:String>
|
||||
<system:String x:Key="ExternalNotificationSendFail">发送失败</system:String>
|
||||
<system:String x:Key="ExternalNotificationSendTest">发送测试</system:String>
|
||||
<system:String x:Key="ExternalNotificationSendTestTitle">MAA 外部通知测试</system:String>
|
||||
<system:String x:Key="ExternalNotificationSendTestContent">这是 MAA 外部通知测试信息。如果你看到了这段内容,就说明通知发送成功了!</system:String>
|
||||
<system:String x:Key="ExternalNotificationServerChanSendKey">[Server Chan] 发送密钥</system:String>
|
||||
<system:String x:Key="ExternalNotificationSmtpServer">[SMTP] 服务器</system:String>
|
||||
<system:String x:Key="ExternalNotificationSmtpPort">[SMTP] 端口</system:String>
|
||||
<system:String x:Key="ExternalNotificationSmtpSsl">[SMTP] 使用 SSL</system:String>
|
||||
<system:String x:Key="ExternalNotificationSmtpAuth">[SMTP] 需要登录</system:String>
|
||||
<system:String x:Key="ExternalNotificationSmtpUser">[SMTP] 用户名</system:String>
|
||||
<system:String x:Key="ExternalNotificationSmtpPassword">[SMTP] 密码</system:String>
|
||||
<system:String x:Key="ExternalNotificationSmtpFrom">[SMTP] 发件人</system:String>
|
||||
<system:String x:Key="ExternalNotificationSmtpTo">[SMTP] 收件人</system:String>
|
||||
<!-- 设置指引 -->
|
||||
<system:String x:Key="TaskSettings">任务设置</system:String>
|
||||
<system:String x:Key="SettingsGuide">设置指引</system:String>
|
||||
@@ -509,6 +527,7 @@
|
||||
<system:String x:Key="StartCombat" xml:space="preserve">开始战斗: </system:String>
|
||||
<system:String x:Key="CompleteCombat">完成战斗</system:String>
|
||||
<system:String x:Key="AllTasksComplete">任务已全部完成!</system:String>
|
||||
<system:String x:Key="AllTaskCompleteContent">MAA 已在 {Datetime} 完成了 {Preset} 配置下所有预设的任务。</system:String>
|
||||
<system:String x:Key="BackgroundLinkStarted">开始执行任务</system:String>
|
||||
<system:String x:Key="BackgroundLinkStopped">任务终止</system:String>
|
||||
<system:String x:Key="FailedToOpenClient">打开客户端失败,请检查配置文件</system:String>
|
||||
@@ -625,4 +644,11 @@
|
||||
<system:String x:Key="ApiUpdateSuccess">关卡数据获取成功</system:String>
|
||||
<system:String x:Key="GameResourceUpdated">游戏资源已更新,请重启 MAA</system:String>
|
||||
<!-- Api -->
|
||||
<!-- External Notification -->
|
||||
<system:String x:Key="ExternalNotificationEmailTemplateHello">博士,有新的通知哦!</system:String>
|
||||
<system:String x:Key="ExternalNotificationEmailTemplateFooterLineOne">您会收到此邮件,是因为您在 MAA 中设置了 SMTP 服务器并开启了邮件通知服务。</system:String>
|
||||
<system:String x:Key="ExternalNotificationEmailTemplateFooterLineTwo">此邮件为系统自动发送,请勿回复。</system:String>
|
||||
<system:String x:Key="ExternalNotificationEmailTemplateLinkOfficialSite">官网</system:String>
|
||||
<system:String x:Key="ExternalNotificationEmailTemplateLinkCopilotSite">作业站</system:String>
|
||||
<!-- External Notification -->
|
||||
</ResourceDictionary>
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MaaWpfGui.Services.Notification
|
||||
{
|
||||
public class DummyNotificationProvider : IExternalNotificationProvider
|
||||
{
|
||||
public Task<bool> SendAsync(string title, string content)
|
||||
{
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
// <copyright file="ExternalNotificationService.cs" company="MaaAssistantArknights">
|
||||
// MaaWpfGui - A part of the MaaCoreArknights project
|
||||
// Copyright (C) 2021 MistEO and Contributors
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY
|
||||
// </copyright>
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using MaaWpfGui.Constants;
|
||||
using MaaWpfGui.Helper;
|
||||
using Vanara.PInvoke;
|
||||
|
||||
namespace MaaWpfGui.Services.Notification
|
||||
{
|
||||
public static class ExternalNotificationService
|
||||
{
|
||||
/// <summary>
|
||||
/// Send notification
|
||||
/// </summary>
|
||||
/// <param name="title">The title of the notification</param>
|
||||
/// <param name="content">The content of the notification</param>
|
||||
/// <param name="isTest">Indicate if it is a test or not.</param>
|
||||
/// <returns>Async task</returns>
|
||||
public static async Task SendAsync(string title, string content, bool isTest = false)
|
||||
{
|
||||
var enabledProvider = ConfigurationHelper.GetValue(ConfigurationKeys.ExternalNotificationEnabled, "Off");
|
||||
|
||||
IExternalNotificationProvider provider = enabledProvider switch
|
||||
{
|
||||
"ServerChan" => new ServerChanNotificationProvider(Instances.HttpService),
|
||||
"SMTP" => new SmtpNotificationProvider(),
|
||||
_ => new DummyNotificationProvider(),
|
||||
};
|
||||
|
||||
var result = await provider.SendAsync(title, content);
|
||||
|
||||
if (isTest is false && result)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
using var toast = new ToastNotification(LocalizationHelper.GetString(result ? "ExternalNotificationSendSuccess" : "ExternalNotificationSendFail"));
|
||||
toast.Show();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// <copyright file="IExternalNotificationProvider.cs" company="MaaAssistantArknights">
|
||||
// MaaWpfGui - A part of the MaaCoreArknights project
|
||||
// Copyright (C) 2021 MistEO and Contributors
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY
|
||||
// </copyright>
|
||||
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MaaWpfGui.Services.Notification
|
||||
{
|
||||
public interface IExternalNotificationProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// Send notification
|
||||
/// </summary>
|
||||
/// <param name="title">The title of the notification</param>
|
||||
/// <param name="content">The content of the notification</param>
|
||||
/// <returns>True for success, False for fail</returns>
|
||||
public Task<bool> SendAsync(string title, string content);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
// <copyright file="ServerChanNotificationProvider.cs" company="MaaAssistantArknights">
|
||||
// MaaWpfGui - A part of the MaaCoreArknights project
|
||||
// Copyright (C) 2021 MistEO and Contributors
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY
|
||||
// </copyright>
|
||||
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
using MaaWpfGui.Constants;
|
||||
using MaaWpfGui.Helper;
|
||||
using MaaWpfGui.Services.Web;
|
||||
using Serilog;
|
||||
|
||||
namespace MaaWpfGui.Services.Notification
|
||||
{
|
||||
public class ServerChanNotificationProvider : IExternalNotificationProvider
|
||||
{
|
||||
private readonly IHttpService _httpService;
|
||||
|
||||
private readonly ILogger _logger = Log.ForContext<ServerChanNotificationProvider>();
|
||||
|
||||
public ServerChanNotificationProvider(IHttpService httpService)
|
||||
{
|
||||
_httpService = httpService;
|
||||
}
|
||||
|
||||
public async Task<bool> SendAsync(string title, string content)
|
||||
{
|
||||
var sendKey = ConfigurationHelper.GetValue(ConfigurationKeys.ExternalNotificationServerChanSendKey, string.Empty);
|
||||
var url = $"https://sctapi.ftqq.com/{sendKey}.send";
|
||||
|
||||
var response = await _httpService.PostAsJsonAsync(
|
||||
new Uri(url),
|
||||
new ServerChanPostContent { Title = title, Content = content, });
|
||||
|
||||
var responseRoot = JsonDocument.Parse(response).RootElement;
|
||||
var hasCodeProperty = responseRoot.TryGetProperty("code", out var codeElement);
|
||||
if (hasCodeProperty is false)
|
||||
{
|
||||
_logger.Warning("Failed to send ServerChan notification, unknown response, {Response}", response);
|
||||
return false;
|
||||
}
|
||||
|
||||
var hasCode = codeElement.TryGetInt32(out var code);
|
||||
if (hasCode is false)
|
||||
{
|
||||
_logger.Warning("Failed to send ServerChan notification, unknown response {Response}", response);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (code == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
_logger.Warning("Failed to send ServerChan notification, code {Code}", code);
|
||||
return false;
|
||||
}
|
||||
|
||||
private class ServerChanPostContent
|
||||
{
|
||||
[JsonPropertyName("title")]
|
||||
public string Title { get; set; }
|
||||
|
||||
[JsonPropertyName("desp")]
|
||||
public string Content { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
141
src/MaaWpfGui/Services/Notification/SmtpNotificationProvider.cs
Normal file
141
src/MaaWpfGui/Services/Notification/SmtpNotificationProvider.cs
Normal file
@@ -0,0 +1,141 @@
|
||||
using System.Threading.Tasks;
|
||||
using FluentEmail.Core;
|
||||
using FluentEmail.Liquid;
|
||||
using FluentEmail.MailKitSmtp;
|
||||
using MaaWpfGui.Constants;
|
||||
using MaaWpfGui.Helper;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Serilog;
|
||||
|
||||
namespace MaaWpfGui.Services.Notification
|
||||
{
|
||||
public class SmtpNotificationProvider : IExternalNotificationProvider
|
||||
{
|
||||
private readonly ILogger _logger = Log.ForContext<ServerChanNotificationProvider>();
|
||||
|
||||
public async Task<bool> SendAsync(string title, string content)
|
||||
{
|
||||
var smtpServer = ConfigurationHelper.GetValue(ConfigurationKeys.ExternalNotificationSmtpServer, string.Empty);
|
||||
var smtpPortValid = int.TryParse(ConfigurationHelper.GetValue(ConfigurationKeys.ExternalNotificationSmtpPort, "25"), out var smtpPort);
|
||||
var smtpUser = ConfigurationHelper.GetValue(ConfigurationKeys.ExternalNotificationSmtpUser, string.Empty);
|
||||
var smtpPassword = ConfigurationHelper.GetValue(ConfigurationKeys.ExternalNotificationSmtpPassword, string.Empty);
|
||||
var smtpUseSslValid = bool.TryParse(ConfigurationHelper.GetValue(ConfigurationKeys.ExternalNotificationSmtpUseSsl, "false"), out var smtpUseSsl);
|
||||
var smtpRequiresAuthenticationValid = bool.TryParse(ConfigurationHelper.GetValue(ConfigurationKeys.ExternalNotificationSmtpRequiresAuthentication, "false"), out var smtpRequiresAuthentication);
|
||||
|
||||
if (string.IsNullOrEmpty(smtpServer) || smtpPortValid is false || smtpUseSslValid is false || smtpRequiresAuthenticationValid is false)
|
||||
{
|
||||
_logger.Error("Failed to send Email notification, invalid SMTP configuration");
|
||||
return false;
|
||||
}
|
||||
|
||||
Email.DefaultSender = new MailKitSender(new SmtpClientOptions
|
||||
{
|
||||
Server = smtpServer,
|
||||
Port = smtpPort,
|
||||
User = smtpUser,
|
||||
Password = smtpPassword,
|
||||
RequiresAuthentication = smtpRequiresAuthentication,
|
||||
UseSsl = smtpUseSsl,
|
||||
UsePickupDirectory = false,
|
||||
});
|
||||
|
||||
Email.DefaultRenderer = new LiquidRenderer(new OptionsWrapper<LiquidRendererOptions>(new LiquidRendererOptions()));
|
||||
|
||||
var emailFrom = ConfigurationHelper.GetValue(ConfigurationKeys.ExternalNotificationSmtpFrom, string.Empty);
|
||||
var emailTo = ConfigurationHelper.GetValue(ConfigurationKeys.ExternalNotificationSmtpTo, string.Empty);
|
||||
|
||||
var email = Email
|
||||
.From(emailFrom)
|
||||
.To(emailTo)
|
||||
.Subject($"[MAA] {title}")
|
||||
.UsingTemplate(EmailTemplate, new
|
||||
{
|
||||
Title = title,
|
||||
Content = content,
|
||||
Hello = LocalizationHelper.GetString("ExternalNotificationEmailTemplateHello"),
|
||||
FooterLineOne = LocalizationHelper.GetString("ExternalNotificationEmailTemplateFooterLineOne"),
|
||||
FooterLineTwo = LocalizationHelper.GetString("ExternalNotificationEmailTemplateFooterLineTwo"),
|
||||
LinkTextOfficialSite = LocalizationHelper.GetString("ExternalNotificationEmailTemplateLinkOfficialSite"),
|
||||
LinkTextCopilotSite = LocalizationHelper.GetString("ExternalNotificationEmailTemplateLinkCopilotSite"),
|
||||
});
|
||||
|
||||
var sendResult = await email.SendAsync();
|
||||
|
||||
if (sendResult.Successful)
|
||||
{
|
||||
_logger.Information("Successfully sent Email notification to {EmailTo}", emailTo);
|
||||
return true;
|
||||
}
|
||||
|
||||
_logger.Warning("Failed to send Email notification to {EmailTo}, {Error}", emailTo, sendResult.ErrorMessages);
|
||||
return false;
|
||||
}
|
||||
|
||||
private const string EmailTemplate = @"
|
||||
<html lang=""zh"">
|
||||
<style>
|
||||
.title {
|
||||
font-size: xx-large;
|
||||
font-weight: bold;
|
||||
color: black;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.heading {
|
||||
font-size: large;
|
||||
}
|
||||
|
||||
.notification h1 {
|
||||
font-size: large;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.notification p {
|
||||
font-size: medium;
|
||||
}
|
||||
|
||||
.footer {
|
||||
font-size: small;
|
||||
}
|
||||
|
||||
.space {
|
||||
padding-left: 0.5rem;
|
||||
padding-right: 0.5rem;
|
||||
}
|
||||
</style>
|
||||
|
||||
<h1 class=""title"">Maa Assistant Arknights</h1>
|
||||
|
||||
<div class=""heading"">
|
||||
<p>{{ Hello }}</p>
|
||||
</div>
|
||||
|
||||
<hr />
|
||||
|
||||
<div class=""notification"">
|
||||
<h1>{{ Title }}</h1>
|
||||
<p>{{ Content }}</p>
|
||||
</div>
|
||||
|
||||
<hr />
|
||||
|
||||
<div class=""footer"">
|
||||
<p>
|
||||
{{ FooterLineOne }}
|
||||
</p>
|
||||
<p>{{ FooterLineTwo }}</p>
|
||||
<p>
|
||||
<a class=""space"" href=""https://github.com/MaaAssistantArknights"">
|
||||
GitHub
|
||||
</a>
|
||||
<a class=""space"" href=""https://space.bilibili.com/3493274731940507"">
|
||||
Bilibili
|
||||
</a>
|
||||
<a class=""space"" href=""https://maa.plus"">{{ LinkTextOfficialSite }}</a>
|
||||
<a class=""space"" href=""https://prts.plus"">{{ LinkTextCopilotSite }}</a>
|
||||
</p>
|
||||
</div>
|
||||
</html>
|
||||
";
|
||||
}
|
||||
}
|
||||
@@ -45,6 +45,7 @@ using Newtonsoft.Json.Linq;
|
||||
using Serilog;
|
||||
using Stylet;
|
||||
using Windows.Devices.Geolocation;
|
||||
using MaaWpfGui.Services.Notification;
|
||||
using ComboBox = System.Windows.Controls.ComboBox;
|
||||
using Timer = System.Timers.Timer;
|
||||
|
||||
@@ -107,6 +108,7 @@ namespace MaaWpfGui.ViewModels.UI
|
||||
_listTitle.Add(LocalizationHelper.GetString("ConnectionSettings"));
|
||||
_listTitle.Add(LocalizationHelper.GetString("StartupSettings"));
|
||||
_listTitle.Add(LocalizationHelper.GetString("UISettings"));
|
||||
_listTitle.Add(LocalizationHelper.GetString("ExternalNotificationSettings"));
|
||||
_listTitle.Add(LocalizationHelper.GetString("HotKeySettings"));
|
||||
_listTitle.Add(LocalizationHelper.GetString("UpdateSettings"));
|
||||
_listTitle.Add(LocalizationHelper.GetString("AboutUs"));
|
||||
@@ -150,6 +152,156 @@ namespace MaaWpfGui.ViewModels.UI
|
||||
}
|
||||
}
|
||||
|
||||
#region External Notifications
|
||||
|
||||
public async Task ExternalNotificationSendTest()
|
||||
{
|
||||
await ExternalNotificationService.SendAsync(
|
||||
LocalizationHelper.GetString("ExternalNotificationSendTestTitle"),
|
||||
LocalizationHelper.GetString("ExternalNotificationSendTestContent"),
|
||||
true);
|
||||
}
|
||||
|
||||
public List<CombinedData> ExternalNotificationProviders => new List<CombinedData>
|
||||
{
|
||||
new CombinedData { Display = LocalizationHelper.GetString("Off"), Value = "Off" },
|
||||
new CombinedData { Display = "Server Chan", Value = "ServerChan" },
|
||||
new CombinedData { Display = "SMTP", Value = "SMTP" },
|
||||
};
|
||||
|
||||
private string _enabledExternalNotificationProvider = ConfigurationHelper.GetValue(ConfigurationKeys.ExternalNotificationEnabled, "Off");
|
||||
|
||||
public bool IsEnabled => _enabledExternalNotificationProvider != "Off";
|
||||
|
||||
public bool IsServerChan => _enabledExternalNotificationProvider == "ServerChan";
|
||||
|
||||
public bool IsSmtp => _enabledExternalNotificationProvider == "SMTP";
|
||||
|
||||
public string EnabledExternalNotificationProvider
|
||||
{
|
||||
get => _enabledExternalNotificationProvider;
|
||||
set
|
||||
{
|
||||
SetAndNotify(ref _enabledExternalNotificationProvider, value);
|
||||
ConfigurationHelper.SetValue(ConfigurationKeys.ExternalNotificationEnabled, value);
|
||||
|
||||
NotifyOfPropertyChange(nameof(IsEnabled));
|
||||
NotifyOfPropertyChange(nameof(IsSmtp));
|
||||
NotifyOfPropertyChange(nameof(IsServerChan));
|
||||
}
|
||||
}
|
||||
|
||||
private string _serverChanSendKey = ConfigurationHelper.GetValue(ConfigurationKeys.ExternalNotificationServerChanSendKey, string.Empty);
|
||||
|
||||
public string ServerChanSendKey
|
||||
{
|
||||
get => _serverChanSendKey;
|
||||
set
|
||||
{
|
||||
SetAndNotify(ref _serverChanSendKey, value);
|
||||
ConfigurationHelper.SetValue(ConfigurationKeys.ExternalNotificationServerChanSendKey, value);
|
||||
}
|
||||
}
|
||||
|
||||
private string _smtpServer = ConfigurationHelper.GetValue(ConfigurationKeys.ExternalNotificationSmtpServer, string.Empty);
|
||||
|
||||
public string SmtpServer
|
||||
{
|
||||
get => _smtpServer;
|
||||
set
|
||||
{
|
||||
SetAndNotify(ref _smtpServer, value);
|
||||
ConfigurationHelper.SetValue(ConfigurationKeys.ExternalNotificationSmtpServer, value);
|
||||
}
|
||||
}
|
||||
|
||||
private string _smtpPort = ConfigurationHelper.GetValue(ConfigurationKeys.ExternalNotificationSmtpPort, string.Empty);
|
||||
|
||||
public string SmtpPort
|
||||
{
|
||||
get => _smtpPort;
|
||||
set
|
||||
{
|
||||
SetAndNotify(ref _smtpPort, value);
|
||||
ConfigurationHelper.SetValue(ConfigurationKeys.ExternalNotificationSmtpPort, value);
|
||||
}
|
||||
}
|
||||
|
||||
private string _smtpUser = ConfigurationHelper.GetValue(ConfigurationKeys.ExternalNotificationSmtpUser, string.Empty);
|
||||
|
||||
public string SmtpUser
|
||||
{
|
||||
get => _smtpUser;
|
||||
set
|
||||
{
|
||||
SetAndNotify(ref _smtpUser, value);
|
||||
ConfigurationHelper.SetValue(ConfigurationKeys.ExternalNotificationSmtpUser, value);
|
||||
}
|
||||
}
|
||||
|
||||
private string _smtpPassword = ConfigurationHelper.GetValue(ConfigurationKeys.ExternalNotificationSmtpPassword, string.Empty);
|
||||
|
||||
public string SmtpPassword
|
||||
{
|
||||
get => _smtpPassword;
|
||||
set
|
||||
{
|
||||
SetAndNotify(ref _smtpPassword, value);
|
||||
ConfigurationHelper.SetValue(ConfigurationKeys.ExternalNotificationSmtpPassword, value);
|
||||
}
|
||||
}
|
||||
|
||||
private string _smtpFrom = ConfigurationHelper.GetValue(ConfigurationKeys.ExternalNotificationSmtpFrom, string.Empty);
|
||||
|
||||
public string SmtpFrom
|
||||
{
|
||||
get => _smtpFrom;
|
||||
set
|
||||
{
|
||||
SetAndNotify(ref _smtpFrom, value);
|
||||
ConfigurationHelper.SetValue(ConfigurationKeys.ExternalNotificationSmtpFrom, value);
|
||||
}
|
||||
}
|
||||
|
||||
private string _smtpTo = ConfigurationHelper.GetValue(ConfigurationKeys.ExternalNotificationSmtpTo, string.Empty);
|
||||
|
||||
public string SmtpTo
|
||||
{
|
||||
get => _smtpTo;
|
||||
set
|
||||
{
|
||||
SetAndNotify(ref _smtpTo, value);
|
||||
ConfigurationHelper.SetValue(ConfigurationKeys.ExternalNotificationSmtpTo, value);
|
||||
}
|
||||
}
|
||||
|
||||
private bool _smtpUseSsl = bool.Parse(ConfigurationHelper.GetValue(ConfigurationKeys.ExternalNotificationSmtpUseSsl, "false"));
|
||||
|
||||
public bool SmtpUseSsl
|
||||
{
|
||||
get => _smtpUseSsl;
|
||||
set
|
||||
{
|
||||
SetAndNotify(ref _smtpUseSsl, value);
|
||||
ConfigurationHelper.SetValue(ConfigurationKeys.ExternalNotificationSmtpUseSsl, value.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private bool _smtpRequireAuthentication = bool.Parse(ConfigurationHelper.GetValue(ConfigurationKeys.ExternalNotificationSmtpRequiresAuthentication, "false"));
|
||||
|
||||
public bool SmtpRequireAuthentication
|
||||
{
|
||||
get => _smtpRequireAuthentication;
|
||||
set
|
||||
{
|
||||
SetAndNotify(ref _smtpRequireAuthentication, value);
|
||||
ConfigurationHelper.SetValue(ConfigurationKeys.ExternalNotificationSmtpRequiresAuthentication, value.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
private List<string> _listTitle = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -69,12 +69,15 @@
|
||||
<userControl:GUISettingsUserControl Margin="0,20" HorizontalAlignment="Center" />
|
||||
|
||||
<hc:Divider Content="{Binding ListTitle[6]}" />
|
||||
<userControl:HotKeySettingsUserControl Margin="0,20" HorizontalAlignment="Center" />
|
||||
<userControl:ExternalNotificationSettingsUserControl Margin="0,20" HorizontalAlignment="Center" />
|
||||
|
||||
<hc:Divider Content="{Binding ListTitle[7]}" />
|
||||
<userControl:VersionUpdateSettingsUserControl Margin="0,20" HorizontalAlignment="Center" />
|
||||
<userControl:HotKeySettingsUserControl Margin="0,20" HorizontalAlignment="Center" />
|
||||
|
||||
<hc:Divider Content="{Binding ListTitle[8]}" />
|
||||
<userControl:VersionUpdateSettingsUserControl Margin="0,20" HorizontalAlignment="Center" />
|
||||
|
||||
<hc:Divider Content="{Binding ListTitle[9]}" />
|
||||
<userControl:AboutUserControl Margin="0,20" HorizontalAlignment="Center" />
|
||||
<!--<Rectangle HorizontalAlignment="Stretch" Fill="{DynamicResource BorderBrush}" Height="1" />-->
|
||||
</StackPanel>
|
||||
|
||||
@@ -0,0 +1,255 @@
|
||||
<UserControl
|
||||
x:Class="MaaWpfGui.Views.UserControl.ExternalNotificationSettingsUserControl"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:c="clr-namespace:CalcBinding;assembly=CalcBinding"
|
||||
xmlns:controls="clr-namespace:MaaWpfGui.Styles.Controls"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:dd="urn:gong-wpf-dragdrop"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
xmlns:styles="clr-namespace:MaaWpfGui.Styles"
|
||||
xmlns:ui="clr-namespace:MaaWpfGui.ViewModels.UI"
|
||||
xmlns:viewModels="clr-namespace:MaaWpfGui.ViewModels"
|
||||
xmlns:vm="clr-namespace:MaaWpfGui"
|
||||
xmlns:u="clr-namespace:MaaWpfGui.Utilities"
|
||||
xmlns:hc="https://handyorg.github.io/handycontrol"
|
||||
d:DataContext="{d:DesignInstance {x:Type ui:SettingsViewModel}}"
|
||||
d:DesignHeight="300"
|
||||
d:DesignWidth="550"
|
||||
mc:Ignorable="d">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<StackPanel
|
||||
Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
Orientation="Horizontal">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="65"/>
|
||||
<ColumnDefinition Width="420"/>
|
||||
<ColumnDefinition Width="65"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<controls:TextBlock
|
||||
Grid.Column="1"
|
||||
Margin="10"
|
||||
Block.TextAlignment="Center"
|
||||
Text="{DynamicResource ExternalNotificationTips}"
|
||||
TextWrapping="Wrap" />
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel
|
||||
Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Orientation="Horizontal">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="35"/>
|
||||
<ColumnDefinition Width="130"/>
|
||||
<ColumnDefinition Width="270"/>
|
||||
<ColumnDefinition Width="80"/>
|
||||
<ColumnDefinition Width="35"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<controls:TextBlock
|
||||
Grid.Row="0"
|
||||
Grid.Column="1"
|
||||
Margin="10"
|
||||
Block.TextAlignment="Center"
|
||||
Text="{DynamicResource ExternalNotificationEnabled}"
|
||||
TextWrapping="Wrap" />
|
||||
<ComboBox
|
||||
Grid.Row="0"
|
||||
Grid.Column="2"
|
||||
Width="250"
|
||||
Height="30"
|
||||
Margin="10"
|
||||
DisplayMemberPath="Display"
|
||||
ItemsSource="{Binding ExternalNotificationProviders}"
|
||||
SelectedValue="{Binding EnabledExternalNotificationProvider}"
|
||||
SelectedValuePath="Value" />
|
||||
<Button
|
||||
Grid.Row="0"
|
||||
Grid.Column="3"
|
||||
Margin="5"
|
||||
IsEnabled="{c:Binding IsEnabled}"
|
||||
Command="{s:Action ExternalNotificationSendTest}"
|
||||
Content="{DynamicResource ExternalNotificationSendTest}"/>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel
|
||||
Grid.Row="2"
|
||||
Grid.Column="0"
|
||||
IsEnabled="{c:Binding IsServerChan}"
|
||||
Orientation="Horizontal">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="65"/>
|
||||
<ColumnDefinition Width="150"/>
|
||||
<ColumnDefinition Width="270"/>
|
||||
<ColumnDefinition Width="65"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<controls:TextBlock
|
||||
Grid.Row="0"
|
||||
Grid.Column="1"
|
||||
Margin="10"
|
||||
Block.TextAlignment="Center"
|
||||
Text="{DynamicResource ExternalNotificationServerChanSendKey}"
|
||||
TextWrapping="Wrap" />
|
||||
<TextBox
|
||||
x:Name="ServerChanSendKey"
|
||||
Grid.Row="0"
|
||||
Grid.Column="2"
|
||||
Width="250"
|
||||
Height="30"
|
||||
Margin="10"
|
||||
Text="{c:Binding ServerChanSendKey}" />
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel
|
||||
Grid.Row="3"
|
||||
Grid.Column="0"
|
||||
IsEnabled="{c:Binding IsSmtp}"
|
||||
Orientation="Horizontal">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="35"/>
|
||||
<ColumnDefinition Width="70"/>
|
||||
<ColumnDefinition Width="170"/>
|
||||
<ColumnDefinition Width="70"/>
|
||||
<ColumnDefinition Width="170"/>
|
||||
<ColumnDefinition Width="35"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<CheckBox
|
||||
Grid.Row="0"
|
||||
Grid.Column="2"
|
||||
Margin="10"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Content="{DynamicResource ExternalNotificationSmtpSsl}"
|
||||
IsChecked="{c:Binding SmtpUseSsl}"/>
|
||||
<CheckBox
|
||||
Grid.Row="0"
|
||||
Grid.Column="4"
|
||||
Margin="10"
|
||||
VerticalAlignment="Center"
|
||||
Content="{DynamicResource ExternalNotificationSmtpAuth}"
|
||||
IsChecked="{c:Binding SmtpRequireAuthentication}"/>
|
||||
|
||||
<controls:TextBlock
|
||||
Grid.Row="1"
|
||||
Grid.Column="1"
|
||||
Margin="10"
|
||||
Block.TextAlignment="Center"
|
||||
Text="{DynamicResource ExternalNotificationSmtpServer}"
|
||||
TextWrapping="Wrap" />
|
||||
<TextBox
|
||||
x:Name="SmtpServer"
|
||||
Grid.Row="1"
|
||||
Grid.Column="2"
|
||||
Width="150"
|
||||
Height="30"
|
||||
Margin="10"
|
||||
Text="{c:Binding SmtpServer}" />
|
||||
<controls:TextBlock
|
||||
Grid.Row="1"
|
||||
Grid.Column="3"
|
||||
Margin="10"
|
||||
Block.TextAlignment="Center"
|
||||
Text="{DynamicResource ExternalNotificationSmtpPort}"
|
||||
TextWrapping="Wrap" />
|
||||
<TextBox
|
||||
x:Name="SmtpPort"
|
||||
Grid.Row="1"
|
||||
Grid.Column="4"
|
||||
Width="150"
|
||||
Height="30"
|
||||
Margin="10"
|
||||
Text="{c:Binding SmtpPort}" />
|
||||
|
||||
<controls:TextBlock
|
||||
Grid.Row="2"
|
||||
Grid.Column="1"
|
||||
Margin="10"
|
||||
Block.TextAlignment="Center"
|
||||
Text="{DynamicResource ExternalNotificationSmtpUser}"
|
||||
TextWrapping="Wrap" />
|
||||
<TextBox
|
||||
x:Name="SmtpUser"
|
||||
Grid.Row="2"
|
||||
Grid.Column="2"
|
||||
Width="150"
|
||||
Height="30"
|
||||
Margin="10"
|
||||
IsEnabled="{c:Binding SmtpRequireAuthentication}"
|
||||
Text="{c:Binding SmtpUser}" />
|
||||
<controls:TextBlock
|
||||
Grid.Row="2"
|
||||
Grid.Column="3"
|
||||
Margin="10"
|
||||
Block.TextAlignment="Center"
|
||||
Text="{DynamicResource ExternalNotificationSmtpPassword}"
|
||||
TextWrapping="Wrap" />
|
||||
<TextBox
|
||||
x:Name="SmtpPassword"
|
||||
Grid.Row="2"
|
||||
Grid.Column="4"
|
||||
Width="150"
|
||||
Height="30"
|
||||
Margin="10"
|
||||
IsEnabled="{c:Binding SmtpRequireAuthentication}"
|
||||
Text="{c:Binding SmtpPassword}" />
|
||||
|
||||
<controls:TextBlock
|
||||
Grid.Row="3"
|
||||
Grid.Column="1"
|
||||
Margin="10"
|
||||
Block.TextAlignment="Center"
|
||||
Text="{DynamicResource ExternalNotificationSmtpFrom}"
|
||||
TextWrapping="Wrap" />
|
||||
<TextBox
|
||||
x:Name="SmtpFrom"
|
||||
Grid.Row="3"
|
||||
Grid.Column="2"
|
||||
Width="150"
|
||||
Height="30"
|
||||
Margin="10"
|
||||
Text="{c:Binding SmtpFrom}" />
|
||||
<controls:TextBlock
|
||||
Grid.Row="3"
|
||||
Grid.Column="3"
|
||||
Margin="10"
|
||||
Block.TextAlignment="Center"
|
||||
Text="{DynamicResource ExternalNotificationSmtpTo}"
|
||||
TextWrapping="Wrap" />
|
||||
<TextBox
|
||||
x:Name="SmtpTo"
|
||||
Grid.Row="3"
|
||||
Grid.Column="4"
|
||||
Width="150"
|
||||
Height="30"
|
||||
Margin="10"
|
||||
Text="{c:Binding SmtpTo}" />
|
||||
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,29 @@
|
||||
// <copyright file="ExternalNotificationSettingsUserControl.xaml.cs" company="MaaAssistantArknights">
|
||||
// MaaWpfGui - A part of the MaaCoreArknights project
|
||||
// Copyright (C) 2021 MistEO and Contributors
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY
|
||||
// </copyright>
|
||||
|
||||
namespace MaaWpfGui.Views.UserControl
|
||||
{
|
||||
/// <summary>
|
||||
/// ExternalNotificationSettingsUserControl.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class ExternalNotificationSettingsUserControl : System.Windows.Controls.UserControl
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ExternalNotificationSettingsUserControl"/> class.
|
||||
/// </summary>
|
||||
public ExternalNotificationSettingsUserControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user