begin multi-driver page client implementation

This commit is contained in:
yggverse 2025-01-21 15:04:31 +02:00
parent df8dea9534
commit 0c08a0fb2f
39 changed files with 741 additions and 1712 deletions

View file

@ -29,8 +29,8 @@ impl Request {
// Actions
pub fn update(&self, progress_fraction: Option<f64>, is_identity_active: bool) {
self.widget.update(progress_fraction, is_identity_active);
pub fn update(&self, is_identity_active: bool) {
self.widget.update(is_identity_active);
}
pub fn clean(
@ -94,19 +94,19 @@ impl Request {
// Setters
pub fn to_download(&self) {
pub fn into_download(&self) {
self.widget.entry.set_text(&self.download());
}
pub fn to_source(&self) {
pub fn into_source(&self) {
self.widget.entry.set_text(&self.source());
}
// Getters
/// Get current request value in [Uri](https://docs.gtk.org/glib/struct.Uri.html) format
/// Try get current request value as [Uri](https://docs.gtk.org/glib/struct.Uri.html)
/// * `strip_prefix` on parse
pub fn uri(&self) -> Option<Uri> {
pub fn as_uri(&self) -> Option<Uri> {
match Uri::parse(&strip_prefix(self.widget.entry.text()), UriFlags::NONE) {
Ok(uri) => Some(uri),
_ => None,

View file

@ -188,7 +188,7 @@ impl Widget {
Ok(())
}
pub fn update(&self, progress_fraction: Option<f64>, is_identity_active: bool) {
pub fn update(&self, is_identity_active: bool) {
// Update primary icon
self.entry
.first_child()
@ -229,46 +229,46 @@ impl Widget {
}
// Update progress
// * skip update animation for None value
if let Some(value) = progress_fraction {
// Update shared fraction on new value was changed
if value != self.progress.fraction.replace(value) {
// Start new frame on previous process function completed (`source_id` changed to 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 entry = self.entry.clone();
let progress = self.progress.clone();
// * @TODO skip update animation for None value
let value = self.entry.progress_fraction();
// Frame
move || {
// Animate
if *progress.fraction.borrow() > entry.progress_fraction() {
entry.set_progress_fraction(
// Currently, here is no outrange validation, seems that wrapper make this work @TODO
entry.progress_fraction() + PROGRESS_ANIMATION_STEP,
);
return ControlFlow::Continue;
}
// Deactivate
progress.source_id.replace(None);
// Update shared fraction on new value was changed
if value != self.progress.fraction.replace(value) {
// Start new frame on previous process function completed (`source_id` changed to 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 entry = self.entry.clone();
let progress = self.progress.clone();
// Reset on 100% (to hide progress bar)
// or, just await for new value request
if entry.progress_fraction() == 1.0 {
entry.set_progress_fraction(0.0);
}
// Stop iteration
ControlFlow::Break
// Frame
move || {
// Animate
if *progress.fraction.borrow() > entry.progress_fraction() {
entry.set_progress_fraction(
// Currently, here is no outrange validation, seems that wrapper make this work @TODO
entry.progress_fraction() + PROGRESS_ANIMATION_STEP,
);
return ControlFlow::Continue;
}
},
)));
}
// Deactivate
progress.source_id.replace(None);
// Reset on 100% (to hide progress bar)
// or, just await for new value request
if entry.progress_fraction() == 1.0 {
entry.set_progress_fraction(0.0);
}
// Stop iteration
ControlFlow::Break
}
},
)));
}
}
}