From 6b22e4aef143c80984b771b7ba39697bdccdc507 Mon Sep 17 00:00:00 2001 From: Aleksander Date: Wed, 29 Jul 2026 22:00:10 +0200 Subject: [PATCH] dash-frontend: minor refactoring for Tasks --- dash-frontend/src/views/app_launcher.rs | 8 +- dash-frontend/src/views/download_file.rs | 105 +++++++++--------- dash-frontend/src/views/game_launcher.rs | 8 +- dash-frontend/src/views/game_list.rs | 8 +- dash-frontend/src/views/running_games_list.rs | 9 +- dash-frontend/src/views/skymap_list.rs | 8 +- wgui/src/task.rs | 4 + 7 files changed, 68 insertions(+), 82 deletions(-) diff --git a/dash-frontend/src/views/app_launcher.rs b/dash-frontend/src/views/app_launcher.rs index 63d66181..bb429663 100644 --- a/dash-frontend/src/views/app_launcher.rs +++ b/dash-frontend/src/views/app_launcher.rs @@ -298,12 +298,8 @@ impl View { } pub fn update(&mut self, interface: &mut BoxDashInterface, data: &mut T) -> anyhow::Result<()> { - loop { - let tasks = self.tasks.drain(); - if tasks.is_empty() { - break; - } - for task in tasks { + while !self.tasks.is_empty() { + for task in self.tasks.drain() { match task { Task::SetCompositor(mode) => self.compositor_mode = mode, Task::SetRes(mode) => self.res_mode = mode, diff --git a/dash-frontend/src/views/download_file.rs b/dash-frontend/src/views/download_file.rs index 498a126e..66c7d37e 100644 --- a/dash-frontend/src/views/download_file.rs +++ b/dash-frontend/src/views/download_file.rs @@ -66,63 +66,66 @@ fn doc_params(globals: &WguiGlobals) -> ParseDocumentParams<'_> { impl ViewTrait for View { fn update(&mut self, par: &mut ViewUpdateParams) -> anyhow::Result<()> { - for task in self.tasks.drain() { - match task { - Task::StartDownload(url, path) => { - if let Some(on_downloaded) = self.on_downloaded.take() { - self.task_downloader = Some(self.executor.spawn(View::download( - self.tasks.clone(), - url, - path, - on_downloaded, - ))); + while !self.tasks.is_empty() { + for task in self.tasks.drain() { + match task { + Task::StartDownload(url, path) => { + if let Some(on_downloaded) = self.on_downloaded.take() { + self.task_downloader = Some(self.executor.spawn(View::download( + self.tasks.clone(), + url, + path, + on_downloaded, + ))); + } } - } - Task::SetStatusText(text) => { - let widgets = &mut par.layout.state.widgets; - widgets - .fetch(self.id_label_status)? - .cast::()? - .set_text(&mut par.layout.common(), Translation::from_raw_text_string(text)); - } - Task::ShowIconSuccess => { - par.layout.remove_children(self.id_loading_parent); - wgui_simple::create_icon( - par.layout, - self.id_loading_parent, - Vec2::splat(32.0), - AssetPath::BuiltIn("dashboard/check.svg"), - )?; - - // "Close window" button - self - .parser_state - .realize_template( - &doc_params(&self.globals), - "btn_close", + Task::SetStatusText(text) => { + let widgets = &mut par.layout.state.widgets; + widgets + .fetch(self.id_label_status)? + .cast::()? + .set_text(&mut par.layout.common(), Translation::from_raw_text_string(text)); + } + Task::ShowIconSuccess => { + par.layout.remove_children(self.id_loading_parent); + wgui_simple::create_icon( par.layout, - self.id_content, - Default::default(), - )? - .fetch_component_as::("btn")? - .on_click(self.tasks.get_button_click_callback(Task::Close)); - } - Task::ShowIconError => { - par.layout.remove_children(self.id_loading_parent); - wgui_simple::create_icon( - par.layout, - self.id_loading_parent, - Vec2::splat(32.0), - AssetPath::BuiltIn("dashboard/error.svg"), - )?; - } - Task::Close => { - if let Some(on_close) = self.on_close_request.take() { - on_close(); + self.id_loading_parent, + Vec2::splat(32.0), + AssetPath::BuiltIn("dashboard/check.svg"), + )?; + + // "Close window" button + self + .parser_state + .realize_template( + &doc_params(&self.globals), + "btn_close", + par.layout, + self.id_content, + Default::default(), + )? + .fetch_component_as::("btn")? + .on_click(self.tasks.get_button_click_callback(Task::Close)); + } + Task::ShowIconError => { + par.layout.remove_children(self.id_loading_parent); + wgui_simple::create_icon( + par.layout, + self.id_loading_parent, + Vec2::splat(32.0), + AssetPath::BuiltIn("dashboard/error.svg"), + )?; + } + Task::Close => { + if let Some(on_close) = self.on_close_request.take() { + on_close(); + } } } } } + Ok(()) } } diff --git a/dash-frontend/src/views/game_launcher.rs b/dash-frontend/src/views/game_launcher.rs index f10163e3..e763d0fb 100644 --- a/dash-frontend/src/views/game_launcher.rs +++ b/dash-frontend/src/views/game_launcher.rs @@ -52,12 +52,8 @@ pub struct View { impl ViewTrait for View { fn update(&mut self, par: &mut ViewUpdateParams) -> anyhow::Result<()> { - loop { - let tasks = self.tasks.drain(); - if tasks.is_empty() { - break; - } - for task in tasks { + while !self.tasks.is_empty() { + for task in self.tasks.drain() { match task { Task::FillAppDetails(details) => self.action_fill_app_details(par.layout, details)?, Task::Launch => self.action_launch(), diff --git a/dash-frontend/src/views/game_list.rs b/dash-frontend/src/views/game_list.rs index 1097f5f2..4736ba7a 100644 --- a/dash-frontend/src/views/game_list.rs +++ b/dash-frontend/src/views/game_list.rs @@ -70,12 +70,8 @@ pub struct View { impl ViewTrait for View { fn update(&mut self, par: &mut ViewUpdateParams) -> anyhow::Result<()> { - loop { - let tasks = self.tasks.drain(); - if tasks.is_empty() { - break; - } - for task in tasks { + while !self.tasks.is_empty() { + for task in self.tasks.drain() { match task { Task::LoadManifests => self.load_manifests(), Task::FillPage(page_idx) => self.fill_page(par.layout, par.executor, page_idx)?, diff --git a/dash-frontend/src/views/running_games_list.rs b/dash-frontend/src/views/running_games_list.rs index bc607b20..39941c1f 100644 --- a/dash-frontend/src/views/running_games_list.rs +++ b/dash-frontend/src/views/running_games_list.rs @@ -77,13 +77,8 @@ impl View { } pub fn update(&mut self, layout: &mut Layout, time_ms: u32) -> anyhow::Result<()> { - loop { - let tasks = self.tasks.drain(); - if tasks.is_empty() { - break; - } - - for task in tasks { + while !self.tasks.is_empty() { + for task in self.tasks.drain() { match task { Task::Refresh => self.refresh(layout)?, Task::StopGame(app_id, kill) => self.stop_game(app_id, kill), diff --git a/dash-frontend/src/views/skymap_list.rs b/dash-frontend/src/views/skymap_list.rs index e95f4ddd..ddd8a169 100644 --- a/dash-frontend/src/views/skymap_list.rs +++ b/dash-frontend/src/views/skymap_list.rs @@ -58,12 +58,8 @@ impl ViewTrait for View { self.popup_remote_skymap_list.update(par)?; self.popup_dialog_box.update(par)?; - loop { - let tasks = self.tasks.drain(); - if tasks.is_empty() { - break; - } - for task in tasks { + while !self.tasks.is_empty() { + for task in self.tasks.drain() { match task { Task::DownloadSkymaps => { self.download_skymaps(par.executor)?; diff --git a/wgui/src/task.rs b/wgui/src/task.rs index 8cd9f914..5ac26388 100644 --- a/wgui/src/task.rs +++ b/wgui/src/task.rs @@ -22,6 +22,10 @@ impl Tasks { self.0.borrow().len() } + pub fn is_empty(&self) -> bool { + self.0.borrow().is_empty() + } + pub fn drain(&mut self) -> VecDeque { let mut tasks = self.0.borrow_mut(); std::mem::take(&mut *tasks)