summaryrefslogtreecommitdiffstats
path: root/winit/src/system.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2022-05-11 18:08:36 +0200
committerLibravatar GitHub <noreply@github.com>2022-05-11 18:08:36 +0200
commit2e7757a42819fba3757c5b88e77e184b09649910 (patch)
tree80b0a55ff3834647a6527d8856632e79d8352789 /winit/src/system.rs
parentd4ed8afa1ed15486144dc7afee52c09e044a92e0 (diff)
parentb440df9afbb2b63717e84d209a0995ada0e72e6d (diff)
downloadiced-2e7757a42819fba3757c5b88e77e184b09649910.tar.gz
iced-2e7757a42819fba3757c5b88e77e184b09649910.tar.bz2
iced-2e7757a42819fba3757c5b88e77e184b09649910.zip
Merge pull request #1314 from derezzedex/dev/system-information
feat: fetch system information
Diffstat (limited to '')
-rw-r--r--winit/src/system.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/winit/src/system.rs b/winit/src/system.rs
new file mode 100644
index 00000000..0ed61dc9
--- /dev/null
+++ b/winit/src/system.rs
@@ -0,0 +1,41 @@
+//! Access the native system.
+use crate::command::{self, Command};
+pub use iced_native::system::*;
+
+use iced_graphics::compositor;
+
+/// Query for available system information.
+pub fn fetch_information<Message>(
+ f: impl Fn(Information) -> Message + Send + 'static,
+) -> Command<Message> {
+ Command::single(command::Action::System(Action::QueryInformation(
+ Box::new(f),
+ )))
+}
+
+pub(crate) fn information(
+ graphics_info: compositor::Information,
+) -> Information {
+ use sysinfo::{ProcessExt, ProcessorExt, System, SystemExt};
+ let mut system = System::new_all();
+ system.refresh_all();
+
+ let cpu = system.global_processor_info();
+
+ let memory_used = sysinfo::get_current_pid()
+ .and_then(|pid| system.process(pid).ok_or("Process not found"))
+ .and_then(|process| Ok(process.memory()))
+ .ok();
+
+ Information {
+ system_name: system.name(),
+ system_kernel: system.kernel_version(),
+ system_version: system.long_os_version(),
+ 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,
+ }
+}