mirror of https://github.com/wayvr-org/wayvr.git
dash-frontend: minor refactoring for Tasks
This commit is contained in:
parent
707e3a4927
commit
6b22e4aef1
|
|
@ -298,12 +298,8 @@ impl View {
|
|||
}
|
||||
|
||||
pub fn update<T>(&mut self, interface: &mut BoxDashInterface<T>, 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,
|
||||
|
|
|
|||
|
|
@ -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::<WidgetLabel>()?
|
||||
.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::<WidgetLabel>()?
|
||||
.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::<ComponentButton>("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::<ComponentButton>("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(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -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)?,
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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)?;
|
||||
|
|
|
|||
|
|
@ -22,6 +22,10 @@ impl<TaskType: 'static> Tasks<TaskType> {
|
|||
self.0.borrow().len()
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.0.borrow().is_empty()
|
||||
}
|
||||
|
||||
pub fn drain(&mut self) -> VecDeque<TaskType> {
|
||||
let mut tasks = self.0.borrow_mut();
|
||||
std::mem::take(&mut *tasks)
|
||||
|
|
|
|||
Loading…
Reference in New Issue