Skip to content

Commit

Permalink
fix(menubar): only show latest release downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammed-Rahif committed Nov 19, 2024
1 parent d6c7370 commit 0ad3b44
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 17 deletions.
36 changes: 20 additions & 16 deletions src/lib/components/DownloadButton.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,29 @@
import DownloadIcon from '@/components/icons/Download.svelte';
import { slide } from 'svelte/transition';
function getContentForDownloadUrl(fileUrl: string) {
function getContentForDownloadUrl(fileUrl: string, versionName: string) {
const fileName = fileUrl.split('/').pop();
if (fileName?.endsWith('.deb')) return { text: 'Linux (.deb)', icon: LinuxIcon };
if (fileName?.endsWith('.rpm')) return { text: 'Linux (.rpm)', icon: LinuxIcon };
if (fileName?.endsWith('.exe')) return { text: 'Windows (.exe)', icon: WindowsIcon };
if (fileName?.endsWith('.msi')) return { text: 'Windows (.msi)', icon: WindowsIcon };
if (fileName?.endsWith('.dmg')) return { text: 'MacOS (.dmg)', icon: MacOSIcon };
if (fileName?.endsWith('.zip')) return { text: 'Source Code (.zip)', icon: LinuxIcon };
if (fileName?.endsWith('.tar.gz')) return { text: 'Source Code (.tar.gz)', icon: LinuxIcon };
return { text: 'Download', icon: DownloadIcon };
if (fileName?.endsWith('.deb')) return { text: `Linux (${versionName}.deb)`, icon: LinuxIcon };
if (fileName?.endsWith('.rpm')) return { text: `Linux (${versionName}.rpm)`, icon: LinuxIcon };
if (fileName?.endsWith('.exe'))
return { text: `Windows (${versionName}.exe)`, icon: WindowsIcon };
if (fileName?.endsWith('.msi'))
return { text: `Windows (${versionName}.msi)`, icon: WindowsIcon };
if (fileName?.endsWith('.dmg')) return { text: `MacOS (${versionName}.dmg)`, icon: MacOSIcon };
if (fileName?.endsWith('.zip'))
return { text: `Source Code (${versionName}.zip)`, icon: LinuxIcon };
if (fileName?.endsWith('.tar.gz'))
return { text: `Source Code (${versionName}.tar.gz)`, icon: LinuxIcon };
return { text: `Download`, icon: DownloadIcon };
}
</script>

{#await Notpad.github.getReleases() then releases}
{#if releases}
{@const assets = releases
.flatMap((release) => release.assets)
.sort((a, b) => a.name.localeCompare(b.name))}
{@const latestRelease = releases
.filter((release) => !release.draft)
.sort((a, b) => (a.published_at > b.published_at ? -1 : 1))[0]}
{@const latestAssets = latestRelease.assets}

<div
transition:slide|global
Expand All @@ -33,12 +38,11 @@
<Menubar.Menu>
<Menubar.Trigger>Download</Menubar.Trigger>
<Menubar.Content>
{#each assets as asset}
{@const { text, icon: Icon } = getContentForDownloadUrl(asset.name)}
{#each latestAssets as asset}
{@const { text, icon: Icon } = getContentForDownloadUrl(asset.name, latestRelease.name)}
<a href={asset.browser_download_url} download={asset.browser_download_url}>
<Menubar.Item class="flex items-center justify-between">
<Menubar.Item class="flex items-center justify-between gap-3">
{text}

<Icon class="text-xl" />
</Menubar.Item>
</a>
Expand Down
46 changes: 45 additions & 1 deletion src/lib/helpers/github-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,64 @@ export interface ContributorType {
}

export interface ReleasesType {
url: string;
assets_url: string;
upload_url: string;
html_url: string;
id: number;
author: Author;
node_id: string;
tag_name: string;
target_commitish: string;
name: string;
draft: boolean;
prerelease: boolean;
created_at: Date;
published_at: Date;
assets: Asset[];
tarball_url: string;
zipball_url: string;
body: string;
}

export interface Asset {
name: string;
url: string;
id: number;
node_id: string;
name: string;
label: string;
uploader: Author;
content_type: string;
state: string;
size: number;
download_count: number;
created_at: Date;
updated_at: Date;
browser_download_url: string;
}

export interface Author {
login: string;
id: number;
node_id: string;
avatar_url: string;
gravatar_id: string;
url: string;
html_url: string;
followers_url: string;
following_url: string;
gists_url: string;
starred_url: string;
subscriptions_url: string;
organizations_url: string;
repos_url: string;
events_url: string;
received_events_url: string;
type: string;
user_view_type: string;
site_admin: boolean;
}

export class GithubApi {
public async getAppLicense(): Promise<string | undefined> {
try {
Expand Down

0 comments on commit 0ad3b44

Please sign in to comment.