Skip to content

Commit

Permalink
feat: don show check for update if auto update is not supported (#414)
Browse files Browse the repository at this point in the history
  • Loading branch information
hrzlgnm authored Oct 20, 2024
1 parent f207ec9 commit 20bee22
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 17 deletions.
14 changes: 14 additions & 0 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,19 @@ fn is_desktop() -> bool {
true
}

#[cfg(desktop)]
#[tauri::command]
fn can_auto_update() -> bool {
#[cfg(target_os = "linux")]
{
false
}
#[cfg(not(target_os = "linux"))]
{
true
}
}

#[cfg(not(desktop))]
#[tauri::command]
fn is_desktop() -> bool {
Expand Down Expand Up @@ -531,6 +544,7 @@ pub fn run() {
app_updates::install_update,
browse,
browse_types,
can_auto_update,
copy_to_clipboard,
is_desktop,
open,
Expand Down
48 changes: 31 additions & 17 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -760,14 +760,21 @@ async fn get_version(writer: WriteSignal<String>) {
writer.update(|v| *v = ver);
}

async fn get_can_auto_update(writer: WriteSignal<bool>) {
let can_auto_update = invoke::<bool>("can_auto_update", &()).await;
writer.update(|v| *v = can_auto_update);
}

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());
let (update, set_update) = create_signal(None);
let (can_auto_update, set_can_auto_update) = create_signal(false);
create_local_resource(move || set_version, get_version);
create_local_resource(move || set_can_auto_update, get_can_auto_update);

let fetch_update_action = create_action(move |_: &()| async move {
let update = fetch_update().await;
Expand Down Expand Up @@ -854,27 +861,34 @@ pub fn About() -> impl IntoView {
"Releases"
</Button>
<Show
when=move || { can_install.get() }
when=move || { can_auto_update.get() }
fallback=move || {
view! {
<Button
size=ButtonSize::Tiny
on_click=on_check_update_click
icon=icondata::RiDownloadSystemLine
>
"Check for updates"
</Button>
}
view! { <div /> }
}
>
<Button
size=ButtonSize::Tiny
on_click=on_install_update_click
icon=icondata::RiInstallDeviceLine
<Show
when=move || { can_install.get() }
fallback=move || {
view! {
<Button
size=ButtonSize::Tiny
on_click=on_check_update_click
icon=icondata::RiDownloadSystemLine
>
"Check for updates"
</Button>
}
}
>
"Download and Install "
{{ installable_version }}
</Button>
<Button
size=ButtonSize::Tiny
on_click=on_install_update_click
icon=icondata::RiInstallDeviceLine
>
"Download and Install "
{{ installable_version }}
</Button>
</Show>
</Show>
</Space>
</CollapseItem>
Expand Down

0 comments on commit 20bee22

Please sign in to comment.