mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-19 18:47:55 +08:00
@@ -13,6 +13,7 @@ using System.Windows;
|
||||
using System.Windows.Threading;
|
||||
using Stylet;
|
||||
using StyletIoC;
|
||||
using Microsoft.Toolkit.Uwp.Notifications;
|
||||
|
||||
namespace MeoAsstGui
|
||||
{
|
||||
@@ -37,6 +38,8 @@ namespace MeoAsstGui
|
||||
protected override void OnExit(ExitEventArgs e)
|
||||
{
|
||||
// MessageBox.Show("O(∩_∩)O 拜拜");
|
||||
//关闭程序时清理操作中心中的通知
|
||||
ToastNotificationManagerCompat.History.Clear();
|
||||
ViewStatusStorage.Save();
|
||||
}
|
||||
|
||||
|
||||
@@ -25,11 +25,18 @@ using Notification.Wpf;
|
||||
using Notification.Wpf.Base;
|
||||
using Notification.Wpf.Constants;
|
||||
using Notification.Wpf.Controls;
|
||||
using Microsoft.Toolkit.Uwp.Notifications;
|
||||
|
||||
namespace MeoAsstGui
|
||||
{
|
||||
public class ToastNotification : IDisposable
|
||||
{
|
||||
|
||||
public bool CheckToastSystem()
|
||||
{
|
||||
return Convert.ToBoolean(ViewStatusStorage.Get("Toast.UsingSystem", bool.FalseString));
|
||||
}
|
||||
|
||||
private NotificationManager _notificationManager = new NotificationManager();
|
||||
|
||||
/// <summary>
|
||||
@@ -196,6 +203,17 @@ namespace MeoAsstGui
|
||||
|
||||
protected Action _buttonRightAction = null;
|
||||
|
||||
//系统按钮
|
||||
protected string _buttonSystemText = null;
|
||||
|
||||
protected string _buttonSystemUrl;
|
||||
public string ButtonSystemUrl
|
||||
{
|
||||
get { return _buttonSystemUrl; }
|
||||
set { _buttonSystemUrl = value; }
|
||||
}
|
||||
|
||||
protected bool _buttonSystemEnabled = Convert.ToBoolean(bool.FalseString);
|
||||
#endregion 通知按钮变量
|
||||
|
||||
/// <summary>
|
||||
@@ -208,6 +226,8 @@ namespace MeoAsstGui
|
||||
{
|
||||
_buttonLeftText = text;
|
||||
_buttonLeftAction = action;
|
||||
_buttonSystemText = text;
|
||||
_buttonSystemEnabled = Convert.ToBoolean(bool.TrueString);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -221,6 +241,8 @@ namespace MeoAsstGui
|
||||
{
|
||||
_buttonRightText = text;
|
||||
_buttonRightAction = action;
|
||||
_buttonSystemText = text;
|
||||
_buttonSystemEnabled = Convert.ToBoolean(bool.TrueString);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -294,35 +316,60 @@ namespace MeoAsstGui
|
||||
/// <param name="row">内容显示行数,如果内容太多建议使用 ShowMore()</param>
|
||||
/// <param name="sound">播放提示音</param>
|
||||
/// <param name="notificationContent">通知内容</param>
|
||||
///
|
||||
public void Show(double lifeTime = 10d, uint row = 1,
|
||||
NotificationSounds sound = NotificationSounds.Notification,
|
||||
NotificationContent notificationContent = null)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(ViewStatusStorage.Get("Toast.Position", NotificationPosition.BottomRight.ToString())))
|
||||
if (CheckToastSystem())
|
||||
{
|
||||
notificationContent = notificationContent ?? BaseContent();
|
||||
|
||||
notificationContent.RowsCount = row;
|
||||
|
||||
// 调整显示时间,如果存在按钮的情况下显示时间将强制设为最大时间
|
||||
lifeTime = lifeTime < 3d ? 3d : lifeTime;
|
||||
|
||||
var timeSpan = _buttonLeftAction == null && _buttonRightAction == null
|
||||
? TimeSpan.FromSeconds(lifeTime)
|
||||
: TimeSpan.MaxValue;
|
||||
|
||||
// 显示通知
|
||||
_notificationManager.Show(
|
||||
notificationContent,
|
||||
expirationTime: timeSpan,
|
||||
ShowXbtn: false);
|
||||
if (_buttonSystemEnabled)
|
||||
{
|
||||
Uri _burl = new Uri(_buttonSystemUrl);
|
||||
new ToastContentBuilder()
|
||||
.AddText(_notificationTitle)
|
||||
.AddText(_contentCollection.ToString())
|
||||
.AddButton(new ToastButton()
|
||||
.SetContent(_buttonSystemText)
|
||||
.SetProtocolActivation(_burl))
|
||||
.Show();
|
||||
}
|
||||
else
|
||||
{
|
||||
new ToastContentBuilder()
|
||||
.AddText(_notificationTitle)
|
||||
.AddText(_contentCollection.ToString())
|
||||
.Show();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(ViewStatusStorage.Get("Toast.Position", NotificationPosition.BottomRight.ToString())))
|
||||
{
|
||||
notificationContent = notificationContent ?? BaseContent();
|
||||
|
||||
// 播放通知提示音
|
||||
PlayNotificationSoundAsync(sound).Wait();
|
||||
notificationContent.RowsCount = row;
|
||||
|
||||
// 任务栏闪烁
|
||||
FlashWindowEx();
|
||||
// 调整显示时间,如果存在按钮的情况下显示时间将强制设为最大时间
|
||||
lifeTime = lifeTime < 3d ? 3d : lifeTime;
|
||||
|
||||
var timeSpan = _buttonLeftAction == null && _buttonRightAction == null
|
||||
? TimeSpan.FromSeconds(lifeTime)
|
||||
: TimeSpan.MaxValue;
|
||||
|
||||
// 显示通知
|
||||
_notificationManager.Show(
|
||||
notificationContent,
|
||||
expirationTime: timeSpan,
|
||||
ShowXbtn: false);
|
||||
}
|
||||
|
||||
// 播放通知提示音
|
||||
PlayNotificationSoundAsync(sound).Wait();
|
||||
|
||||
// 任务栏闪烁
|
||||
FlashWindowEx();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -390,10 +437,9 @@ namespace MeoAsstGui
|
||||
content.Background = (SolidColorBrush)new BrushConverter().ConvertFrom("#FF007280");
|
||||
|
||||
ShowMore(row: row,
|
||||
sound: NotificationSounds.Notification,
|
||||
notificationContent: content);
|
||||
sound: NotificationSounds.Notification,
|
||||
notificationContent: content);
|
||||
}
|
||||
|
||||
#endregion 显示通知方法
|
||||
|
||||
#endregion 通知显示
|
||||
|
||||
@@ -260,6 +260,9 @@
|
||||
<PackageReference Include="Microsoft.NETCore.Platforms">
|
||||
<Version>6.0.3</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications">
|
||||
<Version>7.1.2</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Win32.Primitives">
|
||||
<Version>4.3.0</Version>
|
||||
</PackageReference>
|
||||
|
||||
@@ -16,16 +16,16 @@
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
<RowDefinition Height="10*" />
|
||||
<RowDefinition Height="25*" />
|
||||
<RowDefinition Height="44*" />
|
||||
<RowDefinition Height="231*" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock
|
||||
Margin="5" HorizontalAlignment="Center" Block.TextAlignment="Center"
|
||||
Margin="0,5,0,5" HorizontalAlignment="Center" Block.TextAlignment="Center"
|
||||
Style="{StaticResource TextBlockDefault}" TextWrapping="Wrap"
|
||||
Text="通知显示的位置,默认显示在屏幕的右下角,全不勾选则只有通知声音" />
|
||||
Text="通知显示的位置,默认显示在屏幕的右下角,全不勾选则只有通知声音 使用系统推送通知时此设置无效" Grid.Row="1" Width="372" />
|
||||
|
||||
<Grid Grid.Row="1">
|
||||
<Grid Grid.Row="2">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition />
|
||||
@@ -56,38 +56,52 @@
|
||||
<CheckBox
|
||||
Grid.Row="0" Grid.Column="0" Margin="16" HorizontalAlignment="Left"
|
||||
VerticalAlignment="Top" Content="↖ 左上"
|
||||
IsChecked="{Binding ToastPositionTopLeft}" />
|
||||
IsChecked="{Binding ToastPositionTopLeft}"
|
||||
IsEnabled="{Binding ToastControl}"/>
|
||||
<CheckBox
|
||||
Grid.Row="1" Grid.Column="0" Margin="16" HorizontalAlignment="Left"
|
||||
VerticalAlignment="Center" Content="← 左边"
|
||||
IsChecked="{Binding ToastPositionCenterLeft}" />
|
||||
IsChecked="{Binding ToastPositionCenterLeft}"
|
||||
IsEnabled="{Binding ToastControl}"/>
|
||||
<CheckBox
|
||||
Grid.Row="2" Grid.Column="0" Margin="16" HorizontalAlignment="Left"
|
||||
VerticalAlignment="Bottom" Content="↙ 左下"
|
||||
IsChecked="{Binding ToastPositionBottomLeft}" />
|
||||
IsChecked="{Binding ToastPositionBottomLeft}"
|
||||
IsEnabled="{Binding ToastControl}"/>
|
||||
|
||||
<CheckBox
|
||||
Grid.Row="0" Grid.Column="1" Margin="16" HorizontalAlignment="Center"
|
||||
VerticalAlignment="Top" Content="↑ 上边"
|
||||
IsChecked="{Binding ToastPositionTopCenter}" />
|
||||
IsChecked="{Binding ToastPositionTopCenter}"
|
||||
IsEnabled="{Binding ToastControl}"/>
|
||||
<CheckBox
|
||||
Grid.Row="2" Grid.Column="1" Margin="16" HorizontalAlignment="Center"
|
||||
VerticalAlignment="Bottom" Content="↓ 下边"
|
||||
IsChecked="{Binding ToastPositionBottomCenter}" />
|
||||
IsChecked="{Binding ToastPositionBottomCenter}"
|
||||
IsEnabled="{Binding ToastControl}"/>
|
||||
|
||||
<CheckBox
|
||||
Grid.Row="0" Grid.Column="2" Margin="16" HorizontalAlignment="Right"
|
||||
VerticalAlignment="Top" Content="↗ 右上"
|
||||
IsChecked="{Binding ToastPositionTopRight}" />
|
||||
IsChecked="{Binding ToastPositionTopRight}"
|
||||
IsEnabled="{Binding ToastControl}"/>
|
||||
<CheckBox
|
||||
Grid.Row="1" Grid.Column="2" Margin="16" HorizontalAlignment="Right"
|
||||
VerticalAlignment="Center" Content="→ 右边"
|
||||
IsChecked="{Binding ToastPositionCenterRight}" />
|
||||
IsChecked="{Binding ToastPositionCenterRight}"
|
||||
IsEnabled="{Binding ToastControl}"/>
|
||||
<CheckBox
|
||||
Grid.Row="2" Grid.Column="2" Margin="16" HorizontalAlignment="Right"
|
||||
VerticalAlignment="Bottom" Content="↘ 右下"
|
||||
IsChecked="{Binding ToastPositionBottomRight}" />
|
||||
IsChecked="{Binding ToastPositionBottomRight}"
|
||||
IsEnabled="{Binding ToastControl}"/>
|
||||
</Grid>
|
||||
<CheckBox
|
||||
x:Name="usesystemnote" Content="使用Windows系统推送通知(支持Win10/Win11)" HorizontalAlignment="Left"
|
||||
Margin="10,0,0,0" VerticalAlignment="Center"
|
||||
IsChecked="{Binding ToastUsingSystem}"
|
||||
IsEnabled="{Binding ToastOS}"
|
||||
Height="20" Width="450"/>
|
||||
</Grid>
|
||||
|
||||
<Button
|
||||
|
||||
@@ -569,6 +569,53 @@ namespace MeoAsstGui
|
||||
|
||||
#region 通知显示
|
||||
|
||||
//是否使用系统通知
|
||||
private bool _toastUsingSystem = Convert.ToBoolean(ViewStatusStorage.Get("Toast.UsingSystem", bool.FalseString));
|
||||
private bool _toastControl = Convert.ToBoolean(bool.TrueString);
|
||||
private bool _toastOS = Convert.ToBoolean(bool.TrueString);
|
||||
public bool toastOScheck()
|
||||
{
|
||||
var os = RuntimeInformation.OSDescription.ToString();
|
||||
if (os.ToString().CompareTo("Microsoft Windows 10.0.10240") >= 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ViewStatusStorage.Set("Toast.UsingSystem", bool.FalseString);
|
||||
ToastUsingSystem = false;
|
||||
ToastControl = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public bool ToastOS
|
||||
{
|
||||
get { return toastOScheck(); }
|
||||
set
|
||||
{
|
||||
SetAndNotify(ref _toastOS, value);
|
||||
}
|
||||
}
|
||||
public bool ToastControl
|
||||
{
|
||||
get { return !_toastUsingSystem; }
|
||||
set
|
||||
{
|
||||
SetAndNotify(ref _toastControl, value);
|
||||
}
|
||||
}
|
||||
public bool ToastUsingSystem
|
||||
{
|
||||
get { return _toastUsingSystem; }
|
||||
set
|
||||
{
|
||||
SetAndNotify(ref _toastUsingSystem, value);
|
||||
ToastControl = !Convert.ToBoolean(value);
|
||||
ViewStatusStorage.Set("Toast.UsingSystem", value.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
//不使用系统通知时的设置
|
||||
// 左上
|
||||
private bool _toastPositionTopLeft = ViewStatusStorage.Get("Toast.Position", string.Empty) == NotificationPosition.TopLeft.ToString();
|
||||
|
||||
@@ -826,7 +873,7 @@ namespace MeoAsstGui
|
||||
using (var toast = new ToastNotification("通知显示位置测试"))
|
||||
{
|
||||
toast.AppendContentText("如果选择了新的位置")
|
||||
.AppendContentText("请先点掉这个通知再测试").Show(lifeTime: 5, row: 2);
|
||||
.AppendContentText("请先点掉这个通知再测试").Show(lifeTime: 5, row: 3);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -76,6 +76,18 @@ namespace MeoAsstGui
|
||||
}
|
||||
}
|
||||
|
||||
private string _updateUrl;
|
||||
public string UpdateUrl
|
||||
{
|
||||
get
|
||||
{
|
||||
return _updateUrl;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetAndNotify(ref _updateUrl, value);
|
||||
}
|
||||
}
|
||||
public FlowDocument UpdateInfoDocument
|
||||
{
|
||||
get
|
||||
@@ -123,7 +135,6 @@ namespace MeoAsstGui
|
||||
/// 检查是否有已下载的更新包,如果有立即更新并重启进程
|
||||
/// </summary>
|
||||
/// <returns>操作成功返回 true,反之则返回 false</returns>
|
||||
|
||||
public bool CheckAndUpdateNow()
|
||||
{
|
||||
if (UpdateTag == string.Empty
|
||||
@@ -233,6 +244,8 @@ namespace MeoAsstGui
|
||||
UpdatePackageName = _assetsObject["name"].ToString();
|
||||
UpdateTag = _lastestJson["name"].ToString();
|
||||
UpdateInfo = _lastestJson["body"].ToString();
|
||||
UpdateUrl = _lastestJson["html_url"].ToString();
|
||||
//ToastNotification.get= _lastestJson["html_url"].ToString();
|
||||
|
||||
var openUrlToastButton = (
|
||||
text: "前往页面查看",
|
||||
@@ -251,6 +264,7 @@ namespace MeoAsstGui
|
||||
{
|
||||
using (var toast = new ToastNotification("检测到新版本"))
|
||||
{
|
||||
toast.ButtonSystemUrl = UpdateUrl;
|
||||
toast.AppendContentText("正在后台下载……")
|
||||
.AppendContentText("新版本: " + UpdateTag)
|
||||
.AppendContentText("更新信息: " + UpdateInfo)
|
||||
@@ -265,6 +279,7 @@ namespace MeoAsstGui
|
||||
{
|
||||
using (var toast = new ToastNotification("检测到新版本"))
|
||||
{
|
||||
toast.ButtonSystemUrl = UpdateUrl;
|
||||
toast.AppendContentText("新版本: " + UpdateTag)
|
||||
.AppendContentText("更新信息: " + UpdateInfo)
|
||||
.AddButtonLeft(openUrlToastButton.text, openUrlToastButton.action)
|
||||
@@ -295,6 +310,7 @@ namespace MeoAsstGui
|
||||
{
|
||||
using (var toast = new ToastNotification("新版本下载失败"))
|
||||
{
|
||||
toast.ButtonSystemUrl = UpdateUrl;
|
||||
toast.AppendContentText("请尝试手动下载后,将压缩包放到目录下_(:з」∠)_")
|
||||
.AddButtonLeft(openUrlToastButton.text, openUrlToastButton.action)
|
||||
.Show();
|
||||
@@ -310,7 +326,7 @@ namespace MeoAsstGui
|
||||
{
|
||||
toast.AppendContentText("软件将在下次启动时自动更新!")
|
||||
.AppendContentText("✿✿ヽ(°▽°)ノ✿")
|
||||
.ShowUpdateVersion(row: 2);
|
||||
.ShowUpdateVersion(row: 3);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -324,7 +340,7 @@ namespace MeoAsstGui
|
||||
|
||||
public bool CheckUpdate()
|
||||
{
|
||||
// 开发版不检查更新
|
||||
//开发版不检查更新
|
||||
if (!isStableVersion())
|
||||
{
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user