-
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
macOS: Notes on notification detection #47
Comments
Hmm, I'm wondering if we should make the async API platform-specific until someone steps up to implement proper async support for every OS... |
Also, it spikes the CPU to maximum as soon as running the |
Hmm, I don't think #50 fixes the polling issue? It just moves the polling to a separate thread that busy loops instead... |
I'll see if I can apply the suggestions today, I'll open this again. |
I think we should release 2.0 with async being platform-specific then. |
@madsmtm I tried your suggestions, but I'm not very familiar with Apple APIs. I'm very interested in implementing this, though. Would you mind if I picked your brain a little? |
I managed to get it working, however, the only reliable way I found requires creating an application and running it, effectively blocking the main thread. Is there a way to do it without running the app? It appears that |
Well, if it was easy to fix I'd have done it myself ;)
I don't know, did you try the If you can make it work with |
I'm not familiar with Objective C or how to work with macOS's platform APIs directly. Are you suggesting that dark_light could provide a helper function that would return some struct to the caller that the caller would then be responsible for running on whatever event loop the caller has running on their side? |
It looks like That would leave this crate only responsible for detection and not notification. |
We could reasonably provide the following API: struct NotificationListener(...);
impl Drop for NotificationListener {
// Unregister the notification
}
/// Note: For this to trigger, you must have the application event loop running.
fn listen(callback: impl Fn(Mode) + Send + 'static) -> NotificationListener {
// Register notification listener
}
That's a good compromise, I think. Preferably with documentation in the crate docs itself that notification detection isn't possible cross-platform, and what the user should do instead. |
I looked at the implementation of this in winit for Wayland and it's not what it seems. The |
I was actually referring to |
winit also has a And, judging by @madsmtm's comments here (please correct me if I misunderstand), the only way to get light/dark mode updates on macOS is for it to be handled by the windowing crate (and maybe by the downstream application?) but it's not possible for an intermediate library like this that is neither the windowing crate nor the end user application to handle. 😵 So where do we go from here? Should this crate continue to exist, or should we deprecated and tell people to use winit's API? But then we'd need to make the winit API actually work on Linux... which I don't look forward to, considering a winit maintainer has already expressed opposition to. Plus, it would be difficult to use zbus in winit because winit isn't an async executor so using zbus in winit would require running an executor in a separate thread and passing data back to the main thread. While most Rust GUI applications use winit, it's not universal, so... maybe it would make sense for this crate to exist independently, and adapt it so winit can use this crate internally? This is such a messy situation for something that should be quite simple. Just looking at Slint for example, they first used this crate, then removed it citing compile times, then of course users complained, then they used ashpd on their own to fill in the gap where winit doesn't work despite winit working for other platforms. |
If you ask me, the sanest approach would be to remove I would've loved to have that in this library but it just doesn't appear to be a feasible option due to platforms specific limitations. What do you think @Be-ing? |
I'm not familiar with Linux enough to comment on whether an implementation of But it seems like you have a working implementation, so I'd suggest you open an issue? |
The current detection mechanism just runs
detect
in a loop, which is woefully inefficient. Details on more efficient implementation options in #37 (comment) and https://github.com/cormacrelf/dark-notify/blob/master/src/app.rs.Also, it doesn't actually work, see #29. I suspect that the problem is that we need to be running the main application with
NSApplication::run
orNSApplicationMain
for this to work? But semantically, that probably isn't really something thatrust-dark-light
should be doing, so unsure what to do.Even if that isn't the problem, or it can be worked around by using
"AppleInterfaceThemeChangedNotification"
, another problem is that most Rust async runtimes don't support mach ports, and as such wouldn't update since notifications arrive via. those, I think? See madsmtm/objc2#279 for that.The text was updated successfully, but these errors were encountered: