summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/system_information/src/main.rs20
1 files changed, 14 insertions, 6 deletions
diff --git a/examples/system_information/src/main.rs b/examples/system_information/src/main.rs
index 363df590..afa657d8 100644
--- a/examples/system_information/src/main.rs
+++ b/examples/system_information/src/main.rs
@@ -7,7 +7,7 @@ pub fn main() -> iced::Result {
Example::update,
Example::view,
)
- .run()
+ .run_with(Example::new)
}
#[derive(Default)]
@@ -28,20 +28,28 @@ enum Message {
}
impl Example {
+ fn new() -> (Self, Task<Message>) {
+ (
+ Self::Loading,
+ system::fetch_information().map(Message::InformationReceived),
+ )
+ }
+
fn update(&mut self, message: Message) -> Task<Message> {
match message {
Message::Refresh => {
- *self = Self::Loading;
+ let (state, refresh) = Self::new();
+
+ *self = state;
- return system::fetch_information()
- .map(Message::InformationReceived);
+ refresh
}
Message::InformationReceived(information) => {
*self = Self::Loaded { information };
+
+ Task::none()
}
}
-
- Task::none()
}
fn view(&self) -> Element<Message> {