diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 37ee6a64..d0f5f995 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -2,7 +2,7 @@ use clap::builder::TypedValueParser as _; #[cfg(desktop)] use clap::Parser; -use mdns_sd::{ServiceDaemon, ServiceEvent, ServiceInfo}; +use mdns_sd::{ServiceDaemon, ServiceEvent, ServiceInfo, VERIFY_TIMEOUT_DEFAULT}; use models::*; #[cfg(all(desktop, not(debug_assertions)))] use shared_constants::SPLASH_SCREEN_DURATION; @@ -102,6 +102,14 @@ fn stop_browse(service_type: String, state: State) { } } +#[tauri::command] +fn verify(instance_fullname: String, state: State) { + if let Ok(mdns) = state.daemon.lock() { + mdns.verify(instance_fullname, VERIFY_TIMEOUT_DEFAULT) + .expect("To verify an instance"); + } +} + fn from_service_info(info: &ServiceInfo) -> ResolvedService { let mut sorted_addresses: Vec = info.get_addresses().clone().drain().collect(); sorted_addresses.sort(); @@ -476,6 +484,7 @@ pub fn run() { open, send_metrics, stop_browse, + verify, version, ]) .run(tauri::generate_context!()) @@ -497,6 +506,7 @@ pub fn run_mobile() { open, send_metrics, stop_browse, + verify, ]) .run(tauri::generate_context!()) .expect("error while running tauri application"); diff --git a/src/app.rs b/src/app.rs index 5776ea64..2b249bd1 100644 --- a/src/app.rs +++ b/src/app.rs @@ -166,6 +166,22 @@ async fn stop_browse(service_type: String) { .await; } +#[derive(Serialize, Deserialize)] +#[allow(non_snake_case)] +struct VerifyArgs<'a> { + instanceFullname: &'a str, +} + +async fn verify_instance(instance_fullname: String) { + let _ = invoke::<()>( + "verify", + &VerifyArgs { + instanceFullname: &instance_fullname, + }, + ) + .await; +} + /// Component to render a string vector into a table #[component] fn ValuesTable(values: Vec, #[prop(into)] title: String) -> impl IntoView { @@ -294,21 +310,6 @@ fn AutoCompleteServiceType( } } -#[derive(Serialize, Deserialize)] -struct CopyToClipboardArgs<'a> { - contents: &'a str, -} - -async fn copy_to_clipboard(contents: String) { - let _ = invoke::<()>( - "copy_to_clipboard", - &CopyToClipboardArgs { - contents: &contents, - }, - ) - .await; -} - /// Component that allows to copy the shown text to the clipboard #[component] fn ToClipBoardCopyable( @@ -339,10 +340,38 @@ fn ToClipBoardCopyable( } } +#[derive(Serialize, Deserialize)] +struct CopyToClipboardArgs<'a> { + contents: &'a str, +} + +async fn copy_to_clipboard(contents: String) { + let _ = invoke::<()>( + "copy_to_clipboard", + &CopyToClipboardArgs { + contents: &contents, + }, + ) + .await; +} + /// Component that shows a service as a card #[component] fn ResolvedServiceGridItem(resolved_service: ResolvedService) -> impl IntoView { log::debug!("ResolvedServiceGridItem"); + + let instance_fullname = create_rw_signal(format!( + "{}.{}", + resolved_service.instance_name, resolved_service.hostname + )); + let verify_action = create_action(|instance_fullname: &String| { + let instance_fullname = instance_fullname.clone(); + async move { verify_instance(instance_fullname.clone()).await } + }); + let on_verify_click = move |_| { + verify_action.dispatch(instance_fullname.get_untracked()); + }; + let mut hostname = resolved_service.hostname; hostname.pop(); // remove the trailing dot let updated_at = DateTime::from_timestamp_millis(resolved_service.updated_at_ms as i64) @@ -362,20 +391,14 @@ fn ResolvedServiceGridItem(resolved_service: ResolvedService) -> impl IntoView { None => vec![], Some(s) => vec![s], }; + let card_title = get_instance_name(resolved_service.instance_name.as_str()); let details_title = card_title.clone(); let show_details = create_rw_signal(false); - let hostname_variant = match resolved_service.dead { - true => TagVariant::Default, - false => TagVariant::Success, - }; - let port_variant = match resolved_service.dead { - true => TagVariant::Default, - false => TagVariant::Warning, - }; - let addrs_footer = match resolved_service.dead { - true => vec![], - false => addrs.clone(), + let (hostname_variant, port_variant, addrs_footer) = if resolved_service.dead { + (TagVariant::Default, TagVariant::Default, vec![]) + } else { + (TagVariant::Success, TagVariant::Warning, addrs.clone()) }; view! { @@ -384,6 +407,12 @@ fn ResolvedServiceGridItem(resolved_service: ResolvedService) -> impl IntoView { {as_local_datetime.format("%Y-%m-%d %H:%M:%S").to_string()} +