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

Add system theme to site themes #20107

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

nshki
Copy link

@nshki nshki commented Nov 8, 2022

Issue

Closes #10976.

Overview

This PR adds a "System settings" option to site themes, allowing users to not have to explicitly select their preferred app theme whenever they change light/dark mode on their OS. This PR takes into consideration the raised points in #10976. Notably:

  1. Makes the app respect system settings by default for unauthenticated users
  2. Gives authenticated users the option to select "System settings" on top of all the existing theme options
  3. Additionally makes bordered emojis still work in all theme scenarios: light, dark, high contrast, and system settings

Screenshots/video

image

Screen.Recording.2022-11-08.at.1.31.58.AM.mov

Misc notes

I just wanted to say thank you Eugen and all the maintainers for this wonderful project. As a recent adopter of Mastodon, I'm super enthusiastic about its future and hope to be able to make small contributions when I can.

config/locales/en.yml Outdated Show resolved Hide resolved
Copy link
Contributor

@ClearlyClaire ClearlyClaire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this looks like a really good change, though I need to think about it a bit more as far as third-party themes are concerned (many instances fork the code and add a theme).

With my glitch-soc (a Mastodon fork) hat on, I'm also a bit concerned about how I'd port that to glitch-soc's theming system, but obviously that should not be a showstopper for upstream.

app/javascript/mastodon/features/emoji/emoji.js Outdated Show resolved Hide resolved
@nshki
Copy link
Author

nshki commented Nov 8, 2022

Thanks for the prompt review, @ClearlyClaire! And thanks for the added insight—didn't know that it was common for forks to exist that added themes. I'm all ears on any suggestions should you think of any.

Use "Automatic (use system theme)" per suggested commented in GitHub.
@nshki nshki changed the title Add "System settings" to site themes Add system theme to site themes Nov 8, 2022
@ineffyble ineffyble added the ui Front-end, design label Nov 14, 2022
@ben-mcginty
Copy link

Have you considered having the 'system' theme just switch between a user-selected light and dark theme?
That might mitigate the issues of being stuck with the default themes.

@nshki
Copy link
Author

nshki commented Nov 15, 2022

Have you considered having the 'system' theme just switch between a user-selected light and dark theme? That might mitigate the issues of being stuck with the default themes.

That's a great point. @Gaelan had a great proof of concept in #10976 that allowed for user-selected light/dark themes. I wasn't considering custom themes and thought that having a system theme option would be simpler, but now that I'm aware of the existence of custom themes, maybe that's a better approach.

@ClearlyClaire would having explicit, user-selected light/dark themes make it easier for forks like glitch-soc to pull from upstream?

@ben-mcginty
Copy link

I was thinking something along these lines for the settings menu (sorry about burning your eyeballs).

themeMockup

@nshki
Copy link
Author

nshki commented Nov 17, 2022

I like that! (No eyeballs were burned.)

There was a comment in the associated issue that shows a similar idea where the user checks an option to explicitly select different themes for light and dark mode. I'm leaning towards perhaps adding a "dark mode theme" dropdown that gets shown when the checkbox is checked.

@ClearlyClaire
Copy link
Contributor

Sorry for coming back to this late, but I was kinda busy with other things—including the security fix that touched some of that very code.

Thinking about it, I think being able to configure themes separately would indeed be good, but I think this can be a separate improvement. Having an automatic selection between two defaults theme would already be an improvement.

@nshki
Copy link
Author

nshki commented Nov 17, 2022

Sorry for coming back to this late, but I was kinda busy with other things—including the security fix that touched some of that very code.

No worries at all! I figured you probably have a lot of other things to deal with. Thanks for taking the time to chip in here.

Thinking about it, I think being able to configure themes separately would indeed be good, but I think this can be a separate improvement. Having an automatic selection between two defaults theme would already be an improvement.

And understood! I'll spend some time fixing up the merge conflicts and will rewrite the markup generation portion using DOM functions instead of a template string. Happy to work on the theme configuration PR separately once everything is good here as well.

EDIT: I've pushed a commit that resolves merge conflicts and swaps template string usage for document.createElement and Element.setAttribute calls.

@nshki
Copy link
Author

nshki commented Nov 23, 2022

Ah, I was just checking the contributing guidelines and missed the part about authorizing CircleCI to run things from my forked repo. Just logged into CircleCI and gave it access to my forked mastodon repo, so hopefully the workflows will now work?

EDIT: Hm. It seems like there are a few issues:

  1. Builds don't trigger automatically on CircleCI after authorizing with my forked repo. I had to set a manual trigger to get it to run.
  2. The suite fails on the "Precompile assets" step, which I assume is because of missing secrets.
  3. The status of the CI run isn't reflected on this PR.

I'm likely missing something here. If someone could give me pointers, that would be appreciated.

EDIT: Found the source of the precompile:assets error which I attempt to address in 45d9ee7.

ClearlyClaire
ClearlyClaire previously approved these changes Nov 28, 2022
@nightpool
Copy link
Member

This change would default Mastodon to using the light theme for the vast majority of users, including unauthenticated users and users who haven't specifically overridden it. I do not believe our light theme is in a polished enough state for this change to be merged and I would strongly suggest we continue use the dark theme as the "default" theme unless the user has manually chosen to override it.

@Cykelero
Copy link

As a counterpoint: right now, for any instance you don't have an account on, it's impossible to choose a theme at all.
(and it feels impractical to create one account per instance just to switch to a light theme)

So, I feel like the downside of having the light theme become default (for users who haven't set their browser/OS to dark mode), might be easily outweighed by everyone gaining the ability to choose between light and dark for all Mastodon instances they visit.

@nshki
Copy link
Author

nshki commented Nov 30, 2022

@nightpool while I definitely understand the concern, I haven't seen any indication that the light theme is too unpolished. (I've been using the light theme for a majority of my time with Mastodon web.) Are there any specific examples that come to mind?

@Cykelero also brings up a great point that I agree with—giving unauthenticated users the ability to pick a theme depending on their OS preferences seems to outweigh the cons here.

ineffyble and others added 3 commits December 11, 2022 00:22
This bundles the new application stylesheet pack tags into a shared
partial that's then used across multiple layouts. This wasn't necessary
before because only one pack tag was being rendered based on the user's
current theme. Now we must conditionally render different pack tags with
media queries if applicable.
Follow-up from last commit. This attempts to fix an issue where
`Warden::Proxy` isn't available during the precompilation step. Instead
of calling out to `current_theme` in layouts where it didn't previously,
this reverts the rendering of stylesheet pack tags to explicit
stylesheets in `layouts/embedded.html.haml` and
`layouts/error.html.haml`.
@nshki
Copy link
Author

nshki commented Dec 10, 2022

I'm still not sure why they aren't reflected in the build-and-test workflow for the PR, but after some investigating, I've found and fixed the build errors.

image

@anthonypwinning
Copy link

I'd just like to say a thank you to everyone. IMHO this is an invaluable addition.

@github-actions
Copy link
Contributor

github-actions bot commented Jun 8, 2023

This pull request has resolved merge conflicts and is ready for review.

@github-actions
Copy link
Contributor

This pull request has merge conflicts that must be resolved before it can be merged.

@github-actions
Copy link
Contributor

This pull request has resolved merge conflicts and is ready for review.

@Ein-Tim
Copy link

Ein-Tim commented Jun 28, 2023

Whats the status of this PR?

@github-actions
Copy link
Contributor

This pull request has merge conflicts that must be resolved before it can be merged.

@github-actions
Copy link
Contributor

This pull request has resolved merge conflicts and is ready for review.

@bondolo
Copy link

bondolo commented Aug 8, 2023

@Gargron Any chance of getting this merged for 4.2.0? Eagerly awaiting this feature and disappointed to see it lingering for months at final review

@Mennaruuk
Copy link

@Gargron It would be great if this PR can be merged for 4.2.2. Competing social networks, such as Bluesky and Threads, already have auto dark mode, and it's on by default.

Copy link
Contributor

github-actions bot commented Jan 9, 2024

This pull request has merge conflicts that must be resolved before it can be merged.

Copy link
Contributor

github-actions bot commented Jan 9, 2024

This pull request has resolved merge conflicts and is ready for review.

Using single quotes instead of double quotes where interpolation isn't needed.
@damianvila
Copy link

Got tired of waiting, and I'm actually using an alternative web client. Good luck with this PR.

Copy link
Contributor

This pull request has merge conflicts that must be resolved before it can be merged.

Copy link
Contributor

This pull request has resolved merge conflicts and is ready for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ui Front-end, design
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Automatically switch between dark/light mode via prefers-color-scheme