Skip to content

Commit

Permalink
Add acquiring arch and os and basing update upon that
Browse files Browse the repository at this point in the history
  • Loading branch information
kettek committed Oct 22, 2024
1 parent 02ce3b2 commit 7354820
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
1 change: 1 addition & 0 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type App struct {
versionString string
fsAccess sync.Mutex
RichPresence
Platform
}

// NewApp creates a new App application struct
Expand Down
19 changes: 16 additions & 3 deletions frontend/src/sections/About.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
-->
<script lang="ts">
import { onMount } from 'svelte'
import { Version, Update } from '../../wailsjs/go/main/App.js'
import { Version, Update, GetPlatform } from '../../wailsjs/go/main/App.js'
import { BrowserOpenURL } from '../../wailsjs/runtime/runtime.js'
import { ModalHeader, ModalBody, ModalFooter, Link } from 'carbon-components-svelte'
Expand All @@ -24,6 +24,19 @@
BrowserOpenURL((e.target as HTMLAnchorElement).href)
}
async function getRelativeTarget(asset: any[]) {
let platform = await GetPlatform()
if (platform.startsWith('windows')) {
platform += '.exe'
}
for (const a of asset) {
if (a.name === `Staxie-${platform}`) {
return a.browser_download_url
}
}
return ''
}
async function getRelease() {
const url = 'https://api.github.com/repos/kettek/staxie/releases/latest'
Expand All @@ -32,7 +45,7 @@
const results = await (await fetch(url)).json()
const tag = await (await fetch(`https://api.github.com/repos/kettek/staxie/git/ref/tags/${results.tag_name}`)).json()
const sha = (await (await fetch(`https://api.github.com/repos/kettek/staxie/git/tags/${tag.object.sha}`)).json())?.object?.sha
const match = results.assets.find((asset: any) => asset.name === 'Staxie.exe')?.browser_download_url
const match = await getRelativeTarget(results.assets)
downloadURL = match
availableVersion = results.tag_name
Expand Down Expand Up @@ -80,7 +93,7 @@
<article>
<header>Latest Version</header>
<Link on:click={followLink} href="https://github.com/kettek/staxie/releases/tag/{availableVersion}">{availableVersion} ({availableSHA})</Link>
{#if newer}
{#if newer && downloadURL}
<Button kind="ghost" size="small" icon={UpdateNow} tooltipPosition="bottom" tooltip="Update Now" on:click={update} />
{/if}
</article>
Expand Down
17 changes: 17 additions & 0 deletions platform.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package main

import "runtime"

type Platform struct{}

func (p *Platform) getArch() string {
return runtime.GOARCH
}

func (p *Platform) getOS() string {
return runtime.GOOS
}

func (p *Platform) GetPlatform() string {
return p.getOS() + "-" + p.getArch()
}

0 comments on commit 7354820

Please sign in to comment.