Skip to content

Commit

Permalink
Add "Skip This Version" button
Browse files Browse the repository at this point in the history
  • Loading branch information
probablykasper committed Oct 8, 2024
1 parent 207a0a4 commit 7fb91d3
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
1 change: 1 addition & 0 deletions ferrum-addon/addon.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ export interface ViewOptions {
shownPlaylistFolders: Array<string>
/** Empty is treated as default */
columns: Array<string>
skipUpdatingToVersion?: string
}
export declare function load_view_options(): ViewOptions
export declare function save_view_options(viewOptions: ViewOptions): void
Expand Down
2 changes: 2 additions & 0 deletions src-native/view_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub struct ViewOptions {
pub shown_playlist_folders: Vec<String>,
/// Empty is treated as default
pub columns: Vec<String>,
pub skip_updating_to_version: Option<String>,
}
impl ViewOptions {
pub fn load(paths: &Paths) -> ViewOptions {
Expand All @@ -23,6 +24,7 @@ impl ViewOptions {
Err(_) => ViewOptions {
shown_playlist_folders: Vec::new(),
columns: Vec::new(),
skip_updating_to_version: None,
},
}
}
Expand Down
11 changes: 10 additions & 1 deletion src/components/Button.svelte
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
<script lang="ts">
import type { HTMLBaseAttributes } from 'svelte/elements'
// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface $$Props extends HTMLBaseAttributes {
secondary?: boolean
danger?: boolean
type?: 'button' | 'submit' | 'reset'
}
export let secondary = false
export let danger = false
export let type: 'button' | 'submit' | 'reset' = 'button'
let normal = !danger && !secondary
$: normal = !danger && !secondary
</script>

<button on:click on:mousedown class:normal class:secondary class:danger {type}>
<button on:click on:mousedown class:normal class:secondary class:danger {type} {...$$restProps}>
<slot />
</button>

Expand Down
30 changes: 24 additions & 6 deletions src/components/CheckForUpdates.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { ipc_renderer } from '@/lib/window'
import Modal from './Modal.svelte'
import Button from './Button.svelte'
import { is_dev } from '@/lib/data'
import { is_dev, save_view_options, view_options } from '@/lib/data'
let latest_update: Awaited<ReturnType<typeof check>> | null = null
Expand All @@ -12,23 +12,33 @@
return
}
const result = await ipc_renderer.invoke('check_for_updates')
if (!result || result.channel.version === result.app_version) {
if (
!result ||
result.channel.version === result.app_version ||
result.channel.version === view_options.skipUpdatingToVersion
) {
return
}
latest_update = result
return result
}
function skip_update(version: string) {
view_options.skipUpdatingToVersion = version
save_view_options(view_options)
}
</script>

{#if latest_update}
{@const url = latest_update.channel.url}
{@const channel = latest_update.channel}
<Modal
on_cancel={() => (latest_update = null)}
cancel_on_escape
form={() => ipc_renderer.invoke('open_url', url)}
form={() => ipc_renderer.invoke('open_url', channel.url)}
title="A new version of Ferrum is available!"
>
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
<div class="max-w-xl text-sm">
<p class="pb-3">
Ferrum {latest_update.channel.version} is available. You are currently on {latest_update.app_version}
Expand All @@ -39,8 +49,16 @@
</p>
</div>
<svelte:fragment slot="buttons">
<Button secondary on:click={() => (latest_update = null)}>Later</Button>
<Button on:click={() => ipc_renderer.invoke('open_url', url)}>Update</Button>
<Button
secondary
on:click={() => {
skip_update(channel.version)
latest_update = null
}}>Skip This Version</Button
>
<div class="grow"></div>
<Button secondary autofocus on:click={() => (latest_update = null)}>Later</Button>
<Button on:click={() => ipc_renderer.invoke('open_url', channel.url)}>Update</Button>
</svelte:fragment>
</Modal>
{/if}

0 comments on commit 7fb91d3

Please sign in to comment.