From 10e6f835161bfa7a2f16d91a6bc13955491b43dc Mon Sep 17 00:00:00 2001 From: HavenDV Date: Wed, 3 Jan 2024 20:25:10 +0400 Subject: [PATCH] fix: Removed UpdateIcon failed exception. --- src/libs/H.NotifyIcon.Shared/TaskbarIcon.Properties.cs | 8 +++++--- src/libs/H.NotifyIcon/Core/TrayIcon.cs | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/libs/H.NotifyIcon.Shared/TaskbarIcon.Properties.cs b/src/libs/H.NotifyIcon.Shared/TaskbarIcon.Properties.cs index d0a141d..0b567cc 100644 --- a/src/libs/H.NotifyIcon.Shared/TaskbarIcon.Properties.cs +++ b/src/libs/H.NotifyIcon.Shared/TaskbarIcon.Properties.cs @@ -43,7 +43,7 @@ partial void OnCustomNameChanged(string? newValue) partial void OnIconChanged(Icon? oldValue, Icon? newValue) { oldValue?.Dispose(); - UpdateIcon(newValue); + _ = UpdateIcon(newValue); } /// @@ -52,10 +52,12 @@ partial void OnIconChanged(Icon? oldValue, Icon? newValue) /// [CLSCompliant(false)] [SupportedOSPlatform("windows5.1.2600")] - public void UpdateIcon(Icon? value) + public bool UpdateIcon(Icon? value) { #if !MACOS - TrayIcon.UpdateIcon((nint?)value?.Handle ?? 0); + return TrayIcon.UpdateIcon((nint?)value?.Handle ?? 0); +#else + return true; #endif } diff --git a/src/libs/H.NotifyIcon/Core/TrayIcon.cs b/src/libs/H.NotifyIcon/Core/TrayIcon.cs index 3a0a7b8..aa3cb44 100644 --- a/src/libs/H.NotifyIcon/Core/TrayIcon.cs +++ b/src/libs/H.NotifyIcon/Core/TrayIcon.cs @@ -459,14 +459,14 @@ public void UpdateToolTip(string text) /// The title to display on the balloon tip. /// /// - public void UpdateIcon(nint handle) + public bool UpdateIcon(nint handle) { EnsureNotDisposed(); if (!IsCreated) { Icon = handle; - return; + return true; } var additionalFlags = (NOTIFY_ICON_DATA_FLAGS)0; @@ -477,9 +477,11 @@ public void UpdateIcon(nint handle) if (!TrayIconMethods.TryModifyIcon(Id, additionalFlags, handle)) { - throw new InvalidOperationException("UpdateIcon failed."); + return false; } + Icon = handle; + return true; } #endif