Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows bug: Update the window theme without taking into account the preferred theme. #479

Closed
wants to merge 1 commit into from

Conversation

axoroll7
Copy link

Issue

If the preferred system theme is lightMode, it is impossible to switch to darkMode, on Windows.

await windowManager.setBrightness(Brightness.light);
await windowManager.setBrightness(Brightness.dark);

Solution

The preferred theme should not be taken into account, like the MacOS implementation.
In the swift file for MacOS, the theme is simply updated by passing an argument :

public func setBrightness(_ args: [String: Any]) {
    let brightness: String = args["brightness"] as! String
    if (brightness == "dark") {
        mainWindow.appearance = NSAppearance(named: NSAppearance.Name.vibrantDark)
    } else {
        mainWindow.appearance = NSAppearance(named: NSAppearance.Name.vibrantLight)
    }
    mainWindow.invalidateShadow()
}

But in the file for Windows, the system preferred theme is retrieved, and utilized incorrectly. Instead of doing:

BOOL enable_dark_mode = light_mode == 0 && brightness == "dark";

It should be:

BOOL enable_dark_mode = brightness == "dark";

(Apologies, English isn't my first language.)

@axoroll7
Copy link
Author

My apologies, after some tests I concluded the initial method is also valid. It didn't work at first in my tests because I didn't take into account that flutter changes automatically the title bar when the MaterialApp theme changes. That's another issue. Thank you

@axoroll7 axoroll7 closed this Aug 11, 2024
@axoroll7
Copy link
Author

If anyone is wondering how I managed to work around my problem, I put a debouncing in my stream listener to let the flutter engine do its change before mine. My stream is activated on themeMode changes, or platformBrightness if themeMode is ThemeMode.system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant