-
Notifications
You must be signed in to change notification settings - Fork 45
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
Cannot get NSDistributedNotificationCenter
to work with the addObserverForName:object:queue:usingBlock:
message
#644
Comments
The documentation for
That is, blocking the main thread using tokio and such is not sufficient for getting this event to trigger - you have to be actively polling the system using In general, the async story in Rust for GUI applications / functionality on macOS/iOS is not really fleshed out, if you can avoid it in this case, I'd suggest you do so (see also #279). |
Would it be better to just have a busy loop that polls the accent color like so, or would it be more efficient to figure out polling with let mut last = get_accent_color().await?.into_color();
let stream = stream! {
while let Ok(current) = get_accent_color().await {
let current_conv = current.into_color();
if last != current_conv {
last = current_conv;
yield current_conv;
}
}
}; |
Much more, as the OS can put the process to sleep (which a busy loop will not). But it depends on your use-case, maybe it'll be fine for you to check e.g. every 60 seconds whether the color changed. |
I'm going to close this issue, since it isn't really actionable, this is a fundamental limitation of Apple's frameworks that you have to know about to use them effectively. The best we can do, until #279 is resolved at an ecosystem level, is add more documentation, which I have done here as part of #650. Feel free to say if there's something in that documentation that's unclear, then I'll try to reword it! |
I'm working on a library that should allow for the fetching/listening of the OS's accent color setting similar to
dark-light
but for accent colors, I've got every OS working except macOS. For listening to the accent color changes, I've tried changing it in all sorts of ways, and it still will not notify on OS changes. Any help would be appreciated.Below here is the code I've written as a prototype to get it working, I'm creating a
NSDistributedNotificationCenter
using thedefaultCenter
message, I'm creating a block that transmits onto an unbounded channel, which is listened on for the accent color changes, the block is then wrapped into aRcBlock
and then I send theaddObserverForName:object:queue:usingBlock:
message with the block and the notification nameAppleColorPreferencesChangedNotification
. I'm not sure if my code calling objc2 is wrong, or not, but I also feel like there isn't a way it could be my non objc2 code, because the block, would be at least printing the debug message which is defined in the block. My code also uses an intermediary stream, so I can implementDrop
on the stream, because I'm using theasync-stream
crate, however, I'm not sure if this is required, so I'm also unsure about that. Also, sorry for the messy code.Additionally, for context I referenced some of the code from https://github.com/freethinkel/tauri-plugin-accent-color/blob/main/src/lib.rs, at first I tried writing this library with
objc2
, gave up, tried withobjc
, but still could not get it working, and then switched back toobjc2
however since the repo referenced is not written usingobjc2
, I had to figure out different ways of doing things for actually converting the accent color.The text was updated successfully, but these errors were encountered: