Tyrrrz / LightBulb

Reduces eye strain by adjusting screen gamma based on the current time
MIT License
2.23k stars 141 forks source link

UI breaks if Windows switches dark/light themes #296

Closed LilithSilver closed 4 months ago

LilithSilver commented 4 months ago

Version

v2.4.12

Platform

Windows 10

Steps to reproduce

Step 1: Open LightBulb Step 2: Switch the Windows theme in Settings

Details

image image

The only way out is restarting the app.

The reason for this is that, when the system theme changes, MaterialTheme reloads the theme and applies the requested theme. However, it doesn't re-apply the theme created in App.axml.cs, instead using the default empty theme. Since no colors are added by default, nothing displays!

I have a fix for this, but there are several different options, and I want to get your opinion. Here's a branch with the changes for option 2. It still needs some work, but I wanted to get your thoughts before I go ahead on opening a PR.

Option 1: Allow dark mode and don't touch the accent colors

Dark mode is available by default with the correct approach, and everything works OK (with an update to Material 3.6):

image image

Light mode would remain identical (Ignore the darkened lightbulb icon; I'd fix that if we took this approach).

However, notice how the sliders are difficult to see.

Option 2: Allow dark mode and choose a reasonable accent color that works with light/dark

To fix the issue with option 1, a different accent color can be chosen (this is just an example):

image

Light mode would look like: image

Option 3: Force light mode

Light mode can be forced by setting BaseTheme="Light" on the MaterialTheme element and specifying the custom accent colors as brush resource overrides. This is the simplest option, but I'd prefer to have dark mode because light mode hurts my eyes. (And this application seems important to make easy on the eyes).

Option 4: Change color configurations between light and dark mode

I don't know how to do this option with the Material library for Avalonia. I would likely need to open an issue and ask the dev. If changing the color configurations between dark/light mode isn't possible in the current state, it should be, considering the material guidelines recommend it.

Checklist

Tyrrrz commented 4 months ago

I'd say forcing the light mode is the easiest solution and we should do that. To fully support dark mode, we'd have to do a design pass and make sure all colors align well with each other, which would be a decent chunk of effort. We can have a separate issue to track dark mode, but the simple solution would be an immediate fix to the problem you described.

Also, the library docs do recommend changing colors through code as it's done now: https://github.com/AvaloniaCommunity/Material.Avalonia/wiki/Advanced-Theming#itheme-manipulation

Does setting them as resources ensures the correct colors stay in sync with the preferred theme?

LilithSilver commented 4 months ago

Does setting them as resources ensures the correct colors stay in sync with the preferred theme?

Yep!

Also, the library docs do recommend changing colors through code as it's done now: https://github.com/AvaloniaCommunity/Material.Avalonia/wiki/Advanced-Theming#itheme-manipulation

The PR uses the strategy from here. Our current approach is actually incorrect, which is probably what's causing the issue -- we should be using MaterialThemeBase as specified instead of MaterialTheme, but I had some errors with DialogHost when I tried to use that. This method is simpler.

We can have a separate issue to track dark mode

Would you mind making that issue (since the repo is in maintenance-only mode)? If there is indeed interest in implementing dark mode, I can work on that. (If not, let me know and I'll skip it.)

Tyrrrz commented 4 months ago

Would you mind making that issue (since the repo is in maintenance-only mode)? If there is indeed interest in implementing dark mode, I can work on that. (If not, let me know and I'll skip it.)

I created #298