Automatic Dark Mode

I guess u need to force the users by disable the ability to choice the color scheme
go to settings → customization → colors → The color scheme can be selected by users ((disable it))

then go back to the style and sign a color scheme thats will appear to the users by force

1 Like

Thanks for trying to help :slight_smile:

It is already disabled.

I am asking for this As mentioned here: Automatic Dark Mode color scheme switching

I want this setting to force enable for all users but I can’t seem to find a way for it.

Perhaps you want the default dark mode color scheme id in admin-settings?


Discourse settings bot says:
1 Like

It’s set to dark color scheme

A few users reported that this setting is not enabled for them and they having issues seeing the logo in dark mode after enabling the setting it fixes the issue.

I was wondering why this setting is not enabled for all users. That’s why I was looking for a way to force enable for all users.

You can’t do that from the interface.
You can bulk update user options using a rails command, though it’s to be done with caution.
I suggest you first check how many users have this setting disabled using data explorer, for example. If the number isn’t high, you can set it manually or ask users to do it themselves.

I think you should also ensure what is the default value when an account is created.

2 Likes

Thank you can you please tell me the rails commands?

I have data explorer installed can you tell me script to see how many users have it enabled?

Thank you for your help really appreciate it. :heart:

By default, the Dark Mode user setting is “Same as regular”.

In the database, it’s defined by user_options.dark_scheme value being NULL.
“Dark” is -1. Other values are positive integers.

The query to return users that don’t have the default value would be:

SELECT 
    u.username,
    up.dark_scheme_id
FROM 
    users AS u
JOIN 
    user_options AS up
ON 
    u.id = up.user_id
WHERE up.dark_scheme_id IS NOT NULL
1 Like

There are 59 results.

Now how I can bulk change their settings with rails commands?

I’m a bit confused now. Why would you like to break user’s choise of colors? If you wouldn’ want to give choises then uninstall every other color schemes than default light and dark. That’s it.

You can reset this preference for the users that changed it with this rails script:

UserOption.where.not(dark_scheme_id: nil).find_each do |uo|
    uo.update(dark_scheme_id: nil)
end

I successfully used it on my test instance, but keep in mind I’m not a rails expert and, of course, always do a backup first. :slight_smile:

There are no choices. Just this setting is not enabled by default for many after I selected a dark color scheme for the automatic dark mode from the site settings.

I want this to be enabled for all. But there are 59 users that don’t have this enabled by default don’t know why.

Just to be clear, the setting in your screenshot is from the admin panel (server-wide), not a personal preference.

The latter being:

image

No, this is from user preference it shows for the users when you enable automatic dark mode from the site settings.

1 Like

So I have to do this to be clear:

cd /var/discourse

./launcher enter app

Then

UserOption.where.not(dark_scheme_id: nil).find_each do |uo|
    uo.update(dark_scheme_id: nil)
end

Right?

No, wait. I’m not sure I fully understand the request and I may lack some information about this dark mode setting :thinking:

The site admin I found is:

Where is the setting you’re talking about:

?

Please see this:

It’s all about this one.

Okay. I had to disable color schemes to have this option showing up. I’ll get another read to this topic so I understand better.

Yes! its " default dark mode color scheme id"

Okay, so unchecking “Enable automatic dark mode color scheme” sets user_options.dark_scheme to -1, and checking sets it to NULL.

So, if you want all users to have this setting checked, you can use my script.

The default setting when a new use is created is checked as well.

Do rails c after to enter the rails console.

If the script outputs a log, you can press q to exit it.

2 Likes

Okay I did this:

cd /var/discourse

./launcher enter app

rails c

Then

UserOption.where.not(dark_scheme_id: nil).find_each do |uo|
    uo.update(dark_scheme_id: nil)
end

It worked!

Now when I run the script of data explorer there are no results I also confirmed by opening one user preferences > interface to see if it is checked and yes it is now checked.

Thank you for your help :smiling_face_with_three_hearts:

1 Like