fix(windows): accept successful tray readiness HRESULTs
This commit is contained in:
1 parent
ae5e979761
commit
0735908ca9
7 files changed
+71
-2
No files matched your search
@@ -239,6 +239,19 @@ func TestNativeTrayIconLayout_HP_WINTRAY_03(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNativeInstalledTrayReadiness_BH_WINTRAY_07(t *testing.T) {
|
||||
class, _ := winapi.UTF16PtrFromString("RVBoxTrayWindowV1")
|
||||
hwnd, _, _ := procFindWindow.Call(uintptr(unsafe.Pointer(class)), 0)
|
||||
if hwnd == 0 {
|
||||
t.Skip("requires an installed tray on this interactive desktop")
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
defer cancel()
|
||||
if err := WaitReady(ctx); err != nil {
|
||||
t.Fatalf("existing installed icon was falsely reported unready: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNativeTrayWindowLifecycle_HP_WINTRAY_04(t *testing.T) {
|
||||
var session uint32
|
||||
if err := winapi.ProcessIdToSessionId(winapi.GetCurrentProcessId(), &session); err != nil {
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package windowstray
|
||||
|
||||
// iconQuerySucceeded follows SUCCEEDED(HRESULT), including S_FALSE. Explorer
|
||||
// can return S_FALSE with valid icon coordinates; requiring S_OK falsely reports
|
||||
// a tray startup failure. HRESULT is signed 32-bit even in a 64-bit syscall.
|
||||
func iconQuerySucceeded(result uintptr) bool {
|
||||
return int32(result) >= 0
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package windowstray
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestTrayReadinessAcceptsSuccessfulHRESULT_BH_WINTRAY_06(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
result uintptr
|
||||
ready bool
|
||||
}{
|
||||
{"S_OK", 0, true},
|
||||
{"S_FALSE with registered icon", 1, true},
|
||||
{"other successful HRESULT", 0x00040000, true},
|
||||
{"E_FAIL", 0x80004005, false},
|
||||
{"E_INVALIDARG", 0x80070057, false},
|
||||
{"E_ACCESSDENIED", 0x80070005, false},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if got := iconQuerySucceeded(tc.result); got != tc.ready {
|
||||
t.Fatalf("HRESULT %#x: ready=%v, want %v", tc.result, got, tc.ready)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -509,7 +509,7 @@ func WaitReady(ctx context.Context) error {
|
||||
id := identifier{Size: uint32(unsafe.Sizeof(identifier{})), HWnd: hwnd, UID: trayIconID}
|
||||
var rect rectangle
|
||||
result, _, _ := procShellIconRect.Call(uintptr(unsafe.Pointer(&id)), uintptr(unsafe.Pointer(&rect)))
|
||||
if int32(result) == 0 {
|
||||
if iconQuerySucceeded(result) {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user