Run system::information in a different thread
... since it seems it can block for a couple of seconds.
This commit is contained in:
parent
e24f26c28f
commit
f1ec0af507
3 changed files with 17 additions and 9 deletions
|
|
@ -1,15 +1,18 @@
|
||||||
use crate::system;
|
use crate::system;
|
||||||
|
|
||||||
use iced_futures::MaybeSend;
|
use iced_futures::MaybeSend;
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
/// An operation to be performed on the system.
|
/// An operation to be performed on the system.
|
||||||
pub enum Action<T> {
|
pub enum Action<T> {
|
||||||
/// Query system information and produce `T` with the result.
|
/// Query system information and produce `T` with the result.
|
||||||
QueryInformation(Box<dyn Fn(system::Information) -> T>),
|
QueryInformation(Box<dyn Closure<T>>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait Closure<T>: Fn(system::Information) -> T + MaybeSend {}
|
||||||
|
|
||||||
|
impl<T, O> Closure<O> for T where T: Fn(system::Information) -> O + MaybeSend {}
|
||||||
|
|
||||||
impl<T> Action<T> {
|
impl<T> Action<T> {
|
||||||
/// Maps the output of a system [`Action`] using the provided closure.
|
/// Maps the output of a system [`Action`] using the provided closure.
|
||||||
pub fn map<A>(
|
pub fn map<A>(
|
||||||
|
|
|
||||||
|
|
@ -583,14 +583,19 @@ pub fn run_command<Message: 'static + std::fmt::Debug + Send, E: Executor>(
|
||||||
system::Action::QueryInformation(_tag) => {
|
system::Action::QueryInformation(_tag) => {
|
||||||
#[cfg(feature = "system")]
|
#[cfg(feature = "system")]
|
||||||
{
|
{
|
||||||
let information =
|
let graphics_info = _graphics_info();
|
||||||
crate::system::information(_graphics_info());
|
let proxy = proxy.clone();
|
||||||
|
|
||||||
let message = _tag(information);
|
let _ = std::thread::spawn(move || {
|
||||||
|
let information =
|
||||||
|
crate::system::information(graphics_info);
|
||||||
|
|
||||||
proxy
|
let message = _tag(information);
|
||||||
.send_event(message)
|
|
||||||
.expect("Send message to event loop");
|
proxy
|
||||||
|
.send_event(message)
|
||||||
|
.expect("Send message to event loop")
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ use iced_graphics::compositor;
|
||||||
|
|
||||||
/// Query for available system information.
|
/// Query for available system information.
|
||||||
pub fn fetch_information<Message>(
|
pub fn fetch_information<Message>(
|
||||||
f: impl Fn(Information) -> Message + 'static,
|
f: impl Fn(Information) -> Message + Send + 'static,
|
||||||
) -> Command<Message> {
|
) -> Command<Message> {
|
||||||
Command::single(command::Action::System(Action::QueryInformation(
|
Command::single(command::Action::System(Action::QueryInformation(
|
||||||
Box::new(f),
|
Box::new(f),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue