diff options
author | 2022-03-08 19:49:03 -0300 | |
---|---|---|
committer | 2022-04-26 18:54:27 -0300 | |
commit | 6295a72aa66381af9567b0b25e22d960ac672998 (patch) | |
tree | 756bf259b4f7ae1792852e2d3d9c435fd30fd0fd /winit/src/application.rs | |
parent | 69781499cb070535bfc4e968d9ed3102ea722fb3 (diff) | |
download | iced-6295a72aa66381af9567b0b25e22d960ac672998.tar.gz iced-6295a72aa66381af9567b0b25e22d960ac672998.tar.bz2 iced-6295a72aa66381af9567b0b25e22d960ac672998.zip |
Implement `QueryInformation` for `iced_winit`
Diffstat (limited to 'winit/src/application.rs')
-rw-r--r-- | winit/src/application.rs | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/winit/src/application.rs b/winit/src/application.rs index 33f53315..d184c0c3 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -540,6 +540,7 @@ pub fn run_command<Message: 'static + std::fmt::Debug + Send, E: Executor>( window: &winit::window::Window, ) { use iced_native::command; + use iced_native::system; use iced_native::window; for action in command.actions() { @@ -573,7 +574,49 @@ pub fn run_command<Message: 'static + std::fmt::Debug + Send, E: Executor>( }); } }, - command::Action::System(_action) => {} + command::Action::System(action) => match action { + system::Action::QueryInformation(tag) => { + #[cfg(feature = "sysinfo")] + let information = { + use sysinfo::{ProcessorExt, System, SystemExt}; + let mut system = System::new_all(); + system.refresh_all(); + + let cpu = system.global_processor_info(); + let unknown = String::from("unknown"); + + let information = system::Information { + system_name: system + .name() + .unwrap_or(unknown.clone()), + system_kernel: system + .kernel_version() + .unwrap_or(unknown.clone()), + system_version: system + .long_os_version() + .unwrap_or(unknown.clone()), + cpu_brand: cpu.brand().into(), + cpu_vendor: cpu.vendor_id().into(), + cpu_name: cpu.name().into(), + cpu_cores: system + .physical_core_count() + .map_or(unknown, |cores| cores.to_string()), + memory_total: system.total_memory().to_string(), + }; + + Some(information) + }; + + #[cfg(not(feature = "sysinfo"))] + let information = None; + + let message = tag(information); + + proxy + .send_event(message) + .expect("Send message to event loop"); + } + }, } } } |