mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-03-10 20:51:45 +00:00
make progress fraction value update optional
This commit is contained in:
parent
a145ea4b6d
commit
46bf3c30ec
@ -399,11 +399,12 @@ impl Page {
|
||||
pub fn update(&self) {
|
||||
// Interpret status to progress fraction
|
||||
let progress_fraction = match self.meta.borrow().status {
|
||||
Some(Status::Prepare) => 0.25,
|
||||
Some(Status::Connect) => 0.50,
|
||||
Some(Status::Request) => 0.75,
|
||||
Some(Status::Response | Status::Success) => 1.0,
|
||||
_ => 0.0,
|
||||
Some(Status::Success) => Some(0.0),
|
||||
Some(Status::Prepare) => Some(0.25),
|
||||
Some(Status::Connect) => Some(0.50),
|
||||
Some(Status::Request) => Some(0.75),
|
||||
Some(Status::Response) => Some(1.0),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
// Update components
|
||||
|
@ -75,7 +75,7 @@ impl Navigation {
|
||||
}
|
||||
|
||||
// Actions
|
||||
pub fn update(&self, progress_fraction: f64) {
|
||||
pub fn update(&self, progress_fraction: Option<f64>) {
|
||||
self.base.update(self.request.uri());
|
||||
self.history.update();
|
||||
self.reload.update(!self.request.is_empty());
|
||||
|
@ -60,42 +60,45 @@ impl Request {
|
||||
}
|
||||
|
||||
// Actions
|
||||
pub fn update(&self, progress_fraction: f64) {
|
||||
// Update shared fraction value for async progressbar animation
|
||||
self.progress.fraction.replace(progress_fraction);
|
||||
pub fn update(&self, progress_fraction: Option<f64>) {
|
||||
// Skip Non value
|
||||
if let Some(value) = progress_fraction {
|
||||
// Update shared fraction value for async progressbar animation
|
||||
self.progress.fraction.replace(value);
|
||||
|
||||
// Start new frame on previous process completed only (`source_id` is None)
|
||||
// If previous process still active, we have just updated shared fraction value before, to use it inside the active process
|
||||
if self.progress.source_id.borrow().is_none() {
|
||||
// Start new animation frame iterator, update `source_id`
|
||||
self.progress.source_id.replace(Some(timeout_add_local(
|
||||
Duration::from_millis(PROGRESS_ANIMATION_TIME),
|
||||
{
|
||||
// Clone async pointers dependency
|
||||
let widget = self.widget.clone();
|
||||
let progress = self.progress.clone();
|
||||
// Start new frame on previous process completed only (`source_id` is None)
|
||||
// If previous process still active, we have just updated shared fraction value before, to use it inside the active process
|
||||
if self.progress.source_id.borrow().is_none() {
|
||||
// Start new animation frame iterator, update `source_id`
|
||||
self.progress.source_id.replace(Some(timeout_add_local(
|
||||
Duration::from_millis(PROGRESS_ANIMATION_TIME),
|
||||
{
|
||||
// Clone async pointers dependency
|
||||
let widget = self.widget.clone();
|
||||
let progress = self.progress.clone();
|
||||
|
||||
// Frame
|
||||
move || {
|
||||
// Animate
|
||||
if *progress.fraction.borrow() > widget.progress_fraction() {
|
||||
widget.set_progress_fraction(
|
||||
// Currently, here is no outrange validation, seems that wrapper make this work @TODO
|
||||
widget.progress_fraction() + PROGRESS_ANIMATION_STEP,
|
||||
);
|
||||
return ControlFlow::Continue;
|
||||
// Frame
|
||||
move || {
|
||||
// Animate
|
||||
if *progress.fraction.borrow() > widget.progress_fraction() {
|
||||
widget.set_progress_fraction(
|
||||
// Currently, here is no outrange validation, seems that wrapper make this work @TODO
|
||||
widget.progress_fraction() + PROGRESS_ANIMATION_STEP,
|
||||
);
|
||||
return ControlFlow::Continue;
|
||||
}
|
||||
// Deactivate
|
||||
progress.source_id.replace(None);
|
||||
|
||||
// Reset
|
||||
widget.set_progress_fraction(0.0);
|
||||
|
||||
// Stop iteration
|
||||
ControlFlow::Break
|
||||
}
|
||||
// Deactivate
|
||||
progress.source_id.replace(None);
|
||||
|
||||
// Reset
|
||||
widget.set_progress_fraction(0.0);
|
||||
|
||||
// Stop iteration
|
||||
ControlFlow::Break
|
||||
}
|
||||
},
|
||||
)));
|
||||
},
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user