diff --git a/Directory.Packages.props b/Directory.Packages.props
index 55aa54db8..33172361b 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -104,7 +104,7 @@
-
+
@@ -119,7 +119,7 @@
-
+
diff --git a/src/ST.Client.Desktop.Avalonia.App/NotifyIconHelper.cs b/src/ST.Client.Desktop.Avalonia.App/NotifyIconHelper.cs
index e14abd8c8..a6caf3bc5 100644
--- a/src/ST.Client.Desktop.Avalonia.App/NotifyIconHelper.cs
+++ b/src/ST.Client.Desktop.Avalonia.App/NotifyIconHelper.cs
@@ -30,11 +30,11 @@ using Avalonia.Controls;
namespace System.Application.UI
{
- ///
- /// NotifyIcon / TrayIcon 右下角托盘菜单助手类
- ///
- static class NotifyIconHelper
+ ///
+ sealed class NotifyIconHelper : INotificationService.NotifyIconHelper
{
+ private NotifyIconHelper() => throw new NotSupportedException();
+
#if !TRAY_INDEPENDENT_PROGRAM
static Stream GetIcon(IAssetLoader assets)
{
@@ -58,6 +58,7 @@ namespace System.Application.UI
public static NotifyIcon? Init(App app, EventHandler notifyIconClick)
{
+ if (IsInitialized) return null;
NotifyIcon? notifyIcon = null;
IDisposable? menuItemDisposable = null;
var icon = GetIconByCurrentAvaloniaLocator();
@@ -125,6 +126,7 @@ namespace System.Application.UI
}
}
if (menuItemDisposable != null) menuItemDisposable.AddTo(app);
+ IsInitialized = true;
return notifyIcon;
}
diff --git a/src/ST.Client.Desktop.Avalonia.App/Program.cs b/src/ST.Client.Desktop.Avalonia.App/Program.cs
index 068644e50..0245de7aa 100644
--- a/src/ST.Client.Desktop.Avalonia.App/Program.cs
+++ b/src/ST.Client.Desktop.Avalonia.App/Program.cs
@@ -8,9 +8,9 @@ using System.Runtime.Versioning;
#elif LINUX
[assembly: SupportedOSPlatform("Linux")]
#elif WINDOWS_DESKTOP_BRIDGE
-[assembly: SupportedOSPlatform("Windows")]
-#elif WINDOWS
[assembly: SupportedOSPlatform("Windows10.0.17763.0")]
+#elif WINDOWS
+[assembly: SupportedOSPlatform("Windows")]
#endif
namespace System.Application.UI
diff --git a/src/ST.Client/Services/INotificationService.cs b/src/ST.Client/Services/INotificationService.cs
index 518965c58..20884bad6 100644
--- a/src/ST.Client/Services/INotificationService.cs
+++ b/src/ST.Client/Services/INotificationService.cs
@@ -56,5 +56,19 @@ namespace System.Application.Services
///
///
static Task GetLastNotificationRecordId() => IStorage.Instance.GetAsync(ON_LAST_STARTUP_NOTIFICATION_RECORD_ID);
+
+ ///
+ /// NotifyIcon / TrayIcon 右下角托盘菜单助手类
+ ///
+ public abstract class NotifyIconHelper
+ {
+ protected NotifyIconHelper() => throw new NotSupportedException();
+
+ ///
+ /// 托盘初始化是否完成
+ /// 注意:在 Windows 上托盘初始化之前调用气泡消息会导致托盘不显示
+ ///
+ public static bool IsInitialized { get; protected set; }
+ }
}
}
\ No newline at end of file
diff --git a/src/ST.Client/Services/Implementation/NotificationServiceImpl.cs b/src/ST.Client/Services/Implementation/NotificationServiceImpl.cs
index 7d972930b..e95d5e3dc 100644
--- a/src/ST.Client/Services/Implementation/NotificationServiceImpl.cs
+++ b/src/ST.Client/Services/Implementation/NotificationServiceImpl.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Text;
using System.Properties;
using System.Windows;
+using static System.Application.Services.INotificationService;
namespace System.Application.Services.Implementation
{
@@ -20,7 +21,7 @@ namespace System.Application.Services.Implementation
void INotificationService.Cancel(NotificationType notificationType)
{
- if (OperatingSystem2.IsWindows)
+ if (OperatingSystem2.IsWindows && NotifyIconHelper.IsInitialized)
{
notifyIcon.HideBalloonTip();
}
@@ -28,7 +29,7 @@ namespace System.Application.Services.Implementation
void INotificationService.CancelAll()
{
- if (OperatingSystem2.IsWindows)
+ if (OperatingSystem2.IsWindows && NotifyIconHelper.IsInitialized)
{
notifyIcon.HideBalloonTip();
}
@@ -36,7 +37,7 @@ namespace System.Application.Services.Implementation
void INotificationService.Notify(string text, NotificationType notificationType, bool autoCancel, string? title, Entrance entrance)
{
- if (OperatingSystem2.IsWindows)
+ if (OperatingSystem2.IsWindows && NotifyIconHelper.IsInitialized)
{
title ??= ThisAssembly.AssemblyTrademark;
// 调用托盘显示通知