Files
minstrel/web/src/lib/components/MobileAppDownload.svelte
T

56 lines
2.1 KiB
Svelte
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script lang="ts">
import { onMount } from 'svelte';
import { Download, Smartphone } from 'lucide-svelte';
import { api } from '#lib/api/client.js';
import { formatBytes } from '#lib/utils/bytes.js';
import SettingsGroup from '#lib/components/settings/SettingsGroup.svelte';
import SettingRow from '#lib/components/settings/SettingRow.svelte';
// The Android app this server bundles, at the top of Settings › Account
// (#5595). Polls /api/client/version once on mount. Renders nothing on
// 404 (no bundled APK: dev and pre-CI images) or 401.
//
// The /api/client/* endpoints are auth-gated to prevent anonymous
// bandwidth abuse on the APK stream, so this only shows to a signed-in
// user. Mount in Settings, never on a pre-auth page.
// Server returns snake_case (clientVersionResponse in
// internal/api/client_assets.go).
type WireInfo = { version: string; apk_url: string; size_bytes: number };
type Info = { version: string; apkUrl: string; sizeBytes: number };
let info = $state<Info | null>(null);
onMount(async () => {
try {
const body = await api.get<Partial<WireInfo>>('/api/client/version');
if (!body.version || !body.apk_url) return;
info = {
version: body.version,
apkUrl: body.apk_url,
sizeBytes: body.size_bytes ?? 0
};
} catch {
// 404 (no APK), 401 (somehow unauthed), network error — silent.
}
});
</script>
{#if info}
<SettingsGroup title="Android app">
<SettingRow
label="Minstrel for Android"
hint="{info.version}{info.sizeBytes > 0 ? ` · ${formatBytes(info.sizeBytes)}` : ''} · sign in with this account"
>
<Smartphone size={18} strokeWidth={1.5} class="text-text-secondary" aria-hidden="true" />
<a
href={info.apkUrl}
download="minstrel.apk"
class="inline-flex items-center gap-1.5 rounded-md bg-action-secondary px-3 py-1.5 text-sm text-action-fg hover:opacity-90 focus-visible:ring-2 focus-visible:ring-accent"
>
<Download size={16} strokeWidth={1.75} aria-hidden="true" /> Download
</a>
</SettingRow>
</SettingsGroup>
{/if}