通知结构修改,增加退出时清空消息功能

This commit is contained in:
cgl
2022-06-03 16:28:51 +08:00
parent 5cbb2bef00
commit fca1625a3e
6 changed files with 171 additions and 163 deletions

View File

@@ -190,7 +190,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>

View File

@@ -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();
}

View File

@@ -26,10 +26,10 @@ namespace MeoAsstGui
public class AsstProxy
{
public bool CheckToastSystem()
{
return Convert.ToBoolean(ViewStatusStorage.Get("Toast.UsingSystem", bool.FalseString));
}
//public bool CheckToastSystem()
//{
// return Convert.ToBoolean(ViewStatusStorage.Get("Toast.UsingSystem", bool.FalseString));
//}
private delegate void CallbackDelegate(int msg, IntPtr json_buffer, IntPtr custom_arg);
private delegate void ProcCallbckMsg(AsstMsg msg, JObject details);
@@ -215,11 +215,10 @@ namespace MeoAsstGui
mainModel.Idle = true;
mainModel.AddLog("任务已全部完成");
mainModel.UseStone = false;
if (CheckToastSystem()) new ToastContentBuilder().AddText("任务已全部完成!").Show();
else using (var toast = new ToastNotification("任务已全部完成!"))
{
toast.Show();
}
using (var toast = new ToastNotification("任务已全部完成!"))
{
toast.Show();
}
mainModel.CheckAndShutdown();
break;
}
@@ -445,11 +444,10 @@ namespace MeoAsstGui
case "RecruitSpecialTag":
{
string special = subTaskDetails["tag"].ToString();
if (CheckToastSystem()) new ToastContentBuilder().AddText("公招提示").Show();
else using (var toast = new ToastNotification("公招提示"))
{
toast.AppendContentText(special).ShowRecruit();
}
using (var toast = new ToastNotification("公招提示"))
{
toast.AppendContentText(special).ShowRecruit();
}
}
break;
@@ -458,11 +456,10 @@ namespace MeoAsstGui
int level = (int)subTaskDetails["level"];
if (level >= 5)
{
if (CheckToastSystem()) new ToastContentBuilder().AddText("公招提示").AddText($"公招出{level}星了哦!").Show();
else using (var toast = new ToastNotification($"公招出 {level} 星了哦!"))
{
toast.AppendContentText(new string('★', level)).ShowRecruit(row: 2);
}
using (var toast = new ToastNotification($"公招出 {level} 星了哦!"))
{
toast.AppendContentText(new string('★', level)).ShowRecruit(row: 2);
}
mainModel.AddLog(level + " 星 Tags", "darkorange", "Bold");
}
else
@@ -573,11 +570,10 @@ namespace MeoAsstGui
case "RecruitSpecialTag":
{
string special = subTaskDetails["tag"].ToString();
if (CheckToastSystem()) new ToastContentBuilder().AddText("公招提示").Show();
else using (var toast = new ToastNotification("公招提示"))
{
toast.AppendContentText(special).ShowRecruit();
}
using (var toast = new ToastNotification("公招提示"))
{
toast.AppendContentText(special).ShowRecruit();
}
}
break;
@@ -604,11 +600,10 @@ namespace MeoAsstGui
recruitModel.RecruitResult = resultContent;
if (level >= 5)
{
if (CheckToastSystem()) new ToastContentBuilder().AddText("公招提示").AddText($"公招出 {level} 星了哦!").Show();
else using (var toast = new ToastNotification($"公招出 {level} 星了哦!"))
{
toast.AppendContentText(new string('★', level)).ShowRecruit(row: 2);
}
using (var toast = new ToastNotification($"公招出 {level} 星了哦!"))
{
toast.AppendContentText(new string('★', level)).ShowRecruit(row: 2);
}
}
}
break;

View File

@@ -31,6 +31,12 @@ namespace MeoAsstGui
{
public class ToastNotification : IDisposable
{
public bool CheckToastSystem()
{
return Convert.ToBoolean(ViewStatusStorage.Get("Toast.UsingSystem", bool.FalseString));
}
private NotificationManager _notificationManager = new NotificationManager();
/// <summary>
@@ -197,6 +203,12 @@ namespace MeoAsstGui
protected Action _buttonRightAction = null;
//系统按钮
protected string _buttonSystemText = null;
protected string _buttonSystemUrl = ViewStatusStorage.Get("VersionUpdate.url", string.Empty);
protected bool _buttonSystemEnabled = Convert.ToBoolean(bool.FalseString);
#endregion
/// <summary>
@@ -209,6 +221,8 @@ namespace MeoAsstGui
{
_buttonLeftText = text;
_buttonLeftAction = action;
_buttonSystemText = text;
_buttonSystemEnabled = Convert.ToBoolean(bool.TrueString);
return this;
}
@@ -222,6 +236,8 @@ namespace MeoAsstGui
{
_buttonRightText = text;
_buttonRightAction = action;
_buttonSystemText = text;
_buttonSystemEnabled = Convert.ToBoolean(bool.TrueString);
return this;
}
@@ -295,35 +311,44 @@ 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())
new ToastContentBuilder()
.AddText(_notificationTitle)
.AddText(_contentCollection.ToString())
.Show();
else
{
notificationContent = notificationContent ?? BaseContent();
if (!string.IsNullOrWhiteSpace(ViewStatusStorage.Get("Toast.Position", NotificationPosition.BottomRight.ToString())))
{
notificationContent = notificationContent ?? BaseContent();
notificationContent.RowsCount = row;
notificationContent.RowsCount = row;
// 调整显示时间,如果存在按钮的情况下显示时间将强制设为最大时间
lifeTime = lifeTime < 3d ? 3d : lifeTime;
// 调整显示时间,如果存在按钮的情况下显示时间将强制设为最大时间
lifeTime = lifeTime < 3d ? 3d : lifeTime;
var timeSpan = _buttonLeftAction == null && _buttonRightAction == null
? TimeSpan.FromSeconds(lifeTime)
: TimeSpan.MaxValue;
var timeSpan = _buttonLeftAction == null && _buttonRightAction == null
? TimeSpan.FromSeconds(lifeTime)
: TimeSpan.MaxValue;
// 显示通知
_notificationManager.Show(
notificationContent,
expirationTime: timeSpan,
ShowXbtn: false);
// 显示通知
_notificationManager.Show(
notificationContent,
expirationTime: timeSpan,
ShowXbtn: false);
}
// 播放通知提示音
PlayNotificationSoundAsync(sound).Wait();
// 任务栏闪烁
FlashWindowEx();
}
// 播放通知提示音
PlayNotificationSoundAsync(sound).Wait();
// 任务栏闪烁
FlashWindowEx();
}
/// <summary>
@@ -369,15 +394,38 @@ namespace MeoAsstGui
/// <param name="row">内容行数</param>
public void ShowUpdateVersion(uint row = 3)
{
var content = BaseContent();
Uri _burl = new Uri(_buttonSystemUrl);
if (CheckToastSystem())
{
if (_buttonSystemEnabled)
{
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
{
var content = BaseContent();
content.Background = (SolidColorBrush)new BrushConverter().ConvertFrom("#FF007280");
content.Background = (SolidColorBrush)new BrushConverter().ConvertFrom("#FF007280");
ShowMore(row: row,
sound: NotificationSounds.Notification,
notificationContent: content);
ShowMore(row: row,
sound: NotificationSounds.Notification,
notificationContent: content);
}
}
#endregion
#endregion

View File

@@ -559,6 +559,8 @@ namespace MeoAsstGui
/* 通知显示设置 */
#region
//是否使用系统通知
private bool _toastUsingSystem = Convert.ToBoolean(ViewStatusStorage.Get("Toast.UsingSystem", bool.FalseString));
public bool ToastUsingSystem
{
@@ -570,6 +572,7 @@ namespace MeoAsstGui
}
}
//不使用系统通知时的设置
// 左上
private bool _toastPositionTopLeft = ViewStatusStorage.Get("Toast.Position", string.Empty) == NotificationPosition.TopLeft.ToString();

View File

@@ -77,6 +77,20 @@ namespace MeoAsstGui
}
}
private string _updateUrl = ViewStatusStorage.Get("VersionUpdate.url", string.Empty);
public string UpdateUrl
{
get
{
return _updateUrl;
}
set
{
SetAndNotify(ref _updateUrl, value);
ViewStatusStorage.Set("VersionUpdate.url", value);
}
}
public FlowDocument UpdateInfoDocument
{
get
@@ -124,10 +138,10 @@ namespace MeoAsstGui
/// 检查是否有已下载的更新包,如果有立即更新并重启进程
/// </summary>
/// <returns>操作成功返回 true反之则返回 false</returns>
public bool CheckToastSystem()
{
return Convert.ToBoolean(ViewStatusStorage.Get("Toast.UsingSystem", bool.FalseString));
}
//public bool CheckToastSystem()
//{
// return Convert.ToBoolean(ViewStatusStorage.Get("Toast.UsingSystem", bool.FalseString));
//}
public bool CheckAndUpdateNow()
{
if (UpdateTag == string.Empty
@@ -139,18 +153,12 @@ namespace MeoAsstGui
Execute.OnUIThread(() =>
{
if (CheckToastSystem())
new ToastContentBuilder()
.AddText("检测到新版本包")
.AddText("正在解压,请稍等……")
.Show();
else
using (var toast = new ToastNotification("检测到新版本包"))
{
toast.AppendContentText("正在解压,请稍等……")
.AppendContentText(UpdateTag)
.ShowUpdateVersion(row: 2);
}
using (var toast = new ToastNotification("检测到新版本包"))
{
toast.AppendContentText("正在解压,请稍等……")
.AppendContentText(UpdateTag)
.ShowUpdateVersion(row: 2);
}
});
string extractDir = Directory.GetCurrentDirectory() + "\\NewVersionExtract";
@@ -168,19 +176,12 @@ namespace MeoAsstGui
File.Delete(UpdatePackageName);
Execute.OnUIThread(() =>
{
if (CheckToastSystem())
new ToastContentBuilder()
.AddText("更新文件不正确!")
.AddText("文件名: " + UpdatePackageName)
.AddText("已将其删除!")
.Show();
else
using (var toast = new ToastNotification("更新文件不正确!"))
{
toast.AppendContentText("文件名: " + UpdatePackageName)
.AppendContentText("已将其删除!")
.ShowUpdateVersion();
}
using (var toast = new ToastNotification("更新文件不正确!"))
{
toast.AppendContentText("文件名: " + UpdatePackageName)
.AppendContentText("已将其删除!")
.ShowUpdateVersion();
}
});
return false;
}
@@ -250,6 +251,7 @@ namespace MeoAsstGui
UpdatePackageName = _assetsObject["name"].ToString();
UpdateTag = _lastestJson["name"].ToString();
UpdateInfo = _lastestJson["body"].ToString();
UpdateUrl = _lastestJson["html_url"].ToString();
var openUrlToastButton = (
text: "前往页面查看",
@@ -266,48 +268,27 @@ namespace MeoAsstGui
{
Execute.OnUIThread(() =>
{
Uri up_uri = new Uri(_lastestJson["html_url"].ToString());
if (CheckToastSystem())
new ToastContentBuilder()
.AddText("检测到新版本")
.AddText("正在后台下载……")
.AddText("新版本: " + UpdateTag)
.AddButton(new ToastButton()
.SetContent(openUrlToastButton.text)
.SetProtocolActivation(up_uri)
)
.Show();
else
using (var toast = new ToastNotification("检测到新版本"))
{
toast.AppendContentText("正在后台下载……")
.AppendContentText("新版本: " + UpdateTag)
.AppendContentText("更新信息: " + UpdateInfo)
.AddButtonLeft(openUrlToastButton.text, openUrlToastButton.action)
.ShowUpdateVersion();
}
using (var toast = new ToastNotification("检测到新版本"))
{
toast.AppendContentText("正在后台下载……")
.AppendContentText("新版本: " + UpdateTag)
.AppendContentText("更新信息: " + UpdateInfo)
.AddButtonLeft(openUrlToastButton.text, openUrlToastButton.action)
.ShowUpdateVersion();
}
});
}
else
{
Execute.OnUIThread(() =>
{
if (CheckToastSystem())
new ToastContentBuilder()
.AddText("检测到新版本", hintMaxLines: 1)
.AddText("新版本: " + UpdateTag)
.AddButton(new ToastButton()
.SetContent(openUrlToastButton.text)
.AddArgument("action", openUrlToastButton.action.ToString()))
.Show();
else
using (var toast = new ToastNotification("检测到新版本"))
{
toast.AppendContentText("新版本: " + UpdateTag)
.AppendContentText("更新信息: " + UpdateInfo)
.AddButtonLeft(openUrlToastButton.text, openUrlToastButton.action)
.ShowUpdateVersion();
}
using (var toast = new ToastNotification("检测到新版本"))
{
toast.AppendContentText("新版本: " + UpdateTag)
.AppendContentText("更新信息: " + UpdateInfo)
.AddButtonLeft(openUrlToastButton.text, openUrlToastButton.action)
.ShowUpdateVersion();
}
});
return false;
}
@@ -329,44 +310,28 @@ namespace MeoAsstGui
if (!downloaded)
{
if (CheckToastSystem())
new ToastContentBuilder()
.AddText("新版本下载失败", hintMaxLines: 1)
.AddAttributionText("请尝试手动下载后将压缩包放到目录下_(:з」∠)_")
.AddButton(new ToastButton()
.SetContent(openUrlToastButton.text)
.AddArgument("action", openUrlToastButton.action.ToString()))
.Show();
else
Execute.OnUIThread(() =>
Execute.OnUIThread(() =>
{
using (var toast = new ToastNotification("新版本下载失败"))
{
using (var toast = new ToastNotification("新版本下载失败"))
{
toast.AppendContentText("请尝试手动下载后将压缩包放到目录下_(:з」∠)_")
.AddButtonLeft(openUrlToastButton.text, openUrlToastButton.action)
.Show();
}
});
toast.AppendContentText("请尝试手动下载后将压缩包放到目录下_(:з」∠)_")
.AddButtonLeft(openUrlToastButton.text, openUrlToastButton.action)
.Show();
}
});
return false;
}
// 把相关信息存下来,更新完之后启动的时候显示
Execute.OnUIThread(() =>
{
if (CheckToastSystem())
new ToastContentBuilder()
.AddText("新版本下载完成", hintMaxLines: 1)
.AddText("软件将在下次启动时自动更新!")
.AddText("✿✿ヽ(°▽°)ノ✿")
.Show();
else
using (var toast = new ToastNotification("新版本下载完成"))
{
using (var toast = new ToastNotification("新版本下载完成"))
{
toast.AppendContentText("软件将在下次启动时自动更新!")
.AppendContentText("✿✿ヽ(°▽°)ノ✿")
.ShowUpdateVersion(row: 2);
}
toast.AppendContentText("软件将在下次启动时自动更新!")
.AppendContentText("✿✿ヽ(°▽°)ノ✿")
.ShowUpdateVersion(row: 2);
}
});
return true;
@@ -379,7 +344,7 @@ namespace MeoAsstGui
public bool CheckUpdate()
{
// 开发版不检查更新
//开发版不检查更新
if (!isStableVersion())
{
return false;
@@ -774,18 +739,12 @@ namespace MeoAsstGui
Execute.OnUIThread(() =>
{
if (CheckToastSystem())
new ToastContentBuilder()
.AddText("资源已更新")
.AddText("重启软件生效!")
.Show();
else
using (var toast = new ToastNotification("资源已更新"))
{
toast.AppendContentText("重启软件生效!")
.AppendContentText(message)
.ShowUpdateVersion();
}
using (var toast = new ToastNotification("资源已更新"))
{
toast.AppendContentText("重启软件生效!")
.AppendContentText(message)
.ShowUpdateVersion();
}
});
return true;