-
Notifications
You must be signed in to change notification settings - Fork 16
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
Notifications #26
Notifications #26
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a driveby review from someone who wants to use this crate in a project, disregard what you or the crate owner would like to:
src/freedesktop/notify.rs
Outdated
async fn non_freedesktop_watch(tx: Sender<Mode>) -> anyhow::Result<()> { | ||
let mut mode = detect(); | ||
loop { | ||
let new_mode = detect(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a busy loop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'm still figuring out a way to replace this loop with something better, suggestions are welcome.
8b81313
to
bf1e9a2
Compare
The Linux implementation should be good to go, macOS and Windows still need some work. @frewsxcv could you help me test these changes? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/freedesktop/detect.rs
Outdated
use super::{CINNAMON, GNOME, MATE}; | ||
|
||
pub fn detect() -> Mode { | ||
match legacy_detect() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might also want to check for the freedesktop.portal color theme by blocking on this async fn https://docs.rs/ashpd/latest/ashpd/desktop/settings/struct.Settings.html#method.color_scheme
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to do this without locking the crate to a specific runtime?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure which would be the right way to do that. Maybe using block_on
from async_io
and switch to tokoi
s if the tokio
feature is enabled (that's the way, zbus offers it's blocking APIs).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I'll implement more runtimes it once we test with tokio
.
I encountered this as well using KDE Plasma, oddly I could not replicate this when switching the color scheme using the terminal. |
5751efd
to
f7ac529
Compare
For me there are duplicates also when I use |
I tried with Color Scheme Simulator and I wasn't able to replicate the issue. This may be related either to how DEs handle the color scheme change or ashpd. |
It is not related to ashpd, it is a portal backend issue. As they listen to changes happening on the host and forward them through the portal, the signal ends up being emitted twice |
f4e93ed
to
f5e7a95
Compare
I haven't tested on macOS but Windows and Linux are working fine. The current implementation is using @frewsxcv Would you mind taking a look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I Just took a quick look on this.
I'm thinking about, what a ThemeWatcher
really is, and I believe it really is just a Stream
. So the most obvious interface to me would be similar to ashpd's: a function returning a stream. I don't know how difficult it is to implement for platforms that are not supported by ashpd. An advantage might be, that the only dependency needed would be stream_utils.
@d2weber is this what you had in mind? use std::task::Poll;
use futures::{stream, Stream};
use crate::{detect, Mode};
#[derive(Debug)]
pub enum Event<T> {
ThemeChanged(T),
Waiting,
}
pub fn subscribe() -> impl Stream<Item = Event<Mode>> + Send {
let mut last_mode = detect();
stream::poll_fn(move |_| -> Poll<Option<Event<Mode>>> {
let current_mode = detect();
if current_mode != last_mode {
last_mode = current_mode;
Poll::Ready(Some(Event::ThemeChanged(current_mode)))
} else {
Poll::Ready(Some(Event::Waiting))
}
})
} This is how you would consume it. let mut stream = subscribe();
while let Some(event) = stream.next().await {
if let Event::ThemeChanged(mode) = event {
println!("System theme changed: {:?}", mode);
}
} I was returning an |
bb379d9
to
ccbbe8a
Compare
I re-implemented this to use If someone could help me review before merging I'd appreciate it. |
saw that a review was requested of me the other day, can probably get to this sometime during the week if that works? Definitely think a |
- Updated ashpd
- Removed Settings struct as it was not necessary. - Removed `Settings` parameter from `freedesktop_watch`. - `get_freedesktop_color_scheme` matches `ColorScheme` instead of `u32`
When the settings proxy is unable to init, legacy is used as fallback.
- Upgraded to the master branch of ashpd - Moved the thread spawning to `notify` - Made the async methods return `anyhow::Result<T>`
- Using xdg to find config files on Linux/BSD systems. - Quality of life improvements
- Cleaned Cargo.toml - Modified notify to take a closure.
- Fix wasm issue.
- Moved RGB logic to a single file. - Added documentation.
- Added ThemeWatcher, a new struct which allows users to subscribe and receive notifications when the theme changes. - New crate organization. * Currently only Windows has been implemented. * Currently only tokio has been implemented, we can add new implementations as features in the future.
- Added support for Freedesktop.
- Added generic implementation for all platforms except freedesktop.
- The stream is now using Poll::Pending to wait for a new event instead of returning a value when waiting.
3385153
to
cffa75c
Compare
@edfloreshz Was there a reason tokio was added as a dependency here? It seems it's only being used in the example? Also curious why zbus was bumped down? |
Yeah, it was added as a dev-dependency to showcase the example. As for zbus, that might've been an oversight on my end. |
@edfloreshz the latest build is from April 3, but this was merged 10 days later. Could you cut a new release? |
Made an issue to keep track of this: #38 |
Zbus has become a transient dependency through ashpd |
Implements a
subscribe
function that returns a stream that yields a new mode every time a theme change is detected in the OS.Closes #3