From 0b36a55196300371343a1614cec61ac041f160f4 Mon Sep 17 00:00:00 2001 From: Richard Date: Thu, 10 Mar 2022 01:56:25 -0300 Subject: Add function helper in `iced_winit::system` --- winit/src/system.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 winit/src/system.rs (limited to 'winit/src/system.rs') diff --git a/winit/src/system.rs b/winit/src/system.rs new file mode 100644 index 00000000..cd3ba075 --- /dev/null +++ b/winit/src/system.rs @@ -0,0 +1,14 @@ +//! Access the native system. +use crate::command::{self, Command}; +use iced_native::system; + +/// Query for available system information. +/// +/// Returns `None` if not using the `sysinfo` feature flag. +pub fn information( + f: impl Fn(Option) -> Message + 'static, +) -> Command { + Command::single(command::Action::System(system::Action::QueryInformation( + Box::new(f), + ))) +} -- cgit From c8ed318e17c8a7673e4260e5d4e12c44c9faa987 Mon Sep 17 00:00:00 2001 From: Richard Date: Thu, 10 Mar 2022 03:01:12 -0300 Subject: Export new `system` module --- winit/src/system.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'winit/src/system.rs') diff --git a/winit/src/system.rs b/winit/src/system.rs index cd3ba075..3d1b4022 100644 --- a/winit/src/system.rs +++ b/winit/src/system.rs @@ -1,14 +1,14 @@ //! Access the native system. use crate::command::{self, Command}; -use iced_native::system; +pub use iced_native::system::*; /// Query for available system information. /// /// Returns `None` if not using the `sysinfo` feature flag. pub fn information( - f: impl Fn(Option) -> Message + 'static, + f: impl Fn(Option) -> Message + 'static, ) -> Command { - Command::single(command::Action::System(system::Action::QueryInformation( + Command::single(command::Action::System(Action::QueryInformation( Box::new(f), ))) } -- cgit From 053f352f68863e31a4576b8462a54b4e65f629d9 Mon Sep 17 00:00:00 2001 From: Richard Date: Thu, 14 Apr 2022 11:15:54 -0300 Subject: Introduce `get_information` --- winit/src/system.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'winit/src/system.rs') 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( Box::new(f), ))) } + +#[cfg(feature = "sysinfo")] +pub(crate) fn get_information( + graphics_info: &window::GraphicsInformation, +) -> Option { + 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 { + None +} -- cgit From 5be1ac18fe1757d31386f98774d823bd1137eea4 Mon Sep 17 00:00:00 2001 From: Richard Date: Tue, 26 Apr 2022 19:09:09 -0300 Subject: Rename `GraphicsInformation` to `Information` --- winit/src/system.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'winit/src/system.rs') diff --git a/winit/src/system.rs b/winit/src/system.rs index 7e1c17c8..1305ba5b 100644 --- a/winit/src/system.rs +++ b/winit/src/system.rs @@ -17,7 +17,7 @@ pub fn information( #[cfg(feature = "sysinfo")] pub(crate) fn get_information( - graphics_info: &window::GraphicsInformation, + graphics_info: &window::Information, ) -> Option { use sysinfo::{ProcessExt, ProcessorExt, System, SystemExt}; let mut system = System::new_all(); @@ -47,7 +47,7 @@ pub(crate) fn get_information( #[cfg(not(feature = "sysinfo"))] pub(crate) fn get_information( - _graphics_info: &window::GraphicsInformation, + _graphics_info: &window::Information, ) -> Option { None } -- cgit From 984d1f375ecec301dd42b049eecd1b88e3bca32a Mon Sep 17 00:00:00 2001 From: Richard Date: Tue, 26 Apr 2022 19:18:18 -0300 Subject: Move `compositor` module access from `window` to `crate` --- winit/src/system.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'winit/src/system.rs') diff --git a/winit/src/system.rs b/winit/src/system.rs index 1305ba5b..a961c5b4 100644 --- a/winit/src/system.rs +++ b/winit/src/system.rs @@ -2,7 +2,7 @@ use crate::command::{self, Command}; pub use iced_native::system::*; -use iced_graphics::window; +use iced_graphics::compositor; /// Query for available system information. /// @@ -17,7 +17,7 @@ pub fn information( #[cfg(feature = "sysinfo")] pub(crate) fn get_information( - graphics_info: &window::Information, + graphics_info: &compositor::Information, ) -> Option { use sysinfo::{ProcessExt, ProcessorExt, System, SystemExt}; let mut system = System::new_all(); @@ -47,7 +47,7 @@ pub(crate) fn get_information( #[cfg(not(feature = "sysinfo"))] pub(crate) fn get_information( - _graphics_info: &window::Information, + _graphics_info: &compositor::Information, ) -> Option { None } -- cgit From 8643fbef90fc16371e27ae0142eb7e4c6b432d29 Mon Sep 17 00:00:00 2001 From: Richard Date: Tue, 26 Apr 2022 19:35:43 -0300 Subject: Rename `system::information` to `fetch_information` --- winit/src/system.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'winit/src/system.rs') diff --git a/winit/src/system.rs b/winit/src/system.rs index a961c5b4..f5f68593 100644 --- a/winit/src/system.rs +++ b/winit/src/system.rs @@ -7,7 +7,7 @@ use iced_graphics::compositor; /// Query for available system information. /// /// Returns `None` if not using the `sysinfo` feature flag. -pub fn information( +pub fn fetch_information( f: impl Fn(Option) -> Message + 'static, ) -> Command { Command::single(command::Action::System(Action::QueryInformation( -- cgit From 6e167675d6a51a8a78d93439719ebffe35dcfdef Mon Sep 17 00:00:00 2001 From: Richard Date: Wed, 27 Apr 2022 15:40:29 -0300 Subject: Use closure internally to fetch `graphics_info` --- winit/src/system.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'winit/src/system.rs') diff --git a/winit/src/system.rs b/winit/src/system.rs index f5f68593..beda2bdd 100644 --- a/winit/src/system.rs +++ b/winit/src/system.rs @@ -17,7 +17,7 @@ pub fn fetch_information( #[cfg(feature = "sysinfo")] pub(crate) fn get_information( - graphics_info: &compositor::Information, + graphics_info: compositor::Information, ) -> Option { use sysinfo::{ProcessExt, ProcessorExt, System, SystemExt}; let mut system = System::new_all(); @@ -38,8 +38,8 @@ pub(crate) fn get_information( 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(), + graphics_adapter: graphics_info.adapter, + graphics_backend: graphics_info.backend, }; Some(information) @@ -47,7 +47,7 @@ pub(crate) fn get_information( #[cfg(not(feature = "sysinfo"))] pub(crate) fn get_information( - _graphics_info: &compositor::Information, + _graphics_info: compositor::Information, ) -> Option { None } -- cgit From 5eefa5d4ead9ebfac7dab1db9aebf9797d2dad38 Mon Sep 17 00:00:00 2001 From: Richard Date: Wed, 27 Apr 2022 16:18:27 -0300 Subject: Simplify the `QueryInformation` Action --- winit/src/system.rs | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) (limited to 'winit/src/system.rs') diff --git a/winit/src/system.rs b/winit/src/system.rs index beda2bdd..fa4ad1a3 100644 --- a/winit/src/system.rs +++ b/winit/src/system.rs @@ -5,20 +5,17 @@ pub use iced_native::system::*; use iced_graphics::compositor; /// Query for available system information. -/// -/// Returns `None` if not using the `sysinfo` feature flag. pub fn fetch_information( - f: impl Fn(Option) -> Message + 'static, + f: impl Fn(Information) -> Message + 'static, ) -> Command { Command::single(command::Action::System(Action::QueryInformation( Box::new(f), ))) } -#[cfg(feature = "sysinfo")] -pub(crate) fn get_information( +pub(crate) fn information( graphics_info: compositor::Information, -) -> Option { +) -> Information { use sysinfo::{ProcessExt, ProcessorExt, System, SystemExt}; let mut system = System::new_all(); system.refresh_all(); @@ -30,7 +27,7 @@ pub(crate) fn get_information( .and_then(|process| Ok(process.memory())) .ok(); - let information = Information { + Information { system_name: system.name(), system_kernel: system.kernel_version(), system_version: system.long_os_version(), @@ -40,14 +37,5 @@ pub(crate) fn get_information( memory_used, graphics_adapter: graphics_info.adapter, graphics_backend: graphics_info.backend, - }; - - Some(information) -} - -#[cfg(not(feature = "sysinfo"))] -pub(crate) fn get_information( - _graphics_info: compositor::Information, -) -> Option { - None + } } -- cgit From f1ec0af5070fe2752967cdc38ed66b8b70882366 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 4 May 2022 14:25:04 +0200 Subject: Run `system::information` in a different thread ... since it seems it can block for a couple of seconds. --- winit/src/system.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'winit/src/system.rs') diff --git a/winit/src/system.rs b/winit/src/system.rs index fa4ad1a3..0ed61dc9 100644 --- a/winit/src/system.rs +++ b/winit/src/system.rs @@ -6,7 +6,7 @@ use iced_graphics::compositor; /// Query for available system information. pub fn fetch_information( - f: impl Fn(Information) -> Message + 'static, + f: impl Fn(Information) -> Message + Send + 'static, ) -> Command { Command::single(command::Action::System(Action::QueryInformation( Box::new(f), -- cgit