diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 05ee7bf..ce93a1c 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -12,6 +12,7 @@ tauri-build = { version = "1.5.5", features = [] } clap = { version = "4.5.17", features = ["derive"] } log = "0.4.22" mdns-sd = { version = "0.11.4", features = ["async", "log"] } +open = "5" serde = { version = "1.0.210", features = ["derive"] } serde_json = "1.0.128" tauri = { version = "1.8.0", features = [ diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 5eb0888..9edecfa 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -286,6 +286,22 @@ fn send_metrics(window: Window, state: State) { } } +#[tauri::command] +fn open(url: String) { + let _ = open::that(url.clone()).map_err(|e| log::error!("Failed to open {}: {}", url, e)); +} + +#[tauri::command] +fn version(window: Window) -> String { + window + .app_handle() + .config() + .package + .version + .clone() + .unwrap_or(String::from("Unknown")) +} + #[cfg(target_os = "linux")] fn platform_setup() { let session_type_key = "XDG_SESSION_TYPE"; @@ -380,25 +396,20 @@ fn main() { .setup(|app| { let splashscreen_window = app.get_window("splashscreen").unwrap(); let main_window = app.get_window("main").unwrap(); - let ver = app.config().package.version.clone(); tauri::async_runtime::spawn(async move { std::thread::sleep(std::time::Duration::from_secs(3)); splashscreen_window.close().unwrap(); main_window.show().unwrap(); - main_window - .set_title( - format!("mDNS-Browser v{}", ver.unwrap_or(String::from("Unknown"))) - .as_str(), - ) - .expect("title to be set"); }); Ok(()) }) .invoke_handler(tauri::generate_handler![ browse, browse_types, + open, send_metrics, - stop_browse + stop_browse, + version ]) .run(tauri::generate_context!()) .expect("error while running tauri application"); diff --git a/src/app.rs b/src/app.rs index f722765..787b031 100644 --- a/src/app.rs +++ b/src/app.rs @@ -17,7 +17,7 @@ use tauri_sys::tauri::invoke; use thaw::{ AutoComplete, AutoCompleteOption, AutoCompleteSuffix, Button, ButtonSize, Card, CardFooter, CardHeaderExtra, Collapse, CollapseItem, GlobalStyle, Grid, GridItem, Icon, Layout, Modal, - Space, SpaceAlign, Table, Tag, TagVariant, Theme, ThemeProvider, + Space, SpaceAlign, Table, Tag, TagVariant, Text, Theme, ThemeProvider, }; use thaw_utils::Model; @@ -665,6 +665,71 @@ fn Browse() -> impl IntoView { } } +#[derive(Serialize, Deserialize)] +struct OpenArgs<'a> { + url: &'a str, +} + +async fn open(url: &str) { + let _: () = invoke("open", &OpenArgs { url }).await.unwrap(); +} + +async fn get_version(writer: WriteSignal) { + let ver: String = invoke("version", &()).await.unwrap(); + log::debug!("Got version {}", ver); + writer.update(|v| *v = ver); +} + +const GITHUB_BASE_URL: &str = "https://github.com/hrzlgnm/mdns-browser"; + +/// Component for info about the app +#[component] +pub fn About() -> impl IntoView { + let (version, set_version) = create_signal(String::new()); + create_local_resource(move || set_version, get_version); + let github_action = create_action(|action: &String| { + let action = action.clone(); + log::debug!("Opening {}", action); + async move { open(action.clone().as_str()).await } + }); + + let on_release_notes_click = move |_| { + github_action.dispatch(format!( + "{}/releases/tag/mdns-browser-v{}", + GITHUB_BASE_URL, + version.get() + )); + }; + + let on_issues_click = move |_| { + github_action.dispatch(format!( + "{}/issues?q=is%3Aopen+is%3Aissue+label%3Abug", + GITHUB_BASE_URL + )); + }; + let on_report_issue_click = move |_| { + github_action.dispatch(format!("{}/issues/new", GITHUB_BASE_URL)); + }; + let on_releases_click = move |_| { + github_action.dispatch(format!("{}/releases/", GITHUB_BASE_URL)); + }; + + view! { + + + + + "Version "{move || version.get()} + + + + + + + + + } +} /// Component for metrics #[component] pub fn Metrics() -> impl IntoView { @@ -725,6 +790,7 @@ pub fn App() -> impl IntoView { view! { +