Skip to content

Commit ef0b961

Browse files
committed
1.更新WindowsAppSDK到1.8.251003001;
2.应用通知改用 AppNotificationBuilder,而不是XML,防止意外崩溃; 3.当应用崩溃时弹窗提醒,并可导航到日志目录。
1 parent 67dec7e commit ef0b961

File tree

4 files changed

+22
-21
lines changed

4 files changed

+22
-21
lines changed

MyTools/App.xaml.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Microsoft.UI.Xaml.Media;
77
using Microsoft.UI.Xaml.Navigation;
88
using Microsoft.UI.Xaml.Shapes;
9+
using MyTools.Class;
910
using MyTools.Classes;
1011
using MyTools.Pages;
1112
using System;
@@ -19,6 +20,7 @@
1920
using Windows.Foundation;
2021
using Windows.Foundation.Collections;
2122
using Windows.Storage;
23+
using Windows.System;
2224

2325
// To learn more about WinUI, the WinUI project structure,
2426
// and more about our project templates, see: http://aka.ms/winui-project-info.
@@ -38,7 +40,7 @@ public App()
3840
{
3941
this.InitializeComponent();
4042
InitializeAppSettings();
41-
this.UnhandledException += (sender, e) =>
43+
this.UnhandledException += async (sender, e) =>
4244
{
4345
// 获取可写入的日志路径
4446
var localFolder = Windows.Storage.ApplicationData.Current.LocalFolder.Path;
@@ -50,9 +52,13 @@ public App()
5052
// 写入日志
5153
File.WriteAllText(logPath, e.Exception.ToString());
5254

53-
// 输出路径以便调试
54-
Debug.WriteLine($"崩溃日志已保存到:{logPath}");
55-
55+
// 弹窗提醒
56+
ContentDialogResult result = await ShowMessages.ShowDialog(((FrameworkElement)m_window.Content).XamlRoot, "啊哦~崩溃了!😫😫😫", $"崩溃日志已保存到:\n{logPath}\n是否查看?", true);
57+
58+
if (result == ContentDialogResult.Primary)
59+
{
60+
await Launcher.LaunchFolderPathAsync(localFolder);
61+
}
5662
e.Handled = true;
5763
};
5864
}

MyTools/Classes/ShowMessages.cs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
using Microsoft.UI.Xaml.Controls;
2-
using Microsoft.UI.Xaml;
1+
using Microsoft.UI.Xaml;
2+
using Microsoft.UI.Xaml.Controls;
3+
using Microsoft.Windows.AppNotifications;
4+
using Microsoft.Windows.AppNotifications.Builder;
35
using System;
46
using System.Collections.Generic;
57
using System.Linq;
68
using System.Text;
79
using System.Threading.Tasks;
8-
using Microsoft.Windows.AppNotifications;
910

1011
namespace MyTools.Class
1112
{
@@ -34,17 +35,11 @@ public static async Task<ContentDialogResult> ShowDialog(XamlRoot xamlRoot, stri
3435

3536
public static bool SendNotificationToast(string title, string message)
3637
{
37-
var xmlPayload = new string($@"
38-
<toast>
39-
<visual>
40-
<binding template=""ToastGeneric"">
41-
<text>{title}</text>
42-
<text>{message}</text>
43-
</binding>
44-
</visual>
45-
</toast>");
38+
var toast = new AppNotificationBuilder()
39+
.AddText(title)
40+
.AddText(message)
41+
.BuildNotification();
4642

47-
var toast = new AppNotification(xmlPayload);
4843
AppNotificationManager.Default.Show(toast);
4944
return toast.Id != 0;
5045
}

MyTools/MyTools.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<EnableMsixTooling>true</EnableMsixTooling>
1717
<DefaultLanguage>zh-cn</DefaultLanguage>
1818
<GenerateAppInstallerFile>False</GenerateAppInstallerFile>
19-
<AppxPackageSigningEnabled>True</AppxPackageSigningEnabled>
19+
<AppxPackageSigningEnabled>False</AppxPackageSigningEnabled>
2020
<PackageCertificateThumbprint>9178D1B60747CFA2D71E1EC8D0269C11DF3AAB60</PackageCertificateThumbprint>
2121
<AppxPackageSigningTimestampDigestAlgorithm>SHA256</AppxPackageSigningTimestampDigestAlgorithm>
2222
<AppxAutoIncrementPackageRevision>False</AppxAutoIncrementPackageRevision>
@@ -54,8 +54,8 @@
5454

5555
<ItemGroup>
5656
<PackageReference Include="CommunityToolkit.WinUI.Controls.Primitives" Version="8.2.250402" />
57-
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.8.250916003" />
58-
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.6584" />
57+
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.8.251003001" />
58+
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.6901" />
5959
<Manifest Include="$(ApplicationManifest)" />
6060
</ItemGroup>
6161

MyTools/Package.appxmanifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<Identity
1111
Name="WangZaiqun.MyTools1"
1212
Publisher="CN=B08B672B-E56B-416B-90FA-8C06E7A68E21"
13-
Version="0.1.6.0" />
13+
Version="0.1.7.0" />
1414

1515
<mp:PhoneIdentity PhoneProductId="bf612190-d8e7-49a6-9efc-5602273d0746" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
1616

0 commit comments

Comments
 (0)