diff options
| author | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-06-27 21:18:09 +0200 |
|---|---|---|
| committer | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-06-27 21:18:09 +0200 |
| commit | b3964aefbcab8ff098afabf64befa04a4eebd993 (patch) | |
| tree | 6065486ff980edf04ab1844ad6ad424dde690d59 | |
| parent | 7728f7e1349cc40f8a1bc5c09f0e2ad6b2739c95 (diff) | |
Update mac version to use objc2
| -rw-r--r-- | Cargo.lock | 309 | ||||
| -rw-r--r-- | Cargo.toml | 9 | ||||
| -rw-r--r-- | src/sources/apple_music.rs | 58 | ||||
| -rw-r--r-- | src/sources/spotify.rs | 58 |
4 files changed, 228 insertions, 206 deletions
@@ -106,15 +106,18 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.4.2" +version = "2.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" +checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" [[package]] -name = "block" -version = "0.1.6" +name = "block2" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" +checksum = "340d2f0bdb2a43c1d3cd40513185b2bd7def0aa1052f956455114bc98f82dcf2" +dependencies = [ + "objc2", +] [[package]] name = "bumpalo" @@ -187,36 +190,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" [[package]] -name = "cocoa" -version = "0.26.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f79398230a6e2c08f5c9760610eb6924b52aa9e7950a619602baba59dcbbdbb2" -dependencies = [ - "bitflags 2.4.2", - "block", - "cocoa-foundation", - "core-foundation 0.10.0", - "core-graphics", - "foreign-types 0.5.0", - "libc", - "objc", -] - -[[package]] -name = "cocoa-foundation" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e14045fb83be07b5acf1c0884b2180461635b433455fa35d1cd6f17f1450679d" -dependencies = [ - "bitflags 2.4.2", - "block", - "core-foundation 0.10.0", - "core-graphics-types", - "libc", - "objc", -] - -[[package]] name = "colorchoice" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -233,46 +206,12 @@ dependencies = [ ] [[package]] -name = "core-foundation" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b55271e5c8c478ad3f38ad24ef34923091e0548492a266d19b3c0b4d82574c63" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] name = "core-foundation-sys" version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] -name = "core-graphics" -version = "0.24.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa95a34622365fa5bbf40b20b75dba8dfa8c94c734aea8ac9a5ca38af14316f1" -dependencies = [ - "bitflags 2.4.2", - "core-foundation 0.10.0", - "core-graphics-types", - "foreign-types 0.5.0", - "libc", -] - -[[package]] -name = "core-graphics-types" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d44a101f213f6c4cdc1853d4b78aef6db6bdfa3468798cc1d9912f4735013eb" -dependencies = [ - "bitflags 2.4.2", - "core-foundation 0.10.0", - "libc", -] - -[[package]] name = "cssparser" version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -364,6 +303,16 @@ dependencies = [ ] [[package]] +name = "dispatch2" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89a09f22a6c6069a18470eb92d2298acf25463f14256d24778e1230d789a2aec" +dependencies = [ + "bitflags 2.9.1", + "objc2", +] + +[[package]] name = "dtoa" version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -438,28 +387,7 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" dependencies = [ - "foreign-types-shared 0.1.1", -] - -[[package]] -name = "foreign-types" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d737d9aa519fb7b749cbc3b962edcf310a8dd1f4b67c91c4f83975dbdd17d965" -dependencies = [ - "foreign-types-macros", - "foreign-types-shared 0.3.1", -] - -[[package]] -name = "foreign-types-macros" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742" -dependencies = [ - "proc-macro2", - "quote 1.0.35", - "syn 2.0.96", + "foreign-types-shared", ] [[package]] @@ -469,12 +397,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" [[package]] -name = "foreign-types-shared" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b" - -[[package]] name = "form_urlencoded" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -809,9 +731,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.169" +version = "0.2.174" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" +checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" [[package]] name = "libdbus-sys" @@ -850,12 +772,13 @@ name = "lyricli" version = "4.0.0" dependencies = [ "clap", - "cocoa", "dbus", "libc", "mpris", - "objc", - "objc_id", + "objc2", + "objc2-app-kit", + "objc2-foundation", + "objc2-scripting-bridge", "percent-encoding", "reqwest", "scraper", @@ -871,15 +794,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" [[package]] -name = "malloc_buf" -version = "0.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb" -dependencies = [ - "libc", -] - -[[package]] name = "markup5ever" version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -963,21 +877,164 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" [[package]] -name = "objc" -version = "0.2.7" +name = "objc2" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1" +checksum = "88c6597e14493ab2e44ce58f2fdecf095a51f12ca57bec060a11c57332520551" dependencies = [ - "malloc_buf", + "objc2-encode", ] [[package]] -name = "objc_id" -version = "0.1.1" +name = "objc2-app-kit" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6f29f568bec459b0ddff777cec4fe3fd8666d82d5a40ebd0ff7e66134f89bcc" +dependencies = [ + "bitflags 2.9.1", + "block2", + "libc", + "objc2", + "objc2-cloud-kit", + "objc2-core-data", + "objc2-core-foundation", + "objc2-core-graphics", + "objc2-core-image", + "objc2-foundation", + "objc2-quartz-core", +] + +[[package]] +name = "objc2-cloud-kit" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17614fdcd9b411e6ff1117dfb1d0150f908ba83a7df81b1f118005fe0a8ea15d" +dependencies = [ + "bitflags 2.9.1", + "objc2", + "objc2-foundation", +] + +[[package]] +name = "objc2-core-data" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291fbbf7d29287518e8686417cf7239c74700fd4b607623140a7d4a3c834329d" +dependencies = [ + "bitflags 2.9.1", + "objc2", + "objc2-foundation", +] + +[[package]] +name = "objc2-core-foundation" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c10c2894a6fed806ade6027bcd50662746363a9589d3ec9d9bef30a4e4bc166" +dependencies = [ + "bitflags 2.9.1", + "dispatch2", + "objc2", +] + +[[package]] +name = "objc2-core-graphics" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "989c6c68c13021b5c2d6b71456ebb0f9dc78d752e86a98da7c716f4f9470f5a4" +dependencies = [ + "bitflags 2.9.1", + "dispatch2", + "objc2", + "objc2-core-foundation", + "objc2-io-surface", +] + +[[package]] +name = "objc2-core-image" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79b3dc0cc4386b6ccf21c157591b34a7f44c8e75b064f85502901ab2188c007e" +dependencies = [ + "objc2", + "objc2-foundation", +] + +[[package]] +name = "objc2-core-services" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "159be6e4cd366c7d236d798daa2aa71855230e5691cde045a0670ce01a06d664" +dependencies = [ + "bitflags 2.9.1", + "dispatch2", + "objc2", + "objc2-core-foundation", + "objc2-security", +] + +[[package]] +name = "objc2-encode" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef25abbcd74fb2609453eb695bd2f860d389e457f67dc17cafc8b8cbc89d0c33" + +[[package]] +name = "objc2-foundation" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "900831247d2fe1a09a683278e5384cfb8c80c79fe6b166f9d14bfdde0ea1b03c" +dependencies = [ + "bitflags 2.9.1", + "block2", + "libc", + "objc2", + "objc2-core-foundation", +] + +[[package]] +name = "objc2-io-surface" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7282e9ac92529fa3457ce90ebb15f4ecbc383e8338060960760fa2cf75420c3c" +dependencies = [ + "bitflags 2.9.1", + "objc2", + "objc2-core-foundation", +] + +[[package]] +name = "objc2-quartz-core" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90ffb6a0cd5f182dc964334388560b12a57f7b74b3e2dec5e2722aa2dfb2ccd5" +dependencies = [ + "bitflags 2.9.1", + "objc2", + "objc2-foundation", +] + +[[package]] +name = "objc2-scripting-bridge" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23d9f35649e7fe924558448da45d5554e12430284475612653f41c2051144fde" +dependencies = [ + "libc", + "objc2", + "objc2-core-services", + "objc2-foundation", +] + +[[package]] +name = "objc2-security" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c92d4ddb4bd7b50d730c215ff871754d0da6b2178849f8a2a2ab69712d0c073b" +checksum = "e1f8e0ef3ab66b08c42644dcb34dba6ec0a574bbd8adbb8bdbdc7a2779731a44" dependencies = [ - "objc", + "bitflags 2.9.1", + "objc2", + "objc2-core-foundation", ] [[package]] @@ -1001,9 +1058,9 @@ version = "0.10.64" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95a0481286a310808298130d22dd1fef0fa571e05a8f44ec801801e84b216b1f" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.9.1", "cfg-if", - "foreign-types 0.3.2", + "foreign-types", "libc", "once_cell", "openssl-macros", @@ -1313,7 +1370,7 @@ version = "0.38.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ea3e1a662af26cd7a3ba09c0297a31af215563ecf42817c98df621387f4e949" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.9.1", "errno", "libc", "linux-raw-sys", @@ -1402,7 +1459,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05b64fb303737d99b81884b2c63433e9ae28abebe5eb5045dcdd175dc2ecf4de" dependencies = [ "bitflags 1.3.2", - "core-foundation 0.9.4", + "core-foundation", "core-foundation-sys", "libc", "security-framework-sys", @@ -1424,7 +1481,7 @@ version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd568a4c9bb598e291a08244a5c1f5a8a6650bee243b5b0f8dbb3d9cc1d87fe8" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.9.1", "cssparser", "derive_more", "fxhash", @@ -1643,8 +1700,8 @@ version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" dependencies = [ - "bitflags 2.4.2", - "core-foundation 0.9.4", + "bitflags 2.9.1", + "core-foundation", "system-configuration-sys", ] @@ -21,10 +21,11 @@ serde_json = "1.0.137" tokio = { version = "1.43.0", features = ["full"] } [target.'cfg(target_os = "macos")'.dependencies] -libc = "0.2.169" -objc = "0.2.7" -cocoa = "0.26.0" -objc_id = "0.1.1" +libc = "0.2.174" +objc2 = "0.6.1" +objc2-foundation = "0.3.1" +objc2-app-kit = { version = "0.3.1", features = ["NSWorkspace"] } +objc2-scripting-bridge = "0.3.1" [target.'cfg(target_os = "linux")'.dependencies] dbus = { version = "0.9.6", features = ["vendored"] } diff --git a/src/sources/apple_music.rs b/src/sources/apple_music.rs index 6279a50..572fe6b 100644 --- a/src/sources/apple_music.rs +++ b/src/sources/apple_music.rs @@ -1,16 +1,12 @@ -use std::ffi::CStr; use std::io::Result; -use cocoa::{ - base::{id, nil}, - foundation::NSString, +use objc2::{ + msg_send, + rc::{Retained, autoreleasepool}, + runtime::AnyObject, }; -use objc::{ - class, msg_send, - runtime::{Class, Object}, - sel, sel_impl, -}; -use objc_id::Id; +use objc2_foundation::NSString; +use objc2_scripting_bridge::SBApplication; use crate::Track; @@ -31,36 +27,22 @@ impl LyricsSource for AppleMusic { fn current_track(&self) -> Option<Track> { unsafe { - let app: Id<Object> = { - let cls = class!(SBApplication); - let bundle_identifier = NSString::alloc(nil).init_str("com.apple.Music"); - - let workspace_class = Class::get("NSWorkspace").unwrap(); - let shared_workspace: id = msg_send![workspace_class, sharedWorkspace]; - let app_url: id = msg_send![shared_workspace, URLForApplicationWithBundleIdentifier:bundle_identifier]; - - if app_url != nil { - let app: *mut Object = - msg_send![cls, applicationWithBundleIdentifier:bundle_identifier]; - Id::from_ptr(app) - } else { - return None; - } - }; - - if msg_send![app, isRunning] { - let current_track: *mut Object = msg_send![app, currentTrack]; - if !current_track.is_null() { - let name_raw: *mut Object = msg_send![current_track, name]; - let artist_raw: *mut Object = msg_send![current_track, artist]; - - let name_ptr: *const i8 = msg_send![name_raw, UTF8String]; - let artist_ptr: *const i8 = msg_send![artist_raw, UTF8String]; + let bundle_identifier = NSString::from_str("com.apple.Music"); + let app = SBApplication::applicationWithBundleIdentifier(&bundle_identifier); + if let Some(app) = app + && app.isRunning() + { + let current_track: Option<Retained<AnyObject>> = msg_send![&app, currentTrack]; + if let Some(current_track) = current_track { + let name_raw: Option<Retained<NSString>> = msg_send![¤t_track, name]; + let artist_raw: Option<Retained<NSString>> = msg_send![¤t_track, artist]; - let name = CStr::from_ptr(name_ptr).to_string_lossy().into_owned(); - let artist = CStr::from_ptr(artist_ptr).to_string_lossy().into_owned(); + if let (Some(name_raw), Some(artist_raw)) = (name_raw, artist_raw) { + let name = autoreleasepool(|pool| name_raw.to_str(pool).to_string()); + let artist = autoreleasepool(|pool| artist_raw.to_str(pool).to_string()); - return Some(Track { name, artist }); + return Some(Track { name, artist }); + } } } } diff --git a/src/sources/spotify.rs b/src/sources/spotify.rs index bd627db..cd37491 100644 --- a/src/sources/spotify.rs +++ b/src/sources/spotify.rs @@ -1,16 +1,12 @@ -use std::ffi::CStr; use std::io::Result; -use cocoa::{ - base::{id, nil}, - foundation::NSString, +use objc2::{ + msg_send, + rc::{Retained, autoreleasepool}, + runtime::AnyObject, }; -use objc::{ - class, msg_send, - runtime::{Class, Object}, - sel, sel_impl, -}; -use objc_id::Id; +use objc2_foundation::NSString; +use objc2_scripting_bridge::SBApplication; use crate::Track; @@ -31,36 +27,22 @@ impl LyricsSource for Spotify { fn current_track(&self) -> Option<Track> { unsafe { - let app: Id<Object> = { - let cls = class!(SBApplication); - let bundle_identifier = NSString::alloc(nil).init_str("com.spotify.Client"); - - let workspace_class = Class::get("NSWorkspace").unwrap(); - let shared_workspace: id = msg_send![workspace_class, sharedWorkspace]; - let app_url: id = msg_send![shared_workspace, URLForApplicationWithBundleIdentifier:bundle_identifier]; - - if app_url != nil { - let app: *mut Object = - msg_send![cls, applicationWithBundleIdentifier:bundle_identifier]; - Id::from_ptr(app) - } else { - return None; - } - }; - - if msg_send![app, isRunning] { - let current_track: *mut Object = msg_send![app, currentTrack]; - if !current_track.is_null() { - let name_raw: *mut Object = msg_send![current_track, name]; - let artist_raw: *mut Object = msg_send![current_track, artist]; - - let name_ptr: *const i8 = msg_send![name_raw, UTF8String]; - let artist_ptr: *const i8 = msg_send![artist_raw, UTF8String]; + let bundle_identifier = NSString::from_str("com.spotify.Client"); + let app = SBApplication::applicationWithBundleIdentifier(&bundle_identifier); + if let Some(app) = app + && app.isRunning() + { + let current_track: Option<Retained<AnyObject>> = msg_send![&app, currentTrack]; + if let Some(current_track) = current_track { + let name_raw: Option<Retained<NSString>> = msg_send![¤t_track, name]; + let artist_raw: Option<Retained<NSString>> = msg_send![¤t_track, artist]; - let name = CStr::from_ptr(name_ptr).to_string_lossy().into_owned(); - let artist = CStr::from_ptr(artist_ptr).to_string_lossy().into_owned(); + if let (Some(name_raw), Some(artist_raw)) = (name_raw, artist_raw) { + let name = autoreleasepool(|pool| name_raw.to_str(pool).to_string()); + let artist = autoreleasepool(|pool| artist_raw.to_str(pool).to_string()); - return Some(Track { name, artist }); + return Some(Track { name, artist }); + } } } } |