iced_winit/
system.rs

1//! Access the native system.
2use crate::graphics::compositor;
3use crate::runtime::system::{Action, Information};
4use crate::runtime::{self, Task};
5
6/// Query for available system information.
7pub fn fetch_information() -> Task<Information> {
8    runtime::task::oneshot(|channel| {
9        runtime::Action::System(Action::QueryInformation(channel))
10    })
11}
12
13pub(crate) fn information(
14    graphics_info: compositor::Information,
15) -> Information {
16    use sysinfo::{Process, System};
17    let mut system = System::new_all();
18    system.refresh_all();
19
20    let cpu_brand = system
21        .cpus()
22        .first()
23        .map(|cpu| cpu.brand().to_string())
24        .unwrap_or_default();
25
26    let memory_used = sysinfo::get_current_pid()
27        .and_then(|pid| system.process(pid).ok_or("Process not found"))
28        .map(Process::memory)
29        .ok();
30
31    Information {
32        system_name: System::name(),
33        system_kernel: System::kernel_version(),
34        system_version: System::long_os_version(),
35        system_short_version: System::os_version(),
36        cpu_brand,
37        cpu_cores: system.physical_core_count(),
38        memory_total: system.total_memory(),
39        memory_used,
40        graphics_adapter: graphics_info.adapter,
41        graphics_backend: graphics_info.backend,
42    }
43}