Skip to content

Commit

Permalink
feat: show loading animation while verify timeout is not over
Browse files Browse the repository at this point in the history
* also reduce the verify timeout to 5s while at it
  • Loading branch information
hrzlgnm committed Nov 26, 2024
1 parent 7a82baa commit a9c0f54
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions shared_constants/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ pub const SPLASH_SCREEN_DURATION: Duration = Duration::from_secs(2);
pub const AUTO_COMPLETE_AUTO_FOCUS_DELAY: Duration = Duration::from_secs(5);
pub const SHOW_NO_UPDATE_DURATION: Duration = Duration::from_secs(3);
pub const GITHUB_BASE_URL: &str = "https://github.com/hrzlgnm/mdns-browser";
pub const VERIFY_TIMEOUT: Duration = Duration::from_secs(5);
6 changes: 3 additions & 3 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
use clap::builder::TypedValueParser as _;
#[cfg(desktop)]
use clap::Parser;
use mdns_sd::{ServiceDaemon, ServiceEvent, ServiceInfo, VERIFY_TIMEOUT_DEFAULT};
use mdns_sd::{ServiceDaemon, ServiceEvent, ServiceInfo};
use models::*;
#[cfg(all(desktop, not(debug_assertions)))]
use shared_constants::SPLASH_SCREEN_DURATION;
use shared_constants::{MDNS_SD_META_SERVICE, METRICS_CHECK_INTERVAL};
use shared_constants::{MDNS_SD_META_SERVICE, METRICS_CHECK_INTERVAL, VERIFY_TIMEOUT};
use std::{
collections::HashMap,
net::IpAddr,
Expand Down Expand Up @@ -106,7 +106,7 @@ fn stop_browse(service_type: String, state: State<ManagedState>) {
fn verify(instance_fullname: String, state: State<ManagedState>) {
log::debug!("verifying {}", instance_fullname);
if let Ok(mdns) = state.daemon.lock() {
mdns.verify(instance_fullname, VERIFY_TIMEOUT_DEFAULT)
mdns.verify(instance_fullname, VERIFY_TIMEOUT)
.expect("To verify an instance");
}
}
Expand Down
11 changes: 10 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use models::*;
use serde::{Deserialize, Serialize};
use shared_constants::{
AUTO_COMPLETE_AUTO_FOCUS_DELAY, GITHUB_BASE_URL, SHOW_NO_UPDATE_DURATION,
SPLASH_SCREEN_DURATION,
SPLASH_SCREEN_DURATION, VERIFY_TIMEOUT,
};
use std::collections::HashSet;
use strsim::jaro_winkler;
Expand Down Expand Up @@ -365,8 +365,16 @@ fn ResolvedServiceGridItem(resolved_service: ResolvedService) -> impl IntoView {
let instance_fullname = instance_fullname.clone();
async move { verify_instance(instance_fullname.clone()).await }
});
let verifying = create_rw_signal(false);
let on_verify_click = move |_| {
verifying.set(true);
verify_action.dispatch(instance_fullname.get_untracked());
set_timeout(
move || {
verifying.set(false);
},
VERIFY_TIMEOUT,
)
};

let mut hostname = resolved_service.hostname;
Expand Down Expand Up @@ -405,6 +413,7 @@ fn ResolvedServiceGridItem(resolved_service: ResolvedService) -> impl IntoView {
</CardHeaderExtra>
<Space align=SpaceAlign::Center>
<Button
loading=verifying
size=ButtonSize::Tiny
on_click=on_verify_click
disabled=resolved_service.dead
Expand Down

0 comments on commit a9c0f54

Please sign in to comment.