From 890bff7faff9a7fe95e5d87338f36045f843f7ea Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Tue, 10 Jan 2023 18:58:35 -0700 Subject: [PATCH] macos: add version info to system name --- Cargo.lock | 1 + window/Cargo.toml | 1 + window/src/os/macos/connection.rs | 26 +++++++++++++++++++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index db8f4316a..6a7e46eb0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6290,6 +6290,7 @@ dependencies = [ "metrics", "mio", "objc", + "plist", "promise", "raw-window-handle", "resize", diff --git a/window/Cargo.toml b/window/Cargo.toml index 15b16ab98..78f69f75a 100644 --- a/window/Cargo.toml +++ b/window/Cargo.toml @@ -90,3 +90,4 @@ clipboard_macos = "0.1" core-foundation = "0.7" core-graphics = "0.19" cgl = "0.3" +plist = "1.3" diff --git a/window/src/os/macos/connection.rs b/window/src/os/macos/connection.rs index 1f528d8ea..c03d6283c 100644 --- a/window/src/os/macos/connection.rs +++ b/window/src/os/macos/connection.rs @@ -13,6 +13,7 @@ use cocoa::base::{id, nil}; use cocoa::foundation::{NSArray, NSInteger, NSRect}; use objc::runtime::{Object, BOOL, YES}; use objc::*; +use serde::Deserialize; use std::cell::RefCell; use std::collections::HashMap; use std::rc::Rc; @@ -81,9 +82,32 @@ impl Connection { } } +/// `/System/Library/CoreServices/SystemVersion.plist` +#[derive(Deserialize, Debug)] +#[serde(rename_all = "PascalCase")] +struct SoftwareVersion { + product_build_version: String, + product_user_visible_version: String, + product_name: String, +} + +impl SoftwareVersion { + fn load() -> anyhow::Result { + let vers: Self = plist::from_file("/System/Library/CoreServices/SystemVersion.plist")?; + Ok(vers) + } +} + impl ConnectionOps for Connection { fn name(&self) -> String { - "macOS".to_string() + if let Ok(vers) = SoftwareVersion::load() { + format!( + "{} {} ({})", + vers.product_name, vers.product_user_visible_version, vers.product_build_version + ) + } else { + "macOS".to_string() + } } fn terminate_message_loop(&self) {