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 --- Cargo.toml | 2 -- examples/system_information/Cargo.toml | 2 +- examples/system_information/src/main.rs | 18 ++++++------------ native/src/system/action.rs | 2 +- winit/Cargo.toml | 2 +- winit/src/application.rs | 2 +- winit/src/system.rs | 22 +++++----------------- 7 files changed, 15 insertions(+), 35 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 500fa06e..21bb6dd2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,8 +42,6 @@ smol = ["iced_futures/smol"] palette = ["iced_core/palette"] # Enables pure, virtual widgets in the `pure` module pure = ["iced_pure", "iced_graphics/pure"] -# Enables system information querying `Action` -sysinfo = ["iced_winit/sysinfo"] [badges] maintenance = { status = "actively-developed" } diff --git a/examples/system_information/Cargo.toml b/examples/system_information/Cargo.toml index d3d76182..13a59d5e 100644 --- a/examples/system_information/Cargo.toml +++ b/examples/system_information/Cargo.toml @@ -6,5 +6,5 @@ edition = "2021" publish = false [dependencies] -iced = { path = "../..", features = ["sysinfo"] } +iced = { path = "../.." } bytesize = { version = "1.1.0" } \ No newline at end of file diff --git a/examples/system_information/src/main.rs b/examples/system_information/src/main.rs index 1e61480f..704f5f4d 100644 --- a/examples/system_information/src/main.rs +++ b/examples/system_information/src/main.rs @@ -15,12 +15,11 @@ enum Example { information: system::Information, refresh_button: button::State, }, - Unsupported, } #[derive(Clone, Debug)] enum Message { - InformationReceived(Option), + InformationReceived(system::Information), Refresh, } @@ -46,15 +45,11 @@ impl Application for Example { return system::fetch_information(Message::InformationReceived); } Message::InformationReceived(information) => { - if let Some(information) = information { - let refresh_button = button::State::new(); - *self = Self::Loaded { - information, - refresh_button, - }; - } else { - *self = Self::Unsupported; - } + let refresh_button = button::State::new(); + *self = Self::Loaded { + information, + refresh_button, + }; } } @@ -156,7 +151,6 @@ impl Application for Example { .spacing(10) .into() } - Example::Unsupported => Text::new("Unsupported!").size(20).into(), }; Container::new(content) diff --git a/native/src/system/action.rs b/native/src/system/action.rs index 3bece0bb..6dab20a6 100644 --- a/native/src/system/action.rs +++ b/native/src/system/action.rs @@ -7,7 +7,7 @@ use std::fmt; /// An operation to be performed on the system. pub enum Action { /// Query system information and produce `T` with the result. - QueryInformation(Box) -> T>), + QueryInformation(Box T>), } impl Action { diff --git a/winit/Cargo.toml b/winit/Cargo.toml index b7583149..f5478e73 100644 --- a/winit/Cargo.toml +++ b/winit/Cargo.toml @@ -17,7 +17,7 @@ debug = ["iced_native/debug"] window_clipboard = "0.2" log = "0.4" thiserror = "1.0" -sysinfo = { version = "0.23", optional = true } +sysinfo = "0.23" [dependencies.winit] version = "0.26" diff --git a/winit/src/application.rs b/winit/src/application.rs index 9d881475..04dd55f1 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -582,7 +582,7 @@ pub fn run_command( command::Action::System(action) => match action { system::Action::QueryInformation(tag) => { let information = - crate::system::get_information(graphics_info()); + crate::system::information(graphics_info()); let message = tag(information); 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