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
feat: add immersive dark mode on windows #33624
Conversation
Been waiting for this. 😄 I've built it and played with it on Windows 10. However, it seems to suffer from the same problem outlined in #25373:
Using the fiddle from our docs on dark mode I can confirm that's the behavior I see, the titlebar doesn't change until something forces a window refresh like resizing it, minimizing, blurring it, etc. It does however refresh correctly when it's set to system and you toggle the system setting. Also, can release notes be updated to clarify it's for Windows? |
@dsanders11 yup that's a known issue - I spend quite some time trying to find a fix but wasn't able to come up with a working programmatic "force-redraw" (RedrawWindow API etc.). Feel free to give it a try ;). For some reason I only hit that in vanilla Electron, not in Skype - also it's only an issue when setting dark mode from within the app; afaik it works when changing the system dark mode in OS settings. The fact that the title bar changes after moving a window shows that the property is already set correctly (so it's nothing missing on our side). I wouldn't be surprised if it is an actual Windows bug. |
@mlaurencin after merging, we should also add the new fuse to @electron/fuses :) |
Current implementation doesn't change the titlebar for DevTools windows, but I was able to get that working wtih a small change, see 63e4ef2 for how I implemented it. EDIT: That commit has problems, so just a reference on how it might be done, not a shippable solution. |
@dsanders11 Thanks! I'll check your comments tmw or next week; unfortunately i cannot guarantee for anything but the initially proposed changes, because they were tested in the wild 🤞🏽 |
@deermichel, disregard the commit about doing all windows to get the DevTools windows. I tested it again and it didn't work like it did before. 🤔 I also realized that it wouldn't work for the case where you open DevTools after the theme change, since it wouldn't re-run that code when the DevTools opens. So, disregard that. 🙂 I'll just open a bug once this lands that DevTools won't have dark mode titlebar (would be nice, but not too important). |
@dsanders11 @mlaurencin Let me suggest a path for going forward here:
|
If I am following correctly, the API is currently public for Win11 and private for Win10, so it would be a matter of converting the fuse to only apply to Win10 if it were to be kept, right? |
I much prefer this option, it keeps the code cleaner and makes more sense for consumers. "This is a Windows 11 feature". |
I much prefer leaving it possible to use on Win10 - which is going to be around for a long time to come. Not having the functionality at the moment is an eyesore, especially since the menu bar does respect dark mode, making the out of the box experience on Windows feel unpolished. |
I agree with @dsanders11.
For Win11, enabling the feature per default is a no-brainer. For Win10, putting it behind a fuse seems like a reasonable way to make this feature available to the public without risking too much (it is super unlikely the API will change on Win10 anyway as it is in maintenance mode & would even break msft apps). |
How close are we to getting this landed? I really don't want to create my own custom build of electron |
@deermichel, take a look at my branch, hopefully we can grab these changes and finish this PR off: https://github.com/dsanders11/electron/commits/immersive-dark-mode-add-2 I changed the fuse to mention Win10 specifically, added a runtime check for Win11, and separated out the implementations so it's cleaner and clear which one is using private APIs. |
@dsanders11 thank you very much, i'll take a look next week |
58b3e6d
to
57ec41e
Compare
Release Notes Persisted
|
* feat: add immersive dark mode * fix syntax and add header * add me * Update fuses.json5 * fix: redraw title bar on dark mode change * chore: SetWindowTheme doesn't seem to be needed * chore: separate out Win 10 dark mode implementation * final touches * final touches * chore: limit Win 10 to >= 20H1 and drop fuse * fix types * fix lint Co-authored-by: Micha Hanselmann <micha.hanselmann@gmail.com> Co-authored-by: David Sanders <dsanders11@ucsbalum.com>
* feat: add immersive dark mode * fix syntax and add header * add me * Update fuses.json5 * fix: redraw title bar on dark mode change * chore: SetWindowTheme doesn't seem to be needed * chore: separate out Win 10 dark mode implementation * final touches * final touches * chore: limit Win 10 to >= 20H1 and drop fuse * fix types * fix lint Co-authored-by: Micha Hanselmann <micha.hanselmann@gmail.com> Co-authored-by: David Sanders <dsanders11@ucsbalum.com>
* feat: add immersive dark mode * fix syntax and add header * add me * Update fuses.json5 * fix: redraw title bar on dark mode change * chore: SetWindowTheme doesn't seem to be needed * chore: separate out Win 10 dark mode implementation * final touches * final touches * chore: limit Win 10 to >= 20H1 and drop fuse * fix types * fix lint Co-authored-by: Micha Hanselmann <micha.hanselmann@gmail.com> Co-authored-by: David Sanders <dsanders11@ucsbalum.com>
I have automatically backported this PR to "18-x-y", please check out #34548 |
I have automatically backported this PR to "20-x-y", please check out #34549 |
I have automatically backported this PR to "19-x-y", please check out #34550 |
feat: add immersive dark mode on windows (#33624) * feat: add immersive dark mode * fix syntax and add header * add me * Update fuses.json5 * fix: redraw title bar on dark mode change * chore: SetWindowTheme doesn't seem to be needed * chore: separate out Win 10 dark mode implementation * final touches * final touches * chore: limit Win 10 to >= 20H1 and drop fuse * fix types * fix lint Co-authored-by: Micha Hanselmann <micha.hanselmann@gmail.com> Co-authored-by: David Sanders <dsanders11@ucsbalum.com> Co-authored-by: Michaela Laurencin <35157522+mlaurencin@users.noreply.github.com> Co-authored-by: Micha Hanselmann <micha.hanselmann@gmail.com> Co-authored-by: David Sanders <dsanders11@ucsbalum.com>
Very excited to test this out in the next release! |
* feat: add immersive dark mode * fix syntax and add header * add me * Update fuses.json5 * fix: redraw title bar on dark mode change * chore: SetWindowTheme doesn't seem to be needed * chore: separate out Win 10 dark mode implementation * final touches * final touches * chore: limit Win 10 to >= 20H1 and drop fuse * fix types * fix lint Co-authored-by: Micha Hanselmann <micha.hanselmann@gmail.com> Co-authored-by: David Sanders <dsanders11@ucsbalum.com>
Description of Change
Closes #32913, closes #18119.
A refactored implementation of dark mode for Windows, using official API for Windows 11 and undocumented flag on Win 10 >= 20H1. It allows Electron apps to set a dark title bar based on the system preference.
cc @dsanders11 @deermichel @ckerr
Checklist
npm test
passesRelease Notes
Notes: Added immersive dark mode on Windows.