改变UpdateUrl和show的处理方式

This commit is contained in:
cglcv
2022-06-04 15:42:57 +08:00
parent c0b9ff7209
commit d2ec527886
2 changed files with 64 additions and 61 deletions

View File

@@ -206,7 +206,12 @@ namespace MeoAsstGui
//系统按钮
protected string _buttonSystemText = null;
protected string _buttonSystemUrl = ViewStatusStorage.Get("VersionUpdate.url", string.Empty);
protected string _buttonSystemUrl;
public string ButtonSystemUrl
{
get { return _buttonSystemUrl; }
set { _buttonSystemUrl = value; }
}
protected bool _buttonSystemEnabled = Convert.ToBoolean(bool.FalseString);
#endregion
@@ -317,38 +322,55 @@ namespace MeoAsstGui
NotificationContent notificationContent = null)
{
if (CheckToastSystem())
new ToastContentBuilder()
.AddText(_notificationTitle)
.AddText(_contentCollection.ToString())
.Show();
else
{
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>
@@ -394,37 +416,13 @@ namespace MeoAsstGui
/// <param name="row">内容行数</param>
public void ShowUpdateVersion(uint row = 3)
{
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();
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

View File

@@ -76,15 +76,16 @@ namespace MeoAsstGui
}
}
private string _updateUrl;
public string UpdateUrl
{
get
{
return ViewStatusStorage.Get("VersionUpdate.url", string.Empty);
return _updateUrl;
}
set
{
ViewStatusStorage.Set("VersionUpdate.url", value);
SetAndNotify(ref _updateUrl, value);
}
}
public FlowDocument UpdateInfoDocument
@@ -244,6 +245,7 @@ namespace MeoAsstGui
UpdateTag = _lastestJson["name"].ToString();
UpdateInfo = _lastestJson["body"].ToString();
UpdateUrl = _lastestJson["html_url"].ToString();
//ToastNotification.get= _lastestJson["html_url"].ToString();
var openUrlToastButton = (
text: "前往页面查看",
@@ -262,6 +264,7 @@ namespace MeoAsstGui
{
using (var toast = new ToastNotification("检测到新版本"))
{
toast.ButtonSystemUrl = UpdateUrl;
toast.AppendContentText("正在后台下载……")
.AppendContentText("新版本: " + UpdateTag)
.AppendContentText("更新信息: " + UpdateInfo)
@@ -276,6 +279,7 @@ namespace MeoAsstGui
{
using (var toast = new ToastNotification("检测到新版本"))
{
toast.ButtonSystemUrl = UpdateUrl;
toast.AppendContentText("新版本: " + UpdateTag)
.AppendContentText("更新信息: " + UpdateInfo)
.AddButtonLeft(openUrlToastButton.text, openUrlToastButton.action)
@@ -306,6 +310,7 @@ namespace MeoAsstGui
{
using (var toast = new ToastNotification("新版本下载失败"))
{
toast.ButtonSystemUrl = UpdateUrl;
toast.AppendContentText("请尝试手动下载后将压缩包放到目录下_(:з」∠)_")
.AddButtonLeft(openUrlToastButton.text, openUrlToastButton.action)
.Show();
@@ -321,7 +326,7 @@ namespace MeoAsstGui
{
toast.AppendContentText("软件将在下次启动时自动更新!")
.AppendContentText("✿✿ヽ(°▽°)ノ✿")
.ShowUpdateVersion(row: 2);
.ShowUpdateVersion(row: 3);
}
});