iced-yoda/winit/src/system.rs

42 lines
1.3 KiB
Rust
Raw Normal View History

//! Access the native system.
use crate::graphics::compositor;
2023-03-05 06:35:20 +01:00
use crate::runtime::command::{self, Command};
use crate::runtime::system::{Action, Information};
2022-04-14 11:15:54 -03:00
/// Query for available system information.
pub fn fetch_information<Message>(
f: impl Fn(Information) -> Message + Send + 'static,
) -> Command<Message> {
2022-03-10 03:01:12 -03:00
Command::single(command::Action::System(Action::QueryInformation(
Box::new(f),
)))
}
2022-04-14 11:15:54 -03:00
2022-04-27 16:18:27 -03:00
pub(crate) fn information(
graphics_info: compositor::Information,
2022-04-27 16:18:27 -03:00
) -> Information {
2023-03-07 07:22:48 +01:00
use sysinfo::{CpuExt, ProcessExt, System, SystemExt};
2022-04-14 11:15:54 -03:00
let mut system = System::new_all();
system.refresh_all();
2023-03-07 07:22:48 +01:00
let cpu = system.global_cpu_info();
2022-04-14 11:15:54 -03:00
let memory_used = sysinfo::get_current_pid()
.and_then(|pid| system.process(pid).ok_or("Process not found"))
2022-07-04 01:17:29 +02:00
.map(|process| process.memory())
2022-04-14 11:15:54 -03:00
.ok();
2022-04-27 16:18:27 -03:00
Information {
2022-04-14 11:15:54 -03:00
system_name: system.name(),
system_kernel: system.kernel_version(),
system_version: system.long_os_version(),
system_short_version: system.os_version(),
2022-04-14 11:15:54 -03:00
cpu_brand: cpu.brand().into(),
cpu_cores: system.physical_core_count(),
memory_total: system.total_memory(),
memory_used,
graphics_adapter: graphics_info.adapter,
graphics_backend: graphics_info.backend,
2022-04-27 16:18:27 -03:00
}
2022-04-14 11:15:54 -03:00
}