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

feat: theme switcher #299

Draft
wants to merge 1 commit into
base: release/v0.7.0
Choose a base branch
from

Conversation

hecht-a
Copy link

@hecht-a hecht-a commented Jan 5, 2025

Hello,
I was thinking that the ability to change themes was missing. So I implemented this feature.

We can define 2 themes: light and dark.
The theme changes automatically depending on the device theme (it's also possible to disable this behaviour using the sync-device-theme: false configuration).

Here's an example configuration for a light & dark theme with the theme synchronised with the device theme :

theme:
  default-color-scheme: light
  sync-device-theme: true
  light:
    background-color: 220 23 95
    contrast-multiplier: 1.0
    primary-color: 220 91 54
    positive-color: 109 58 40
    negative-color: 347 87 44
  dark:
    background-color: 229 19 23
    contrast-multiplier: 1.2
    primary-color: 222 74 74
    positive-color: 96 44 68
    negative-color: 359 68 71

There's also a button at the top left of the page to change the theme directly from the app.
Capture d’écran 2025-01-05 à 01 31 43
Capture d’écran 2025-01-05 à 01 32 02

Don't hesitate to let me know if I need to change anything or be clearer in the documentation.

@svilenmarkov
Copy link
Member

Hey, thanks for contributing!

I try very hard not to introduce backwards-incompatible changes for the config such as this one and I think there's a way to avoid doing that here. In addition, I believe it would be more practical if rather than enforcing sync-device-theme: true everywhere, the user had the option to choose this on a per-device basis, as you might want this behavior on your phone but not on your desktop. Here's vaguely what I have in mind in order to be able to achieve both of these:

  • Glance should provide its own default light theme
  • Users can define theme "presets" in the config
  • The front-end should provide a dropdown, allowing you to choose between:
    • Default (the theme defined in the config as is currently)
    • Auto light/dark (using the default dark/light theme provided by Glance)
    • User-defined preset #​1 (if any)
    • User-defined preset #​2 (if any)
    • User-defined preset #​3 (if any)
  • The default dark/light themes can be overridden in the config by specifying a different preset

The config for all of that may look something along the lines of:

theme:
  background-color: 255 14 6
  primary-color: 156 50 65
  negative-color: 342 65 65

  light-theme-preset: my-custom-light-theme
  dark-theme-preset: my-custom-dark-theme

  presets: 
    my-custom-dark-theme:
      background-color: 225 14 15
      primary-color: 157 47 65
      contrast-multiplier: 1.1
    my-custom-light-theme: 
      light: true
      background-color: 0 0 95
      primary-color: 0 0 10
      negative-color: 0 90 50

Where:

  • light-theme-preset and dark-theme-preset are optional and if not provided will fallback to the defaults from Glance
  • Preset names are user-defined, can be anything, but must be unique
  • You can define as many presets as you want

Implementation-wise, selecting a theme would just set a cookie with either:

  • No value or delete the cookie, which would use the default theme
  • Some special value for auto light/dark
  • The name of the chosen preset

Some potentially nasty-looking CSS wizardry might be needed to get all of that overriding behavior working properly, along with being able to change themes on the fly without a page reload.

I've put a little bit of work into implementing this idea but am currently trying to finish things around the v0.7.0 release so haven't made further progress. I'll get back to it once that's out.

@hecht-a hecht-a marked this pull request as draft January 8, 2025 08:49
@hecht-a
Copy link
Author

hecht-a commented Jan 8, 2025

Hello,

Thanks for the feedback. I didn't have in mine that you don't want backwards-incompatible changes.
I'll apply these changes very soon 😄

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

Successfully merging this pull request may close these issues.

2 participants