Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(about): add about with links to github #249

Merged
merged 4 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
27 changes: 19 additions & 8 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,22 @@ fn send_metrics(window: Window, state: State<ManagedState>) {
}
}

#[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";
Expand Down Expand Up @@ -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");
Expand Down
68 changes: 67 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<String>) {
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! {
<Layout style="padding: 10px;">
<Collapse accordion=true>
<CollapseItem title="About" key="about">
<Space>
<Text>"Version "{move || version.get()}</Text>
<Button size=ButtonSize::Tiny on_click=on_release_notes_click icon=icondata::AiGithubOutlined>"Release Notes"</Button>
<Button size=ButtonSize::Tiny on_click=on_report_issue_click icon=icondata::AiGithubOutlined>"Report an Issue"</Button>
<Button size=ButtonSize::Tiny on_click=on_issues_click icon=icondata::AiGithubOutlined>"Known Issues"</Button>
<Button size=ButtonSize::Tiny on_click=on_releases_click icon=icondata::AiGithubOutlined>"Releases"</Button>
</Space>
</CollapseItem>
</Collapse>
</Layout>
}
}
/// Component for metrics
#[component]
pub fn Metrics() -> impl IntoView {
Expand Down Expand Up @@ -725,6 +790,7 @@ pub fn App() -> impl IntoView {
view! {
<ThemeProvider theme>
<GlobalStyle/>
<About/>
<Metrics/>
<Browse/>
</ThemeProvider>
Expand Down