From 2460b570fe80dd78b83cc701421213ad8cb1d073 Mon Sep 17 00:00:00 2001 From: DeltaLaboratory Date: Mon, 2 Sep 2024 18:33:17 +0900 Subject: [PATCH] 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 --- mkdocs-website/docs/en/changelog.md | 1 + v3/pkg/application/systemtray_windows.go | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/mkdocs-website/docs/en/changelog.md b/mkdocs-website/docs/en/changelog.md index 570a2569551..c380987a5af 100644 --- a/mkdocs-website/docs/en/changelog.md +++ b/mkdocs-website/docs/en/changelog.md @@ -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 diff --git a/v3/pkg/application/systemtray_windows.go b/v3/pkg/application/systemtray_windows.go index 9262abf06d9..49354fc7eab 100644 --- a/v3/pkg/application/systemtray_windows.go +++ b/v3/pkg/application/systemtray_windows.go @@ -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