diff --git a/src/app/browser/window/tab/item/page.rs b/src/app/browser/window/tab/item/page.rs index 7aaf79a1..25962345 100644 --- a/src/app/browser/window/tab/item/page.rs +++ b/src/app/browser/window/tab/item/page.rs @@ -29,7 +29,7 @@ use gtk::{ Box, }; use sqlite::Transaction; -use std::{cell::RefCell, sync::Arc}; +use std::{cell::RefCell, sync::Arc, time::Duration}; pub struct Page { id: GString, @@ -548,7 +548,8 @@ impl Page { // Final image size unknown, show loading widget let status = content.set_status_loading( Some(&"Loading.."), - None + None, + Some(Duration::from_secs(1)) // show if download time > 1 second ); // Asynchronously move `InputStream` data from `SocketConnection` into the local `MemoryInputStream` diff --git a/src/app/browser/window/tab/item/page/content.rs b/src/app/browser/window/tab/item/page/content.rs index 3453b036..566fba85 100644 --- a/src/app/browser/window/tab/item/page/content.rs +++ b/src/app/browser/window/tab/item/page/content.rs @@ -13,6 +13,8 @@ use gtk::{ prelude::{BoxExt, WidgetExt}, Box, Orientation, }; +use std::time::Duration; + pub struct Content { // GTK gobject: Box, @@ -46,9 +48,14 @@ impl Content { } /// Loading placeholder - pub fn set_status_loading(&self, title: Option<&str>, description: Option<&str>) -> Status { + pub fn set_status_loading( + &self, + title: Option<&str>, + description: Option<&str>, + show_with_delay: Option, + ) -> Status { self.clean(); - let status = Status::new_loading(title, description); + let status = Status::new_loading(title, description, show_with_delay); self.gobject.append(status.gobject()); status } diff --git a/src/app/browser/window/tab/item/page/content/status.rs b/src/app/browser/window/tab/item/page/content/status.rs index b68472f2..218177b1 100644 --- a/src/app/browser/window/tab/item/page/content/status.rs +++ b/src/app/browser/window/tab/item/page/content/status.rs @@ -5,6 +5,7 @@ use failure::Failure; use loading::Loading; use adw::StatusPage; +use std::time::Duration; pub struct Status { gobject: StatusPage, @@ -25,9 +26,15 @@ impl Status { /// Create new loading preset /// /// Useful as placeholder widget for async operations - pub fn new_loading(title: Option<&str>, description: Option<&str>) -> Self { + pub fn new_loading( + title: Option<&str>, + description: Option<&str>, + show_with_delay: Option, + ) -> Self { Self { - gobject: Loading::new(title, description).gobject().clone(), + gobject: Loading::new(title, description, show_with_delay) + .gobject() + .clone(), } } diff --git a/src/app/browser/window/tab/item/page/content/status/loading.rs b/src/app/browser/window/tab/item/page/content/status/loading.rs index 5cdcfc9e..50968fba 100644 --- a/src/app/browser/window/tab/item/page/content/status/loading.rs +++ b/src/app/browser/window/tab/item/page/content/status/loading.rs @@ -2,15 +2,20 @@ mod widget; use widget::Widget; use adw::StatusPage; +use std::time::Duration; pub struct Loading { widget: Widget, } impl Loading { - pub fn new(title: Option<&str>, description: Option<&str>) -> Self { + pub fn new( + title: Option<&str>, + description: Option<&str>, + show_with_delay: Option, + ) -> Self { Self { - widget: Widget::new(title, description), + widget: Widget::new(title, description, show_with_delay), } } diff --git a/src/app/browser/window/tab/item/page/content/status/loading/widget.rs b/src/app/browser/window/tab/item/page/content/status/loading/widget.rs index 1470b27d..8ea2c879 100644 --- a/src/app/browser/window/tab/item/page/content/status/loading/widget.rs +++ b/src/app/browser/window/tab/item/page/content/status/loading/widget.rs @@ -1,4 +1,9 @@ use adw::{Spinner, StatusPage}; +use gtk::{ + glib::{timeout_add_local, ControlFlow}, + prelude::WidgetExt, +}; +use std::time::Duration; /// 16-64 (px) const SPINNER_SIZE: i32 = 64; @@ -11,7 +16,13 @@ impl Widget { // Constructors /// Create new default widget configuration with options - pub fn new(title: Option<&str>, description: Option<&str>) -> Self { + /// + /// * use `show_with_delay` option on loading not take a while + pub fn new( + title: Option<&str>, + description: Option<&str>, + show_with_delay: Option, + ) -> Self { let gobject = StatusPage::builder() .child( &Spinner::builder() @@ -27,6 +38,17 @@ impl Widget { gobject.set_description(description); + if let Some(duration) = show_with_delay { + gobject.set_visible(false); + timeout_add_local(duration, { + let this = gobject.clone(); + move || { + this.set_visible(true); + ControlFlow::Break + } + }); + } + Self { gobject } }