diff --git a/App.xaml.cs b/App.xaml.cs index 00944fb..81c3a96 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -2,6 +2,9 @@ using System.Diagnostics; using System.Windows; using Microsoft.Windows.AppNotifications; +// 双开 WPF + WinForms 时,Application 在两个命名空间都有,用别名强制走 WPF 的。 +using Application = System.Windows.Application; + namespace WindowsGotify; public partial class App : Application @@ -94,7 +97,7 @@ public partial class App : Application Message = "Windows Gotify Agent 测试通知。", Title = "Gotify 测试", Priority = 5, - Date = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() + Date = DateTimeOffset.UtcNow }); } @@ -106,10 +109,9 @@ public partial class App : Application { try { - var arguments = args.Arguments; - if (arguments.StartsWith("url=", StringComparison.OrdinalIgnoreCase)) + // Windows App SDK 2.4.0:args.Arguments 已经是 IDictionary,由 AddArgument(key, value) 注入 + if (args.Arguments.TryGetValue("url", out var url) && !string.IsNullOrWhiteSpace(url)) { - var url = Uri.UnescapeDataString(arguments[4..]); Process.Start(new ProcessStartInfo { FileName = url, diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 2ed01d9..5e75b7e 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -6,6 +6,9 @@ using WindowsGotify.Models; using WindowsGotify.Services; using WindowsGotify.Tray; +// 双开 WPF + WinForms 时,MessageBox 在两个命名空间都有,用别名强制走 WPF 的。 +using MessageBox = System.Windows.MessageBox; + namespace WindowsGotify; public partial class MainWindow : Window diff --git a/Services/ConfigService.cs b/Services/ConfigService.cs index 6ef239f..2c08a2d 100644 --- a/Services/ConfigService.cs +++ b/Services/ConfigService.cs @@ -1,3 +1,4 @@ +using System.IO; using System.Text.Json; using WindowsGotify.Models; diff --git a/Services/GotifyApiService.cs b/Services/GotifyApiService.cs index a98485f..e7b7f44 100644 --- a/Services/GotifyApiService.cs +++ b/Services/GotifyApiService.cs @@ -1,3 +1,4 @@ +using System.Net.Http; using System.Net.Http.Headers; using System.Text.Json; using WindowsGotify.Models; diff --git a/Services/GotifyWebSocketService.cs b/Services/GotifyWebSocketService.cs index 35f8df9..577c734 100644 --- a/Services/GotifyWebSocketService.cs +++ b/Services/GotifyWebSocketService.cs @@ -1,3 +1,4 @@ +using System.IO; using System.Net.WebSockets; using System.Text; using System.Text.Json; @@ -18,7 +19,6 @@ public sealed class GotifyWebSocketService private readonly object _socketLock = new(); private ClientWebSocket? _socket; private bool _running; - private bool _forceReconnect; /// /// 收到一条新消息(已去重、未越界)时触发,UI 用来追加到历史列表。 @@ -53,7 +53,7 @@ public sealed class GotifyWebSocketService public void RequestReconnect() { - _forceReconnect = true; + // 直接 Abort 当前 socket,ConnectAndReceiveAsync 会抛 → 外层 RunLoopAsync 自动重连 lock (_socketLock) { try @@ -123,7 +123,6 @@ public sealed class GotifyWebSocketService if (!_running || _lifetimeCts.IsCancellationRequested) break; - _forceReconnect = false; _logger.Info($"Reconnect after {delay}s."); _statusChanged($"{delay}s 后重连"); diff --git a/Services/Logger.cs b/Services/Logger.cs index aecabab..aca27c6 100644 --- a/Services/Logger.cs +++ b/Services/Logger.cs @@ -1,3 +1,5 @@ +using System.IO; + namespace WindowsGotify.Services; public sealed class Logger diff --git a/Services/NotificationService.cs b/Services/NotificationService.cs index bcd930d..cd5edbe 100644 --- a/Services/NotificationService.cs +++ b/Services/NotificationService.cs @@ -44,11 +44,12 @@ public sealed class NotificationService : AppNotificationSoundEvent.Default); } - // 把 extras 里的 client::notification.click.url 透传给通知,让 App.OnNotificationInvoked 收到 url=... + // 把 extras 里的 client::notification.click.url 透传给通知,让 App.OnNotificationInvoked 收到 + // Windows App SDK 2.4.0 的 AddArgument 是 (key, value) 两参,跟 1.x 的单参 "key=value" 不一样 var clickUrl = message.ClickUrl; if (!string.IsNullOrWhiteSpace(clickUrl)) { - builder.AddArgument("url=" + Uri.EscapeDataString(clickUrl)); + builder.AddArgument("url", clickUrl); } var notification = builder.BuildNotification(); diff --git a/Services/StateService.cs b/Services/StateService.cs index 7335e46..f1978d7 100644 --- a/Services/StateService.cs +++ b/Services/StateService.cs @@ -1,3 +1,4 @@ +using System.IO; using System.Text.Json; namespace WindowsGotify.Services; diff --git a/WindowsGotify.csproj b/WindowsGotify.csproj index df780bc..6be2875 100644 --- a/WindowsGotify.csproj +++ b/WindowsGotify.csproj @@ -2,7 +2,8 @@ WinExe - net8.0-windows + net8.0-windows10.0.19041.0 + 10.0.17763.0 true true enable