diff options
author | 2024-12-03 01:35:41 +0100 | |
---|---|---|
committer | 2024-12-03 01:35:41 +0100 | |
commit | 9c9334108901951716c020d585ce3deef3127a89 (patch) | |
tree | 54201c58139c82327e793b256a726ffe891a42c1 | |
parent | 3b2a422d5d4bf0d21301338050637ce717cff5f7 (diff) | |
parent | 1e5c1ad2cb040157421a268df599b1ecbff7e678 (diff) | |
download | iced-9c9334108901951716c020d585ce3deef3127a89.tar.gz iced-9c9334108901951716c020d585ce3deef3127a89.tar.bz2 iced-9c9334108901951716c020d585ce3deef3127a89.zip |
Merge pull request #2681 from xosxos/patch-1
fix: add an initial state to the `system_information` example
-rw-r--r-- | examples/system_information/src/main.rs | 20 |
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> { |