chore: 拆分任务完成后通知

This commit is contained in:
uye
2025-04-22 10:15:03 +08:00
parent 7fd494554f
commit 6edbc751b2
9 changed files with 60 additions and 25 deletions

View File

@@ -253,6 +253,7 @@ namespace MaaWpfGui.Constants
public const string RemoteControlDeviceIdentity = "RemoteControl.RemoteControlDeviceIdentity";
public const string ExternalNotificationEnabled = "ExternalNotification.Enabled";
public const string ExternalNotificationSendWhenComplete = "ExternalNotification.SendWhenComplete";
public const string ExternalNotificationEnableDetails = "ExternalNotification.EnableDetails";
public const string ExternalNotificationSendWhenError = "ExternalNotification.SendWhenError";
public const string ExternalNotificationSmtpServer = "ExternalNotification.Smtp.Server";

View File

@@ -837,12 +837,15 @@ namespace MaaWpfGui.Main
allTaskCompleteLog = allTaskCompleteLog + Environment.NewLine + sanityReport;
Instances.TaskQueueViewModel.AddLog(allTaskCompleteLog);
var logs = SettingsViewModel.ExternalNotificationSettings.ExternalNotificationEnableDetails
? Instances.TaskQueueViewModel.LogItemViewModels.Aggregate(string.Empty, (current, logItem) => current + $"[{logItem.Time}][{logItem.Color}]{logItem.Content}\n")
: string.Empty;
logs += allTaskCompleteMessage;
if (SettingsViewModel.ExternalNotificationSettings.ExternalNotificationSendWhenComplete)
{
var logs = SettingsViewModel.ExternalNotificationSettings.ExternalNotificationEnableDetails
? Instances.TaskQueueViewModel.LogItemViewModels.Aggregate(string.Empty, (current, logItem) => current + $"[{logItem.Time}][{logItem.Color}]{logItem.Content}\n")
: string.Empty;
logs += allTaskCompleteMessage;
ExternalNotificationService.Send(allTaskCompleteTitle, logs + Environment.NewLine + sanityReport);
ExternalNotificationService.Send(allTaskCompleteTitle, logs + Environment.NewLine + sanityReport);
}
if (_toastNotificationTimer is not null)
{
@@ -864,12 +867,15 @@ namespace MaaWpfGui.Main
{
Instances.TaskQueueViewModel.AddLog(allTaskCompleteLog);
var logs = SettingsViewModel.ExternalNotificationSettings.ExternalNotificationEnableDetails
? Instances.TaskQueueViewModel.LogItemViewModels.Aggregate(string.Empty, (current, logItem) => current + $"[{logItem.Time}][{logItem.Color}]{logItem.Content}\n")
: string.Empty;
logs += allTaskCompleteMessage;
if (SettingsViewModel.ExternalNotificationSettings.ExternalNotificationSendWhenComplete)
{
var logs = SettingsViewModel.ExternalNotificationSettings.ExternalNotificationEnableDetails
? Instances.TaskQueueViewModel.LogItemViewModels.Aggregate(string.Empty, (current, logItem) => current + $"[{logItem.Time}][{logItem.Color}]{logItem.Content}\n")
: string.Empty;
logs += allTaskCompleteMessage;
ExternalNotificationService.Send(allTaskCompleteTitle, logs);
ExternalNotificationService.Send(allTaskCompleteTitle, logs);
}
}
using (var toast = new ToastNotification(allTaskCompleteTitle))

View File

@@ -39,7 +39,8 @@
<system:String x:Key="ExternalNotificationSettings">External notifications</system:String>
<system:String x:Key="ExternalNotificationEnabled">Enabled configuration</system:String>
<system:String x:Key="ExternalNotificationEnableDetails">Output Detailed Information</system:String>
<system:String x:Key="ExternalNotificationSendWhenError">Send additional notification when task fails</system:String>
<system:String x:Key="ExternalNotificationSendWhenComplete">タスク完了時に通知を送信</system:String>
<system:String x:Key="ExternalNotificationSendWhenError">Send notification when task fails</system:String>
<system:String x:Key="ExternalNotificationSendSuccess">Send successfully</system:String>
<system:String x:Key="ExternalNotificationSendFail">Send failed</system:String>
<system:String x:Key="ExternalNotificationSendTest">Send Test</system:String>

View File

@@ -39,7 +39,8 @@
<system:String x:Key="ExternalNotificationSettings">外部通知</system:String>
<system:String x:Key="ExternalNotificationEnabled">通知構成の有効化</system:String>
<system:String x:Key="ExternalNotificationEnableDetails">詳細情報を出力</system:String>
<system:String x:Key="ExternalNotificationSendWhenError">タスクが失敗したときに追加の通知を送信する</system:String>
<system:String x:Key="ExternalNotificationSendWhenComplete">タスク完了時に通知を送信</system:String>
<system:String x:Key="ExternalNotificationSendWhenError">タスクが失敗したときに通知を送信</system:String>
<system:String x:Key="ExternalNotificationSendSuccess">正常に送信</system:String>
<system:String x:Key="ExternalNotificationSendFail">送信に失敗しました</system:String>
<system:String x:Key="ExternalNotificationSendTest">テストを送信する</system:String>

View File

@@ -39,7 +39,8 @@
<system:String x:Key="ExternalNotificationSettings">외부 알림</system:String>
<system:String x:Key="ExternalNotificationEnabled">알림 구성 사용</system:String>
<system:String x:Key="ExternalNotificationEnableDetails">상세 정보 출력</system:String>
<system:String x:Key="ExternalNotificationSendWhenError">작업 실패 시 추가 알림 전송</system:String>
<system:String x:Key="ExternalNotificationSendWhenComplete">작업 완료 시 알림 전송</system:String>
<system:String x:Key="ExternalNotificationSendWhenError">작업 실패 시 알림 전송</system:String>
<system:String x:Key="ExternalNotificationSendSuccess">전송 성공</system:String>
<system:String x:Key="ExternalNotificationSendFail">전송 실패</system:String>
<system:String x:Key="ExternalNotificationSendTest">테스트</system:String>

View File

@@ -39,7 +39,8 @@
<system:String x:Key="ExternalNotificationSettings">外部通知</system:String>
<system:String x:Key="ExternalNotificationEnabled">启用的通知配置</system:String>
<system:String x:Key="ExternalNotificationEnableDetails">输出详细信息</system:String>
<system:String x:Key="ExternalNotificationSendWhenError">任务出错时发送额外通知</system:String>
<system:String x:Key="ExternalNotificationSendWhenComplete">任务完成后发送通知</system:String>
<system:String x:Key="ExternalNotificationSendWhenError">任务出错时发送通知</system:String>
<system:String x:Key="ExternalNotificationSendSuccess">发送成功</system:String>
<system:String x:Key="ExternalNotificationSendFail">发送失败</system:String>
<system:String x:Key="ExternalNotificationSendTest">发送测试</system:String>

View File

@@ -39,7 +39,8 @@
<system:String x:Key="ExternalNotificationSettings">外部通知</system:String>
<system:String x:Key="ExternalNotificationEnabled">啟用的通知配置</system:String>
<system:String x:Key="ExternalNotificationEnableDetails">輸出詳細信息</system:String>
<system:String x:Key="ExternalNotificationSendWhenError">任務出錯時發送額外通知</system:String>
<system:String x:Key="ExternalNotificationSendWhenComplete">任務完成後發送通知</system:String>
<system:String x:Key="ExternalNotificationSendWhenError">任務出錯時發送通知</system:String>
<system:String x:Key="ExternalNotificationSendSuccess">發送成功</system:String>
<system:String x:Key="ExternalNotificationSendFail">發送失敗</system:String>
<system:String x:Key="ExternalNotificationSendTest">發送測試</system:String>

View File

@@ -44,6 +44,18 @@ public class ExternalNotificationSettingsUserControlModel : PropertyChangedBase
true);
}
private bool _externalNotificationSendWhenComplete = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.ExternalNotificationSendWhenComplete, bool.TrueString));
public bool ExternalNotificationSendWhenComplete
{
get => _externalNotificationSendWhenComplete;
set
{
SetAndNotify(ref _externalNotificationSendWhenComplete, value);
ConfigurationHelper.SetValue(ConfigurationKeys.ExternalNotificationSendWhenComplete, value.ToString());
}
}
private bool _externalNotificationEnableDetails = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.ExternalNotificationEnableDetails, bool.FalseString));
public bool ExternalNotificationEnableDetails
@@ -56,7 +68,7 @@ public class ExternalNotificationSettingsUserControlModel : PropertyChangedBase
}
}
private bool _externalNotificationSendWhenError = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.ExternalNotificationSendWhenError, bool.FalseString));
private bool _externalNotificationSendWhenError = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.ExternalNotificationSendWhenError, bool.TrueString));
public bool ExternalNotificationSendWhenError
{

View File

@@ -30,11 +30,11 @@
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<controls:TextBlock
<!--<controls:TextBlock
Grid.Row="0"
Margin="10"
Text="{DynamicResource ExternalNotificationTips}"
TextWrapping="Wrap" />
TextWrapping="Wrap" />-->
<StackPanel Grid.Row="1">
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
@@ -55,14 +55,25 @@
IsEnabled="{c:Binding 'EnabledExternalNotificationProviderCount > 0'}" />
</StackPanel>
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
<StackPanel HorizontalAlignment="Left" VerticalAlignment="Top">
<CheckBox
Margin="5"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Content="{DynamicResource ExternalNotificationSendWhenComplete}"
IsChecked="{Binding ExternalNotificationSendWhenComplete}" />
<CheckBox
Margin="20,5,5,5"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Content="{DynamicResource ExternalNotificationEnableDetails}"
IsChecked="{Binding ExternalNotificationEnableDetails}"
Visibility="{c:Binding ExternalNotificationSendWhenComplete}" />
</StackPanel>
<CheckBox
Margin="10"
HorizontalAlignment="Center"
Content="{DynamicResource ExternalNotificationEnableDetails}"
IsChecked="{Binding ExternalNotificationEnableDetails}" />
<CheckBox
Margin="10"
HorizontalAlignment="Center"
Margin="5"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Content="{DynamicResource ExternalNotificationSendWhenError}"
IsChecked="{Binding ExternalNotificationSendWhenError}" />
</StackPanel>