Skip to content

Commit 8247ec7

Browse files
committed
Add a function to get os version
1 parent ab933e7 commit 8247ec7

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ mach = "0.3"
1919
audio-mixer = "0.1"
2020
ringbuf = "0.2.6"
2121
triple_buffer = "5.0.5"
22+
plist = "1"

src/backend/utils.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,21 @@ pub fn finally<F: FnOnce()>(f: F) -> Finalizer<F> {
5656
Finalizer(Some(f))
5757
}
5858

59+
pub fn os_version() -> Result<String, cubeb_backend::Error> {
60+
if let Some(s) = plist::Value::from_file("/System/Library/CoreServices/SystemVersion.plist")
61+
.map_err(|e| {
62+
cubeb_log!("Could not read SystemVersion.plist. Error: {}", e);
63+
cubeb_backend::Error::error()
64+
})?
65+
.as_dictionary()
66+
.and_then(|dict| dict.get("ProductVersion"))
67+
.and_then(|version| version.as_string())
68+
{
69+
return Ok(s.to_string());
70+
}
71+
Err(cubeb_backend::Error::error())
72+
}
73+
5974
#[test]
6075
fn test_forget_vec_and_retake_it() {
6176
let expected: Vec<u32> = (10..20).collect();
@@ -105,3 +120,8 @@ fn test_finally() {
105120
}
106121
assert_eq!(x, 100);
107122
}
123+
124+
#[test]
125+
fn test_os_version() {
126+
assert!(!os_version().unwrap().is_empty());
127+
}

0 commit comments

Comments
 (0)