Alternador de tema automático para modo escuro

:warning: O Discourse agora suporta Automatic Dark Mode color scheme switching no núcleo; este componente está obsoleto e não deve mais ser utilizado.

Repositório:

https://github.com/pmusaraj/discourse-dark-mode

Instruções de instalação: Installing a theme or theme component

O que isso faz?

Este componente permite a troca automática para um tema escuro quando o navegador está configurado para o modo escuro. Isso funciona apenas para usuários logados em todos os navegadores que suportam a consulta de mídia prefers-color-scheme.

Por padrão, este componente está ativado e os usuários individuais podem desativá-lo em suas Preferências > Interface. Os administradores também podem configurar o componente para estar desativado por padrão; nesse caso, os usuários verão um botão para ativar a troca automática em suas preferências de interface.

Como funciona?

Se o navegador estiver no modo escuro, este componente recarregará o Discourse com o tema escuro ativado. Se o navegador retornar ao modo claro, o componente recarregará com o tema padrão ativado.

Ele também será recarregado se o modo escuro for alternado enquanto o usuário estiver no site (como mostrado no vídeo acima).

(Se você tiver mais de dois temas ativados e o usuário tiver selecionado um tema diferente do padrão ou escuro, este componente não fará nada, ou seja, respeitará a escolha do usuário.)

Configuração

  • Certifique-se de ter um tema escuro instalado e que ele seja selecionável pelos usuários.
  • Adicione este componente tanto ao tema padrão quanto ao tema escuro (muito importante: se você não adicioná-lo a ambos os temas, os usuários não poderão voltar ao tema padrão).
  • Nas configurações do componente, insira o ID do seu tema escuro em dark theme id.
28 curtidas

Awesome, although flux is overkill just to toggle dark mode on the mac. Night Owl will do the same thing without interfering with anything else.

4 curtidas

I just pushed a small update to this theme component to make it compatible with iOS 13 (which will ship with Dark Mode as well as an option to automatically enable it in the evenings).

9 curtidas

Thanks for this awesome component, I’ve been looking for this! Unfortunately I can’t seem to get it to work. Perhaps something trivial but where do I find the dark theme id? Is that just the name of the theme?

1 curtida

Thanks!

The ID is the number of the theme in the URL when you’ve selected it in the admin. In this URL: /admin/customize/themes/39 for example, it’s 39.

1 curtida

Awesome, works like a charm, thanks! Really hope this becomes part of the standard discourse install.

2 curtidas

Google Chrome now supports dark mode on iOS 13 and iPadOS 13. I’m not too sure about dark mode support for Google Chrome on MacOS Mojave or MacOS Catalina though.

When will support for Google Chrome arrive?

it should work in Chrome already, under the hood it uses the prefers-color-scheme media query and browser support for it is pretty good nowadays: Can I use... Support tables for HTML5, CSS3, etc

Oh, that’s good to hear! :grinning:

Yeah, I also really hope that this becomes part of the standard Discourse install. Some people only like to update their forums and don’t really go beyond that.

1 curtida

@pmusaraj one thing I noticed is that the switching only works for logged in users, is there a way to also have it automatically set for anonymous users that haven’t created an account yet (e.g. switch to dark theme while using a private browser window)?

1 curtida

Doesn’t work for me :-/

Just for future updates: It would be great, if there is some dropdown menu for choosing the right one.

The “prefers-color-scheme” feature is also supported by windows. The newest Chrome Beta and newest Firefox Version supports this media query.

5 curtidas

This component seems to create an issue with 2.4.0.beta11+39. In my registered-users-only community the login screen at https://mydomain/login is blank. It works normally when this component is deactivated.

I can’t reproduce this locally with latest Discourse and latest version of the component. When the login screen is blank, is there an error in the browser console?

Update: the issue Thomas was running into is now fixed in the component. Thanks for the report!

4 curtidas

+1 por tornar isso parte do núcleo do Discourse

4 curtidas