Skip to content

Commit

Permalink
Merge pull request #2681 from xosxos/patch-1
Browse files Browse the repository at this point in the history
fix: add an initial state to the `system_information` example
  • Loading branch information
hecrj authored Dec 3, 2024
2 parents 3b2a422 + 1e5c1ad commit 9c93341
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions examples/system_information/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub fn main() -> iced::Result {
Example::update,
Example::view,
)
.run()
.run_with(Example::new)
}

#[derive(Default)]
Expand All @@ -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> {
Expand Down

0 comments on commit 9c93341

Please sign in to comment.