feat: add Bark Server configuration key

This commit is contained in:
Nitori
2024-03-24 14:57:12 +08:00
committed by nitori
parent 8354445668
commit 84e893dffb
9 changed files with 47 additions and 6 deletions

View File

@@ -212,6 +212,7 @@ namespace MaaWpfGui.Constants
public const string ExternalNotificationTelegramBotToken = "ExternalNotification.Telegram.BotToken";
public const string ExternalNotificationTelegramChatId = "ExternalNotification.Telegram.ChatId";
public const string ExternalNotificationBarkSendKey = "ExternalNotification.Bark.SendKey";
public const string ExternalNotificationBarkServer = "ExternalNotification.Bark.Server";
// The following should not be modified manually
public const string VersionName = "VersionUpdate.name";

View File

@@ -34,6 +34,7 @@
<system:String x:Key="ExternalNotificationSendTestContent">This is MAA external notification test information. If you see this content, the notification was sent successfully!</system:String>
<system:String x:Key="ExternalNotificationServerChanSendKey">Server Chan Send Key</system:String>
<system:String x:Key="ExternalNotificationBarkSendKey">Bark Send Key</system:String>
<system:String x:Key="ExternalNotificationBarkServer">Bark Server</system:String>
<system:String x:Key="ExternalNotificationSmtpTo">Recipient</system:String>
<system:String x:Key="ExternalNotificationSmtpServer">SMTP Server</system:String>
<system:String x:Key="ExternalNotificationSmtpPort">Port</system:String>

View File

@@ -34,6 +34,7 @@
<system:String x:Key="ExternalNotificationSendTestContent">これは MAA 外部通知テスト情報です。 このコンテンツが表示された場合、通知は正常に送信されました!</system:String>
<system:String x:Key="ExternalNotificationServerChanSendKey">ServerChan Send Key</system:String>
<system:String x:Key="ExternalNotificationBarkSendKey">Bark Send Key</system:String>
<system:String x:Key="ExternalNotificationBarkServer">Bark サーバ</system:String>
<system:String x:Key="ExternalNotificationSmtpServer">SMTP サーバ</system:String>
<system:String x:Key="ExternalNotificationSmtpPort">ポート</system:String>
<system:String x:Key="ExternalNotificationSmtpSsl">SSL を使用します</system:String>

View File

@@ -34,6 +34,7 @@
<system:String x:Key="ExternalNotificationSendTestContent">MAA 외부 알림 테스트 정보입니다. 이 콘텐츠가 표시되면 알림이 성공적으로 전송된 것입니다!</system:String>
<system:String x:Key="ExternalNotificationServerChanSendKey">Server Chan 전송 키</system:String>
<system:String x:Key="ExternalNotificationBarkSendKey">Bark 전송 키</system:String>
<system:String x:Key="ExternalNotificationBarkServer">Bark 서버</system:String>
<system:String x:Key="ExternalNotificationSmtpServer">SMTP 서버</system:String>
<system:String x:Key="ExternalNotificationSmtpPort">포트</system:String>
<system:String x:Key="ExternalNotificationSmtpSsl">는 SSL을 사용합니다.</system:String>

View File

@@ -34,6 +34,7 @@
<system:String x:Key="ExternalNotificationSendTestContent">这是 MAA 外部通知测试信息。如果你看到了这段内容,就说明通知发送成功了!</system:String>
<system:String x:Key="ExternalNotificationServerChanSendKey">Server Chan 发送密钥</system:String>
<system:String x:Key="ExternalNotificationBarkSendKey">Bark 发送密钥</system:String>
<system:String x:Key="ExternalNotificationBarkServer">Bark 服务器</system:String>
<system:String x:Key="ExternalNotificationSmtpServer">SMTP 服务器</system:String>
<system:String x:Key="ExternalNotificationSmtpPort">端口</system:String>
<system:String x:Key="ExternalNotificationSmtpSsl">使用 SSL</system:String>

View File

@@ -34,6 +34,7 @@
<system:String x:Key="ExternalNotificationSendTestContent">這是 MAA 外部通知測試資訊。 如果你看到了這段內容,就說明通知發送成功了!</system:String>
<system:String x:Key="ExternalNotificationServerChanSendKey">Server Chan 發送金鑰</system:String>
<system:String x:Key="ExternalNotificationBarkSendKey">Bark 發送金鑰</system:String>
<system:String x:Key="ExternalNotificationBarkServer">Bark 伺服器</system:String>
<system:String x:Key="ExternalNotificationSmtpServer">SMTP 伺服器</system:String>
<system:String x:Key="ExternalNotificationSmtpPort">埠</system:String>
<system:String x:Key="ExternalNotificationSmtpSsl">使用 SSL</system:String>

View File

@@ -19,8 +19,6 @@ namespace MaaWpfGui.Services.Notification
private readonly ILogger _logger = Log.ForContext<BarkNotificationProvider>();
private readonly string _apiBase = "https://api.day.app";
public BarkNotificationProvider(IHttpService httpService)
{
_httpService = httpService;
@@ -34,8 +32,14 @@ namespace MaaWpfGui.Services.Notification
_logger.Warning("Failed to send Bark notification, Bark send key is empty");
return false;
}
var apiBase = ConfigurationHelper.GetValue(ConfigurationKeys.ExternalNotificationBarkServer, string.Empty);
if (string.IsNullOrWhiteSpace(apiBase))
{
_logger.Warning("Failed to send Bark notification, Bark server address is empty");
return false;
}
var response = await _httpService.PostAsJsonAsync(
new Uri($"{_apiBase}/push"),
new Uri(new Uri(apiBase), "/push"),
new BarkPostContent { Title = title, Content = content, SendKey = sendKey });
var data = JsonSerializer.Deserialize<BarkResponse>(response);
if (data.Code != 200)

View File

@@ -406,6 +406,18 @@ namespace MaaWpfGui.ViewModels.UI
private string _barkSendKey = ConfigurationHelper.GetValue(ConfigurationKeys.ExternalNotificationBarkSendKey, string.Empty);
public string BarkServer
{
get => _barkServer;
set
{
SetAndNotify(ref _barkServer, value);
ConfigurationHelper.SetValue(ConfigurationKeys.ExternalNotificationBarkServer, value);
}
}
private string _barkServer = ConfigurationHelper.GetValue(ConfigurationKeys.ExternalNotificationBarkServer, "https://api.day.app");
private string _smtpServer = ConfigurationHelper.GetValue(ConfigurationKeys.ExternalNotificationSmtpServer, string.Empty);
public string SmtpServer

View File

@@ -359,27 +359,46 @@
Visibility="{c:Binding 'EnabledExternalNotificationProvider == &quot;Bark&quot;'}"
Orientation="Horizontal">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="65" />
<ColumnDefinition Width="150" />
<ColumnDefinition Width="270" />
<ColumnDefinition Width="65" />
</Grid.ColumnDefinitions>
<TextBox
x:Name="BarkSendKey"
Grid.Row="1"
Grid.Column="2"
Width="250"
Height="30"
Margin="10"
Text="{c:Binding BarkSendKey}" />
<controls:TextBlock
Grid.Row="0"
Grid.Row="1"
Grid.Column="1"
Margin="10"
Block.TextAlignment="Center"
Text="{DynamicResource ExternalNotificationBarkSendKey}"
TextWrapping="Wrap" />
<TextBox
x:Name="BarkSendKey"
x:Name="BarkServer"
Grid.Row="0"
Grid.Column="2"
Width="250"
Height="30"
Margin="10"
Text="{c:Binding BarkSendKey}" />
Text="{c:Binding BarkServer}" />
<controls:TextBlock
Grid.Row="0"
Grid.Column="1"
Margin="10"
Block.TextAlignment="Center"
Text="{DynamicResource ExternalNotificationBarkServer}"
TextWrapping="Wrap" />
</Grid>
</StackPanel>
</Grid>