Skip to content

Commit

Permalink
Fix auto update
Browse files Browse the repository at this point in the history
  • Loading branch information
probablykasper committed Oct 8, 2024
1 parent da3b62c commit c6c5d08
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
20 changes: 14 additions & 6 deletions src/components/CheckForUpdates.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import Modal from './Modal.svelte'
import Button from './Button.svelte'
import { is_dev, save_view_options, view_options } from '@/lib/data'
import { check_shortcut } from '@/lib/helpers'
let latest_update: Awaited<ReturnType<typeof check>> | null = null
Expand Down Expand Up @@ -35,10 +36,19 @@
<Modal
on_cancel={() => (latest_update = null)}
cancel_on_escape
form={() => ipc_renderer.invoke('open_url', channel.url)}
form={() => {
ipc_renderer.invoke('open_url', channel.url)
latest_update = null
}}
title="A new version of Ferrum is available!"
on:keydown={(e) => {
if (check_shortcut(e, 'Enter')) {
ipc_renderer.invoke('open_url', channel.url)
latest_update = null
}
}}
>
<div class="max-w-xl text-sm">
<div class="w-md max-w-xl text-sm outline-none" autofocus tabindex="-1">
<p class="pb-3">
Ferrum {latest_update.channel.version} is available. You are currently on {latest_update.app_version}
</p>
Expand All @@ -56,10 +66,8 @@
}}>Skip This Version</Button
>
<div class="grow"></div>
<Button secondary autofocus on:click={() => (latest_update = null)}>Later</Button>
<Button type="submit" on:click={() => ipc_renderer.invoke('open_url', channel.url)}
>Update</Button
>
<Button secondary on:click={() => (latest_update = null)}>Later</Button>
<Button type="submit">Update</Button>
</svelte:fragment>
</Modal>
{/if}
9 changes: 5 additions & 4 deletions src/electron/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async function fetch_json(url: string) {
if (response instanceof Error) {
return { error: response.message, data: null }
} else if (response.status !== 200) {
return { error: `${response.status}: ${response.statusText}`, data: null }
return { error: `${response.status}: ${response.statusText}\n\n${url}`, data: null }
}

const value: JsonValue = await response.json().catch(() => {
Expand All @@ -55,12 +55,13 @@ export async function check_for_updates() {
if (
!release ||
typeof release !== 'object' ||
!('name' in release) ||
typeof release.name !== 'string'
!('tag_name' in release) ||
typeof release.tag_name !== 'string'
) {
return popup('Failed to check for updates', 'Could not parse JSON')
}
const update_json_url = `${package_json.repository}/releases/download/${release.name}/update.json`

const update_json_url = `${package_json.repository}/releases/download/${release.tag_name}/update.json`

const update_result = await fetch_json(update_json_url)
if (update_result.error) {
Expand Down

0 comments on commit c6c5d08

Please sign in to comment.