Skip to content

Commit

Permalink
fix: Removed UpdateIcon failed exception.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Jan 3, 2024
1 parent c88a074 commit 10e6f83
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/libs/H.NotifyIcon.Shared/TaskbarIcon.Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ partial void OnCustomNameChanged(string? newValue)
partial void OnIconChanged(Icon? oldValue, Icon? newValue)
{
oldValue?.Dispose();
UpdateIcon(newValue);
_ = UpdateIcon(newValue);
}

/// <summary>
Expand All @@ -52,10 +52,12 @@ partial void OnIconChanged(Icon? oldValue, Icon? newValue)
/// <param name="value"></param>
[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
}

Expand Down
8 changes: 5 additions & 3 deletions src/libs/H.NotifyIcon/Core/TrayIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -459,14 +459,14 @@ public void UpdateToolTip(string text)
/// <param name="handle">The title to display on the balloon tip.</param>
/// <exception cref="InvalidOperationException"></exception>
/// <exception cref="ObjectDisposedException"></exception>
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;
Expand All @@ -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

Expand Down

0 comments on commit 10e6f83

Please sign in to comment.