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

Set default theme based on prefers-color-scheme media query #15

Open
rijkvanzanten opened this issue Nov 21, 2019 · 3 comments
Open

Set default theme based on prefers-color-scheme media query #15

rijkvanzanten opened this issue Nov 21, 2019 · 3 comments

Comments

@rijkvanzanten
Copy link
Contributor

It would be pretty neat if the app would default its color scheme based on the color scheme of the OS of the user.

@kritzware
Copy link
Owner

Hi @rijkvanzanten, apologies for the delay on this one also.

This is an interesting idea. We'll have to find out if the system colour scheme if available across various browsers.

@rijkvanzanten
Copy link
Contributor Author

@media (prefers-color-scheme: dark) { ... } is the "official" way of signaling whether or not the user has requested the system to display in Dark mode (https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme). All the major browsers either support it, or will support it in the next release (Edge) (https://caniuse.com/#search=prefers-color-scheme).

Seeing we mostly rely on the text editor plugin to provide the styles, we'd have to read out this media query from JS, which is possible by using

const hasDarkModeEnabled = window.matchMedia('"prefers-color-scheme: dark)");

(see https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia)

@rijkvanzanten
Copy link
Contributor Author

An interesting edge case is what happens when someone changes from light to dark mode while having the app open? The media query will automatically change, but the editor has to be re-initialized.

While this sounds like a big edge case, macOS can toggle between light and dark on sunset / sunrise. If you combine that with keeping a lot of tabs open, you can end up in a situation where the app UI changed, but the editor didn't.

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

No branches or pull requests

2 participants