You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When Explorer / the taskbar restarts, the tray icon is de-registered until the TaskbarCreated handler (reshowSystrays) re-adds it (~1s debounce). A SetIcon in that window reaches updateIcon
When the thread's last-error is 0, GetLastError() is nil, in Go this is panic(nil) -> "panic called with nil argument", crashing the host app.
Apps that update the tray on a timer hit this; others rarely do.
Fixes # (issue)
1: Fix don not panic(nil) in systray updateIcon when NIM_MODIFY fails
2: Fix nil-deref in destroy()
Please select the option that is relevant.
Bug fix (non-breaking change which fixes an issue)
New feature (non-breaking change which adds functionality)
Breaking change (fix or feature that would cause existing functionality to not work as expected)
This change requires a documentation update
How Has This Been Tested?
Stack trace from user:
os=windows
error: panic called with nil argument
stack:
github.com/wailsapp/wails/v3/pkg/application.(*windowsSystemTray).updateIcon
at github.com/wailsapp/wails/v3@v3.0.0-alpha2.105/pkg/application/systemtray_windows.go:346
github.com/wailsapp/wails/v3/pkg/application.(*windowsSystemTray).setIcon
at github.com/wailsapp/wails/v3@v3.0.0-alpha2.105/pkg/application/systemtray_windows.go:400
github.com/wailsapp/wails/v3/pkg/application.(*SystemTray).SetIcon.func1
at github.com/wailsapp/wails/v3@v3.0.0-alpha2.105/pkg/application/systemtray.go:236
github.com/wailsapp/wails/v3/pkg/application.InvokeSync.func1
at github.com/wailsapp/wails/v3@v3.0.0-alpha2.105/pkg/application/mainthread.go:28
github.com/wailsapp/wails/v3/pkg/application.(*windowsApp).invokeCallback
at github.com/wailsapp/wails/v3@v3.0.0-alpha2.105/pkg/application/mainthread_windows.go:125
github.com/wailsapp/wails/v3/pkg/application.(*windowsApp).wndProc
at
Windows
macOS
Linux
If you checked Linux, please specify the distro and version.
Test Configuration
Please paste the output of wails doctor. If you are unable to run this command, please describe your environment in as much detail as possible.
Checklist:
(v2 only) I have updated website/src/pages/changelog.mdx with details of this PR (v3 changelog entries are added automatically)
My code follows the general coding style of this project
I have performed a self-review of my own code
I have commented my code, particularly in hard-to-understand areas
I have made corresponding changes to the documentation
My changes generate no new warnings
I have added tests that prove my fix is effective or that my feature works
New and existing unit tests pass locally with my changes
Summary by CodeRabbit
Bug Fixes
Improved Windows system tray reliability when updating the tray icon. If an update fails, the app now logs a warning and safely retries later instead of crashing.
Made tray icon removal logging more robust, avoiding a potential issue when reporting errors during shutdown.
Two error-handling fixes in windowsSystemTray on Windows: updateIcon replaces a panic on ShellNotifyIcon(NIM_MODIFY) failure with a warning log plus rollback of s.currentIcon; destroy fixes a potential nil-dereference by passing syscall.GetLastError() directly to the debug logger instead of calling .Error() on it.
updateIcon now warns and restores the previous icon handle on NIM_MODIFY failure instead of panicking. destroy passes syscall.GetLastError() as a value to debug instead of calling .Error() on a potentially nil error.
Estimated code review effort
🎯 2 (Simple) | ⏱️ ~5 minutes
Possibly related PRs
wailsapp/wails#4653: Broader system tray refactor in systemtray_windows.go touching ShellNotifyIcon handling and destroy-path cleanup.
Suggested labels
Bug, Windows, go, v3-alpha, size:M
Suggested reviewers
leaanthony
Poem
🐇 No more panic in the tray,
The icon rolls back, come what may.
A warning logged, a nil unwrapped right,
The system tray hops through the night.
Steady paws keep bugs at bay! 🌟
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When Explorer / the taskbar restarts, the tray icon is de-registered until the TaskbarCreated handler (reshowSystrays) re-adds it (~1s debounce). A SetIcon in that window reaches updateIcon
Shell_NotifyIcon(NIM_MODIFY) fails -> panic(syscall.GetLastError()).
When the thread's last-error is 0, GetLastError() is nil, in Go this is panic(nil) -> "panic called with nil argument", crashing the host app.
Apps that update the tray on a timer hit this; others rarely do.
Fixes # (issue)
1: Fix don not panic(nil) in systray updateIcon when NIM_MODIFY fails
2: Fix nil-deref in destroy()
Please select the option that is relevant.
How Has This Been Tested?
Stack trace from user:
If you checked Linux, please specify the distro and version.
Test Configuration
Please paste the output of
wails doctor. If you are unable to run this command, please describe your environment in as much detail as possible.Checklist:
website/src/pages/changelog.mdxwith details of this PR (v3 changelog entries are added automatically)Summary by CodeRabbit