feat: create system module with SystemInfo struct
Swadhin Biswas committed 7 months ago
a222cf0
1 parent 5e327e2
commit a222cf0
1 file changed
+50 -0
Showing 1 changed file+50-0
▼src/system/mod.rs
+50-0
| @@ -0,0 +1,50 @@ | ||
1 | +//! System information module for FetchX | |
2 | +//! | |
3 | +//! Gathers all system info fields, mirroring neofetch's detection logic. | |
4 | + | |
5 | +use crate::utils::{command_exists, env_or, read_file, read_first_line, run_cmd}; | |
6 | +use std::path::Path; | |
7 | + | |
8 | +/// All system information fields. | |
9 | +#[derive(Debug, Clone)] | |
10 | +pub struct SystemInfo { | |
11 | + pub username: String, | |
12 | + pub hostname: String, | |
13 | + pub os: String, | |
14 | + pub distro_id: String, | |
15 | + pub host: String, | |
16 | + pub kernel: String, | |
17 | + pub uptime: String, | |
18 | + pub packages: String, | |
19 | + pub shell: String, | |
20 | + pub resolution: String, | |
21 | + pub de: String, | |
22 | + pub wm: String, | |
23 | + pub wm_theme: String, | |
24 | + pub theme: String, | |
25 | + pub icons: String, | |
26 | + pub terminal: String, | |
27 | + pub term_font: String, | |
28 | + pub cpu: String, | |
29 | + pub gpu: Vec<String>, | |
30 | + pub memory: String, | |
31 | + pub memory_percent: f64, | |
32 | + pub disk: String, | |
33 | + pub disk_percent: f64, | |
34 | + pub battery: String, | |
35 | + pub local_ip: String, | |
36 | + pub public_ip: String, | |
37 | + pub locale: String, | |
38 | + pub song: String, | |
39 | + pub users: String, | |
40 | +} | |
41 | + | |
42 | +impl SystemInfo { | |
43 | + /// Collect all system information using parallel threads for speed. | |
44 | + pub fn collect() -> Self { | |
45 | + use std::thread; | |
46 | + | |
47 | + let distro_id = detect_distro_id(); | |
48 | + let did = distro_id.clone(); | |
49 | + | |
50 | + // Spawn threads for slow/independent operations | |
0 | 51 | |