frewsxcv / rust-dark-light

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

macOS: Notes on notification detection #47

Open madsmtm opened 1 month ago

madsmtm commented 1 month ago

The current detection mechanism just runs detect in a loop, which is woefully inefficient. Details on more efficient implementation options in https://github.com/frewsxcv/rust-dark-light/pull/37#issuecomment-2123412904 and https://github.com/cormacrelf/dark-notify/blob/master/src/app.rs.

Also, it doesn't actually work, see https://github.com/frewsxcv/rust-dark-light/issues/29. I suspect that the problem is that we need to be running the main application with NSApplication::run or NSApplicationMain for this to work? But semantically, that probably isn't really something that rust-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 https://github.com/madsmtm/objc2/issues/279 for that.

Be-ing commented 1 month ago

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...

casperstorm commented 3 weeks ago

Also, it spikes the CPU to maximum as soon as running the notify example.