mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-09-01 01:12:02 +00:00
init the loading widget on total size reached instead of use timeout
This commit is contained in:
parent
61e3230f66
commit
27a79a10f5
@ -12,7 +12,10 @@ use gtk::{
|
|||||||
glib::{Priority, Uri},
|
glib::{Priority, Uri},
|
||||||
};
|
};
|
||||||
use sourceview::prelude::FileExt;
|
use sourceview::prelude::FileExt;
|
||||||
use std::{cell::RefCell, rc::Rc};
|
use std::{
|
||||||
|
cell::{Cell, RefCell},
|
||||||
|
rc::Rc,
|
||||||
|
};
|
||||||
|
|
||||||
pub struct Nex {
|
pub struct Nex {
|
||||||
page: Rc<Page>,
|
page: Rc<Page>,
|
||||||
@ -144,6 +147,7 @@ impl Nex {
|
|||||||
// Show loading status page if awaiting time > 1 second
|
// Show loading status page if awaiting time > 1 second
|
||||||
// * the RefCell is just to not init the loading widget before timeout and prevent bg blinks
|
// * the RefCell is just to not init the loading widget before timeout and prevent bg blinks
|
||||||
let loading: RefCell<Option<adw::StatusPage>> = RefCell::new(None);
|
let loading: RefCell<Option<adw::StatusPage>> = RefCell::new(None);
|
||||||
|
let loading_total: Cell<usize> = Cell::new(0);
|
||||||
|
|
||||||
// Nex is the header-less protocol, final content size is never known,
|
// Nex is the header-less protocol, final content size is never known,
|
||||||
// borrow ggemini::gio wrapper api to preload the buffer swap-safely,
|
// borrow ggemini::gio wrapper api to preload the buffer swap-safely,
|
||||||
@ -161,15 +165,17 @@ impl Nex {
|
|||||||
{
|
{
|
||||||
let p = p.clone();
|
let p = p.clone();
|
||||||
move |_, t| {
|
move |_, t| {
|
||||||
let mut l = loading.borrow_mut();
|
if loading_total.replace(t) > 1024 {
|
||||||
match *l {
|
let mut l = loading.borrow_mut();
|
||||||
Some(ref this) => this.set_description(Some(
|
match *l {
|
||||||
&format!("Preload: {t} bytes"),
|
Some(ref this) => this.set_description(
|
||||||
)),
|
Some(&format!("Preload: {t} bytes")),
|
||||||
None => {
|
),
|
||||||
l.replace(p.content.to_status_loading(
|
None => {
|
||||||
Some(std::time::Duration::from_secs(1)),
|
l.replace(
|
||||||
));
|
p.content.to_status_loading(None),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user