Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

retry when shellnotifyicon fails #3710

Merged
merged 8 commits into from
Sep 2, 2024
1 change: 1 addition & 0 deletions mkdocs-website/docs/en/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- [windows] Fixed syso icon file generation bug by [atterpac](https://github.com/atterpac) in [#3675](https://github.com/wailsapp/wails/pull/3675)
- [linux] Fix to run natively in wayland incorporated from [#1811](https://github.com/wailsapp/wails/pull/1811) in [#3614](https://github.com/wailsapp/wails/pull/3614) by [@stendler](https://github.com/stendler)
- [windows] Fixed system tray startup panic in [#3693](https://github.com/wailsapp/wails/issues/3693) by [@DeltaLaboratory](https://github.com/DeltaLaboratory)

## v3.0.0-alpha.6 - 2024-07-30

Expand Down
14 changes: 12 additions & 2 deletions v3/pkg/application/systemtray_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ package application
import (
"fmt"
"syscall"
"time"
"unsafe"

"github.com/wailsapp/wails/v3/pkg/icons"

"github.com/samber/lo"

"github.com/wailsapp/wails/v3/pkg/events"
"github.com/wailsapp/wails/v3/pkg/w32"
)
Expand Down Expand Up @@ -174,8 +176,16 @@ func (s *windowsSystemTray) run() {
}
nid.CbSize = uint32(unsafe.Sizeof(nid))

if !w32.ShellNotifyIcon(w32.NIM_ADD, &nid) {
panic(syscall.GetLastError())
for retries := range 6 {
if !w32.ShellNotifyIcon(w32.NIM_ADD, &nid) {
if retries == 5 {
globalApplication.fatal("Failed to register system tray icon: %v", syscall.GetLastError())
}

time.Sleep(500 * time.Millisecond)
continue
}
break
}

nid.UVersion = w32.NOTIFYICON_VERSION
Expand Down
Loading