Interruttore automatico del tema per la modalità scura

:warning: Discourse ora supporta Automatic Dark Mode color scheme switching nel core; questo componente è ora deprecato e non dovrebbe più essere utilizzato.

Repository:

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

Istruzioni per l’installazione: Installing a theme or theme component

Cosa fa?

Questo componente consente il passaggio automatico a un tema scuro quando il browser è impostato sulla modalità scura. Funziona solo per gli utenti registrati su tutti i browser che supportano la query media prefers-color-scheme.

Per impostazione predefinita, questo componente è abilitato e i singoli utenti possono disattivarlo nella schermata Preferenze > Interfaccia. Gli amministratori possono anche impostare il componente come disabilitato di default; in tal caso, gli utenti vedranno un pulsante per abilitare il passaggio automatico nelle preferenze dell’interfaccia.

Come funziona?

Se il browser è in modalità scura, questo componente ricaricherà Discourse con il tema scuro abilitato. Se il browser torna alla modalità chiara, questo componente ricaricherà con il tema predefinito abilitato.

Ricaricherà anche se la modalità scura viene attivata o disattivata mentre l’utente è sul sito (come mostrato nel video sopra).

(Se hai più di due temi abilitati e l’utente ha selezionato un tema diverso da quello predefinito o scuro, questo componente non farà nulla, ovvero rispetterà la scelta dell’utente.)

Configurazione

  • Assicurati di avere un tema scuro installato e che sia selezionabile dagli utenti
  • Aggiungi questo componente sia al tema predefinito che al tema scuro (molto importante: se non lo aggiungi a entrambi i temi, gli utenti non potranno tornare al tema predefinito)
  • Nelle impostazioni del componente, inserisci l’ID del tuo tema scuro in dark theme id
28 Mi Piace

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 Mi Piace

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 Mi Piace

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 Mi Piace

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 Mi Piace

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

2 Mi Piace

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 Mi Piace

@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 Mi Piace

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 Mi Piace

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 Mi Piace

+1 per aver reso questa parte parte del nucleo di Discourse

4 Mi Piace