fyne-io / fyne

Cross platform GUI toolkit in Go inspired by Material Design
https://fyne.io/
Other
24.14k stars 1.35k forks source link

Sometimes fyne fails to setup dark mode #4758

Open lostdusty opened 3 months ago

lostdusty commented 3 months ago

Checklist

Describe the bug

Happens randomly, with error code 0x800703e6. image Dark mode, however, is still set successfully.

How to reproduce

Use go run . until it appears. Depends on your luck I guess.

Screenshots

No response

Example code

func main() {
    a := app.New()
    w := a.NewWindow("Hello")

    hello := widget.NewLabel("Hello Fyne!")
    w.SetContent(container.NewVBox(
        hello,
        widget.NewButton("Hi!", func() {
            hello.SetText("Welcome :)")
        }),
    ))

    w.ShowAndRun()
}

Fyne version

2.4.4

Go compiler version

1.22.0

Operating system and version

Windows 10

Additional Information

Modified internal/driver/glfw/window_windows.go to show the error code.

montovaneli commented 3 months ago

Sometimes this also happens here. Even though the theme is correctly set in the 'fyne elements', the Windows' own window top bar remains in light theme, as in the print below (exactly when it occurred). It throws the same error 0x800703e6.

image

The right behavior for the window would be:

image

I read the error HRESULT =0x800703e6 represents - ERROR_NOACCESS. A description of the code reveals the message invalid access to memory location.

Perhaps a possibility is that the window fyne tries to set to dark mode isn't fully initialized yet?

I take this opportunity to ask you: Were you using the SystemTray or SystemTrayMenu API when this occurred?

lostdusty commented 3 months ago

I were using none of them. At least on my machine the theme is still applied successfully, and I get the following error description: "The operation completed successfully."

lostdusty commented 1 month ago

While developing, happened to me too: image

andydotxyz commented 1 month ago

Any error message logged?

lostdusty commented 1 month ago

The operation completed successfully

andydotxyz commented 1 month ago

OMG windows.

I wonder if there is something in the thread handling where we set that up... possibly we knocked it into a goroutine?

andydotxyz commented 1 month ago

OMG windows.

I wonder if there is something in the thread handling where we set that up... possibly we knocked it into a goroutine?

Seems not:

    runOnMain(func() {
        w.setDarkMode()

Perhaps there is something in our windows call that is not correct for all systems or at all times?

        dwm := syscall.NewLazyDLL("dwmapi.dll")
        setAtt := dwm.NewProc("DwmSetWindowAttribute")
        ret, _, err := setAtt.Call(uintptr(unsafe.Pointer(hwnd)), // window handle
            20,                             // DWMWA_USE_IMMERSIVE_DARK_MODE
            uintptr(unsafe.Pointer(&dark)), // on or off
            8)                              // sizeof(darkMode)
Jacalz commented 1 month ago

I have a vague recollection of this being a thing on old versions of Windows 10 (or at least something similar). Is the system updated to the latest version?