Skip to content

Commit

Permalink
retry when shellnotifyicon fails (#3710)
Browse files Browse the repository at this point in the history
* add retry mechanism for create shell notification icon

* add retry mechanism for create shell notification icon

* adjust delay and attempts

* added changelog

* Use application fatal handler instead of panic

---------

Co-authored-by: Lea Anthony <lea.anthony@gmail.com>
  • Loading branch information
DeltaLaboratory and leaanthony authored Sep 2, 2024
1 parent e316cd0 commit 2460b57
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
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

0 comments on commit 2460b57

Please sign in to comment.