summaryrefslogtreecommitdiffstats
path: root/winit
diff options
context:
space:
mode:
authorLibravatar Richard <richardsoncusto@gmail.com>2022-04-14 11:15:54 -0300
committerLibravatar Richard <richardsoncusto@gmail.com>2022-04-26 18:59:47 -0300
commit053f352f68863e31a4576b8462a54b4e65f629d9 (patch)
tree2439e3d8ebc1104d8e9f145aadee17399d987147 /winit
parentc9ea1f11dec96df04ade463ea9f33062a85c9219 (diff)
downloadiced-053f352f68863e31a4576b8462a54b4e65f629d9.tar.gz
iced-053f352f68863e31a4576b8462a54b4e65f629d9.tar.bz2
iced-053f352f68863e31a4576b8462a54b4e65f629d9.zip
Introduce `get_information`
Diffstat (limited to 'winit')
-rw-r--r--winit/src/application.rs36
-rw-r--r--winit/src/system.rs39
2 files changed, 41 insertions, 34 deletions
diff --git a/winit/src/application.rs b/winit/src/application.rs
index 1865f344..37a0d584 100644
--- a/winit/src/application.rs
+++ b/winit/src/application.rs
@@ -582,40 +582,8 @@ pub fn run_command<Message: 'static + std::fmt::Debug + Send, E: Executor>(
},
command::Action::System(action) => match action {
system::Action::QueryInformation(tag) => {
- #[cfg(feature = "sysinfo")]
- let 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();
-
- let information = system::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.clone(),
- graphics_backend: graphics_info.backend.clone(),
- };
-
- Some(information)
- };
-
- #[cfg(not(feature = "sysinfo"))]
- let information = None;
+ let information =
+ crate::system::get_information(graphics_info);
let message = tag(information);
diff --git a/winit/src/system.rs b/winit/src/system.rs
index 3d1b4022..7e1c17c8 100644
--- a/winit/src/system.rs
+++ b/winit/src/system.rs
@@ -2,6 +2,8 @@
use crate::command::{self, Command};
pub use iced_native::system::*;
+use iced_graphics::window;
+
/// Query for available system information.
///
/// Returns `None` if not using the `sysinfo` feature flag.
@@ -12,3 +14,40 @@ pub fn information<Message>(
Box::new(f),
)))
}
+
+#[cfg(feature = "sysinfo")]
+pub(crate) fn get_information(
+ graphics_info: &window::GraphicsInformation,
+) -> Option<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();
+
+ let information = 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.clone(),
+ graphics_backend: graphics_info.backend.clone(),
+ };
+
+ Some(information)
+}
+
+#[cfg(not(feature = "sysinfo"))]
+pub(crate) fn get_information(
+ _graphics_info: &window::GraphicsInformation,
+) -> Option<Information> {
+ None
+}