Skip to content

Commit 86676d5

Browse files
committed
[feat] 更新内容预览
1 parent efd4cfc commit 86676d5

File tree

5 files changed

+139
-4
lines changed

5 files changed

+139
-4
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<ContentDialog
2+
x:Class="FluentWeather.Uwp.Controls.Dialogs.UpdateDialog"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="using:FluentWeather.Uwp.Controls.Dialogs"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
9+
xmlns:app="using:FluentWeather.Uwp.Shared"
10+
mc:Ignorable="d"
11+
SecondaryButtonText="查看"
12+
PrimaryButtonStyle="{ThemeResource AccentButtonStyle}"
13+
PrimaryButtonClick="ContentDialog_PrimaryButtonClick"
14+
PrimaryButtonText="下载"
15+
CloseButtonText="取消"
16+
SecondaryButtonClick="ContentDialog_SecondaryButtonClick"
17+
RequestedTheme="{x:Bind app:Common.Settings.ApplicationTheme}"
18+
Style="{ThemeResource DefaultContentDialogStyle}">
19+
<ContentDialog.Title>
20+
<TextBlock>
21+
<Run Text="更新"/>
22+
<Run Text="{x:Bind UpdateInfo.TagName,Mode=OneWay}" Foreground="{ThemeResource SystemControlForegroundBaseMediumBrush}"/>
23+
</TextBlock>
24+
25+
</ContentDialog.Title>
26+
27+
<ScrollViewer>
28+
<controls:MarkdownTextBlock Background="Transparent" LinkClicked="MarkdownTextBlock_LinkClicked" Text="{x:Bind UpdateInfo.Changelog,Mode=OneWay}"/>
29+
</ScrollViewer>
30+
</ContentDialog>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using FluentWeather.Uwp.Helpers.Update;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using System.Linq;
6+
using System.Runtime.InteropServices.WindowsRuntime;
7+
using Windows.Foundation;
8+
using Windows.Foundation.Collections;
9+
using Windows.System;
10+
using Windows.UI.Xaml;
11+
using Windows.UI.Xaml.Controls;
12+
using Windows.UI.Xaml.Controls.Primitives;
13+
using Windows.UI.Xaml.Data;
14+
using Windows.UI.Xaml.Input;
15+
using Windows.UI.Xaml.Media;
16+
using Windows.UI.Xaml.Navigation;
17+
18+
// https://go.microsoft.com/fwlink/?LinkId=234238 上介绍了“内容对话框”项模板
19+
20+
namespace FluentWeather.Uwp.Controls.Dialogs
21+
{
22+
public sealed partial class UpdateDialog : ContentDialog
23+
{
24+
public UpdateDialog(UpdateInfo updateInfo)
25+
{
26+
this.InitializeComponent();
27+
this.UpdateInfo = updateInfo;
28+
}
29+
30+
public UpdateInfo UpdateInfo
31+
{
32+
get => (UpdateInfo)GetValue(UpdateInfoProperty);
33+
set => SetValue(UpdateInfoProperty, value);
34+
}
35+
36+
// Using a DependencyProperty as the backing store for UpdateInfo. This enables animation, styling, binding, etc...
37+
public static readonly DependencyProperty UpdateInfoProperty =
38+
DependencyProperty.Register(nameof(UpdateInfo), typeof(UpdateInfo), typeof(UpdateDialog), new PropertyMetadata(default));
39+
40+
private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
41+
{
42+
Launcher.LaunchUriAsync(new Uri("https://wwxk.lanzouj.com/b02x4kddg"));
43+
}
44+
45+
private void ContentDialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
46+
{
47+
Launcher.LaunchUriAsync(new Uri(UpdateInfo.HtmlUrl));
48+
}
49+
50+
private void MarkdownTextBlock_LinkClicked(object sender, Microsoft.Toolkit.Uwp.UI.Controls.LinkClickedEventArgs e)
51+
{
52+
Launcher.LaunchUriAsync(new Uri(e.Link));
53+
}
54+
}
55+
}

FluentWeather.Uwp/Controls/Settings/UpdateSettingSection.xaml.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using CommunityToolkit.WinUI.Helpers;
2121
using Microsoft.AppCenter.Analytics;
2222
using System.Security.Cryptography.X509Certificates;
23+
using FluentWeather.Uwp.Controls.Dialogs;
2324

2425
//https://go.microsoft.com/fwlink/?LinkId=234236 上介绍了“用户控件”项模板
2526

@@ -41,15 +42,15 @@ private async void CheckUpdateButton_Click(object sender, RoutedEventArgs e)
4142
var info = await UpdateHelper.CheckUpdateAsync("zxbmmmmmmmmm", "FluentWeather", new Version(versionString));
4243
var viewAction = new Action(() =>
4344
{
44-
Launcher.LaunchUriAsync(new Uri(info.HtmlUrl));
45+
new UpdateDialog(info).ShowAsync();
4546
});
4647
if (info.IsExistNewVersion)
4748
{
4849
InfoBarHelper.Info("更新可用", info.TagName, action: viewAction, buttonContent: "查看");
4950
}
5051
else
5152
{
52-
InfoBarHelper.Success("应用为最新版本", versionString);
53+
InfoBarHelper.Success("应用为最新版本", versionString, action: viewAction, buttonContent: "查看");
5354
}
5455
}
5556
catch (Exception ex)

FluentWeather.Uwp/FluentWeather.Uwp.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@
157157
<Compile Include="Controls\Dialogs\TyphoonDialog.xaml.cs">
158158
<DependentUpon>TyphoonDialog.xaml</DependentUpon>
159159
</Compile>
160+
<Compile Include="Controls\Dialogs\UpdateDialog.xaml.cs">
161+
<DependentUpon>UpdateDialog.xaml</DependentUpon>
162+
</Compile>
160163
<Compile Include="Controls\HourlyTemperatureChart.xaml.cs">
161164
<DependentUpon>HourlyTemperatureChart.xaml</DependentUpon>
162165
</Compile>
@@ -445,6 +448,10 @@
445448
<SubType>Designer</SubType>
446449
<Generator>MSBuild:Compile</Generator>
447450
</Page>
451+
<Page Include="Controls\Dialogs\UpdateDialog.xaml">
452+
<SubType>Designer</SubType>
453+
<Generator>MSBuild:Compile</Generator>
454+
</Page>
448455
<Page Include="Controls\HourlyTemperatureChart.xaml">
449456
<SubType>Designer</SubType>
450457
<Generator>MSBuild:Compile</Generator>

FluentWeather.Uwp/Helpers/InfoBarHelper.cs

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,52 @@ public static void Info(string title, string message, int delay = 5000, bool isC
7272
}
7373
});
7474
}
75-
public static void Success(string title, string message, int delay = 5000, bool isClosable = true)
75+
public static void Success(string title, string message, int delay = 5000, bool isClosable = true, string buttonContent = null, Action action = null)
7676
{
77-
AddToContainer(InfoBarSeverity.Success, title, message, delay, isClosable);
77+
DispatcherQueue.GetForCurrentThread().TryEnqueue(async () =>
78+
{
79+
var infoBar = new InfoBar
80+
{
81+
Severity = InfoBarSeverity.Success,
82+
Title = title,
83+
Message = message,
84+
IsOpen = true,
85+
IsClosable = isClosable,
86+
};
87+
if (action is not null)
88+
{
89+
var btn = new Button
90+
{
91+
Content = buttonContent,
92+
HorizontalAlignment = HorizontalAlignment.Right,
93+
};
94+
btn.Click += (_, _) =>
95+
{
96+
try
97+
{
98+
action();
99+
}
100+
catch (Exception ex)
101+
{
102+
Common.LogManager.GetLogger(("InfoBarHelper")).Error($"{title} - {message} - {buttonContent}", ex);
103+
}
104+
};
105+
infoBar.ActionButton = btn;
106+
}
107+
_container.Children.Add(infoBar);
108+
if (delay > 0)
109+
{
110+
111+
await Task.Delay(delay);
112+
infoBar.IsOpen = false;
113+
}
114+
});
78115
}
116+
117+
//public static void Success(string title, string message, int delay = 5000, bool isClosable = true)
118+
//{
119+
// AddToContainer(InfoBarSeverity.Success, title, message, delay, isClosable);
120+
//}
79121
public static void Warning(string title, string message, int delay = 5000, bool isClosable = true)
80122
{
81123
AddToContainer(InfoBarSeverity.Warning, title, message, delay, isClosable);

0 commit comments

Comments
 (0)