5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-21 11:29:29 +08:00

retry when shellnotifyicon fails (#3710)

* 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>
This commit is contained in:
DeltaLaboratory 2024-09-02 18:33:17 +09:00 committed by GitHub
parent e316cd0719
commit 2460b570fe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 2 deletions

View File

@ -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

View File

@ -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"
)
@ -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