system_specs.rs

 1use std::{env, fmt::Display};
 2
 3use gpui::AppContext;
 4use human_bytes::human_bytes;
 5use serde::Serialize;
 6use sysinfo::{System, SystemExt};
 7use util::channel::ReleaseChannel;
 8
 9#[derive(Debug, Serialize)]
10pub struct SystemSpecs {
11    app_version: &'static str,
12    release_channel: &'static str,
13    os_name: &'static str,
14    os_version: Option<String>,
15    memory: u64,
16    architecture: &'static str,
17}
18
19impl SystemSpecs {
20    pub fn new(cx: &AppContext) -> Self {
21        let platform = cx.platform();
22        let system = System::new_all();
23
24        SystemSpecs {
25            app_version: env!("CARGO_PKG_VERSION"),
26            release_channel: cx.global::<ReleaseChannel>().dev_name(),
27            os_name: platform.os_name(),
28            os_version: platform
29                .os_version()
30                .ok()
31                .map(|os_version| os_version.to_string()),
32            memory: system.total_memory(),
33            architecture: env::consts::ARCH,
34        }
35    }
36}
37
38impl Display for SystemSpecs {
39    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40        let os_information = match &self.os_version {
41            Some(os_version) => format!("OS: {} {}", self.os_name, os_version),
42            None => format!("OS: {}", self.os_name),
43        };
44        let system_specs = [
45            format!("Zed: v{} ({})", self.app_version, self.release_channel),
46            os_information,
47            format!("Memory: {}", human_bytes(self.memory as f64)),
48            format!("Architecture: {}", self.architecture),
49        ]
50        .join("\n");
51
52        write!(f, "{system_specs}")
53    }
54}