frewsxcv / rust-dark-light

Rust crate to detect if dark mode or light mode is enabled
https://crates.io/crates/dark-light
73 stars 12 forks source link

Add new function that takes a callback which gets run whenever dark/light mode changes #3

Closed frewsxcv closed 2 months ago

frewsxcv commented 3 years ago
edfloreshz commented 2 years ago

I'm on it!

frewsxcv commented 2 years ago

Some relevant macOS links:

edfloreshz commented 2 years ago

I have a working function that takes a callback.

I'm calling dark-light::detect on a loop and invoking the callback function when the theme changes.

I want to leave this behavior for distros that haven't yet implemented color-scheme since there's no single way we can get every DE to notify us of a change in theme. Let me know if there's a better way to do this.

For the ones that have, I would like to get a notification from dbus when that key changes value, can dbus do that?

Be-ing commented 2 years ago

Yes you can get a notification from dbus. That would be better than a perpetual loop.

edfloreshz commented 2 years ago

Any ideas for distros that haven't implemented color-scheme? I really don't like that loop 😅

Be-ing commented 2 years ago

For the ones that rely on config files, you could use https://lib.rs/crates/notify

edfloreshz commented 2 years ago

I considered using that crate, I'll see what I can do. 😉

edfloreshz commented 2 years ago

Yes you can get a notification from dbus. That would be better than a perpetual loop.

I have little experience working with dbus, could you point me in the right direction?

Be-ing commented 2 years ago

I don't have much experience with dbus either, but I do know it can emit signals that your application can receive. This looks like the signal we want.

edfloreshz commented 2 years ago

Big help! Thanks 🙏🏼

d2weber commented 11 months ago

See this repo where I implemented listening color scheme preferences from freedesktops dbus: https://github.com/d2weber/tintanum