Simplify the QueryInformation Action
This commit is contained in:
parent
6e167675d6
commit
5eefa5d4ea
7 changed files with 15 additions and 35 deletions
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -582,7 +582,7 @@ pub fn run_command<Message: 'static + std::fmt::Debug + Send, E: Executor>(
|
|||
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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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<Message>(
|
||||
f: impl Fn(Option<Information>) -> Message + 'static,
|
||||
f: impl Fn(Information) -> Message + 'static,
|
||||
) -> Command<Message> {
|
||||
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> {
|
||||
) -> 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<Information> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue