commit
a
diff --git a/ReadMe.md b/ReadMe.md
index 6ad5743..f6354f8 100644
--- a/ReadMe.md
+++ b/ReadMe.md
@@ -21,6 +21,7 @@ account system.
- Discord Rich Presence (desktop) showing what you're playing
- OS media controls / lock-screen widget (media keys, Now Playing)
- One codebase, three targets: **web**, **desktop** (Windows/macOS/Linux), and **Android**
+- In-app **Get the app** page (`/downloads`) with the latest per-platform builds, plus back/forward history arrows in the header
## Tech stack
diff --git a/web/client/src/app.ts b/web/client/src/app.ts
index df40bce..b022ce1 100644
--- a/web/client/src/app.ts
+++ b/web/client/src/app.ts
@@ -25,6 +25,7 @@ import {
startDesktopLogin,
clearDesktopToken,
isDesktop,
+ openExternal,
syncDiscordPresence,
} from "./desktop.ts";
import { initNative } from "./native.ts";
@@ -49,6 +50,7 @@ type View =
| { kind: "linkRequests" }
| { kind: "pendingSongs" }
| { kind: "editRequests" }
+ | { kind: "downloads" }
| { kind: "settings" };
// Admin-only views, and views that need any account, gated in boot()/popstate.
@@ -85,6 +87,7 @@ function viewToPath(view: View): string {
case "linkRequests": return "/admin/link-requests";
case "pendingSongs": return "/admin/pending";
case "editRequests": return "/admin/edit-requests";
+ case "downloads": return "/downloads";
case "settings": return "/settings";
}
}
@@ -101,20 +104,38 @@ function pathToView(pathname: string): View {
if (head === "admin" && id === "link-requests") return { kind: "linkRequests" };
if (head === "admin" && id === "pending") return { kind: "pendingSongs" };
if (head === "admin" && id === "edit-requests") return { kind: "editRequests" };
+ if (head === "downloads") return { kind: "downloads" };
if (head === "settings") return { kind: "settings" };
return { kind: "library" };
}
+// Position in our own in-app history, mirrored into history.state, so the
+// header's back/forward arrows can tell when they're at an end. It's a
+// counter, not the browser's real history length (which we can't read).
+let navPos = 0;
+let navMax = 0;
+
// Every user-triggered view change goes through here so the address bar
// always matches what's on screen (and so it's shareable/hotlinkable).
// popstate (back/forward) sets state.view + renders directly instead, since
// the URL there is already correct — see the listener below.
function navigate(view: View): void {
state.view = view;
- history.pushState(null, "", viewToPath(view));
+ navPos += 1;
+ navMax = navPos; // a new navigation truncates any forward stack
+ history.pushState({ navPos }, "", viewToPath(view));
render();
}
+// In-app back/forward. history.back()/forward() fire popstate, which just
+// re-renders the SPA — no page load, so audio keeps playing.
+function goBack(): void {
+ if (navPos > 0) history.back();
+}
+function goForward(): void {
+ if (navPos < navMax) history.forward();
+}
+
const state = {
me: null as Me | null,
songs: [] as Song[],
@@ -294,16 +315,33 @@ async function boot(): Promise<void> {
restoreNowPlaying();
handleLastfmRedirect();
+ // Stamp the landing entry so the back/forward arrows have a baseline.
+ history.replaceState({ navPos }, "", window.location.pathname + window.location.search);
render();
}
// Back/forward: the URL is already correct, so just re-derive the view from
// it and render — no history.pushState (that would double up entries).
-window.addEventListener("popstate", () => {
+window.addEventListener("popstate", (e) => {
+ const p = (e.state as { navPos?: number } | null)?.navPos;
+ navPos = typeof p === "number" ? p : 0;
state.view = allowedView(pathToView(window.location.pathname));
render();
});
+// Alt+Arrow back/forward (browsers already do this on web; belt-and-braces
+// for the Electron shell where there's no browser chrome).
+document.addEventListener("keydown", (e) => {
+ if (!e.altKey || e.metaKey || e.ctrlKey) return;
+ if (e.key === "ArrowLeft") {
+ e.preventDefault();
+ goBack();
+ } else if (e.key === "ArrowRight") {
+ e.preventDefault();
+ goForward();
+ }
+});
+
// After the Last.fm "Connect" handshake, the backend redirects back here
// with ?lastfm=connected|error. Surface that, land on Settings, and drop
// the param so a refresh doesn't re-show the toast.
@@ -316,7 +354,7 @@ function handleLastfmRedirect(): void {
if (result === "connected") flash("Last.fm connected.");
else if (result === "error") flash("Couldn't connect Last.fm. Try again?");
- history.replaceState(null, "", viewToPath(state.view));
+ history.replaceState({ navPos }, "", viewToPath(state.view));
}
async function loadSongs(): Promise<void> {
@@ -366,7 +404,15 @@ function render(): void {
<div class="layout">
<aside class="sidebar" id="sidebar"></aside>
<div class="scrim" id="scrim"></div>
- <main class="main" id="main"></main>
+ <main class="main" id="main">
+ <nav class="nav-arrows" aria-label="History">
+ <button class="icon-btn" id="nav-back" title="Back (Alt+Left)" aria-label="Back">
+ <i class="bi bi-chevron-left"></i></button>
+ <button class="icon-btn" id="nav-fwd" title="Forward (Alt+Right)" aria-label="Forward">
+ <i class="bi bi-chevron-right"></i></button>
+ </nav>
+ <div id="main-content"></div>
+ </main>
</div>
<div class="playerbar" id="playerbar"></div>
`;
@@ -374,6 +420,17 @@ function render(): void {
renderMain();
renderPlayerBar();
+ const back = document.getElementById("nav-back") as HTMLButtonElement | null;
+ const fwd = document.getElementById("nav-fwd") as HTMLButtonElement | null;
+ if (back) {
+ back.disabled = navPos <= 0;
+ back.addEventListener("click", goBack);
+ }
+ if (fwd) {
+ fwd.disabled = navPos >= navMax;
+ fwd.addEventListener("click", goForward);
+ }
+
const sidebar = document.getElementById("sidebar");
const scrim = document.getElementById("scrim");
const closeDrawer = () => {
@@ -470,6 +527,7 @@ function renderSidebar(): void {
}
${nav("browse", "Browse shared")}
${nav("artists", "Artists")}
+ ${nav("downloads", `<i class="bi bi-download"></i> Get the app`)}
${
state.me?.isAdmin
? `
@@ -518,6 +576,7 @@ function renderSidebar(): void {
| "linkRequests"
| "pendingSongs"
| "editRequests"
+ | "downloads"
| "settings";
navigate({ kind });
});
@@ -552,7 +611,7 @@ function renderSidebar(): void {
// --- main area -------------------------------------------------------------
async function renderMain(): Promise<void> {
- const el = document.getElementById("main");
+ const el = document.getElementById("main-content");
if (!el) return;
const view = state.view;
@@ -566,6 +625,7 @@ async function renderMain(): Promise<void> {
else if (view.kind === "linkRequests") await renderLinkRequests(el);
else if (view.kind === "pendingSongs") await renderPendingSongs(el);
else if (view.kind === "editRequests") await renderEditRequests(el);
+ else if (view.kind === "downloads") await renderDownloadsView(el);
else if (view.kind === "settings") await renderSettings(el);
else await renderPlaylistView(el, view.id);
}
@@ -656,6 +716,9 @@ function renderLibrary(el: HTMLElement): void {
Hide explicit
</label>
<input id="search" class="search" placeholder="Search title or artist" />
+ <button class="btn btn-sm" id="get-app" title="Download the desktop & mobile apps">
+ <i class="bi bi-download"></i> Get the app
+ </button>
</div>
</header>
<div id="songlist">${songTableHtml(shown)}</div>
@@ -663,6 +726,10 @@ function renderLibrary(el: HTMLElement): void {
wireSongList();
+ document
+ .getElementById("get-app")
+ ?.addEventListener("click", () => navigate({ kind: "downloads" }));
+
document.getElementById("hide-explicit")?.addEventListener("change", (e) => {
hideExplicit = (e.target as HTMLInputElement).checked;
try {
@@ -687,6 +754,60 @@ function renderLibrary(el: HTMLElement): void {
});
}
+// --- downloads (native apps) ----------------------------------------------
+
+async function renderDownloadsView(el: HTMLElement): Promise<void> {
+ el.innerHTML = `
+ <header class="main-head"><h2>Get the app</h2></header>
+ <p class="empty">Loading…</p>
+ `;
+
+ let data: Awaited<ReturnType<typeof api.getDownloads>>;
+ try {
+ data = await api.getDownloads();
+ } catch {
+ el.innerHTML = `
+ <header class="main-head"><h2>Get the app</h2></header>
+ <p class="empty">Couldn't load the download list. Try again later.</p>
+ `;
+ return;
+ }
+
+ const cards = data.platforms
+ .map(
+ (p) => `
+ <a class="download-card" href="${escapeHtml(p.url)}" target="_blank" rel="noopener">
+ <i class="bi bi-${escapeHtml(p.icon)}"></i>
+ <span class="dl-label">${escapeHtml(p.label)}</span>
+ <span class="dl-file">${escapeHtml(p.filename)}</span>
+ <span class="dl-go"><i class="bi bi-download"></i> Download</span>
+ </a>`,
+ )
+ .join("");
+
+ el.innerHTML = `
+ <header class="main-head"><h2>Get the app</h2></header>
+ <p class="downloads-sub">
+ Stream in any browser, or install the app for Discord Rich Presence, media
+ keys and offline-friendly playback.
+ ${data.tag ? `Latest release: <strong>${escapeHtml(data.codename)}</strong> (${escapeHtml(data.tag)}).` : ""}
+ </p>
+ <div class="downloads-grid">${cards || `<p class="empty">No builds published yet.</p>`}</div>
+ <p class="downloads-foot">
+ <a href="${escapeHtml(data.releaseUrl)}" target="_blank" rel="noopener">Release notes & checksums</a>
+ · <a href="${escapeHtml(data.repoUrl)}" target="_blank" rel="noopener">All versions</a>
+ </p>
+ `;
+
+ // Desktop: a top-level <a> would navigate the Electron webview off the
+ // app, so hand external links to the system browser instead.
+ el.querySelectorAll<HTMLAnchorElement>("a[href^='http']").forEach((a) => {
+ a.addEventListener("click", (e) => {
+ if (openExternal(a.href)) e.preventDefault();
+ });
+ });
+}
+
// --- playlist modals ---------------------------------------------------------
function openCreatePlaylistModal(): void {
diff --git a/web/client/src/desktop.ts b/web/client/src/desktop.ts
index 13d8d4b..eb78d0f 100644
--- a/web/client/src/desktop.ts
+++ b/web/client/src/desktop.ts
@@ -61,6 +61,16 @@ export function initDesktopBridge(): void {
}
}
+// Open a URL outside the app. On desktop this hands off to the system
+// browser (a plain <a href> would navigate the Electron webview away from
+// the app); on web it's a no-op and the caller lets the link behave.
+// Returns true if it handled the open.
+export function openExternal(url: string): boolean {
+ if (!bridge) return false;
+ void bridge.openExternal(url);
+ return true;
+}
+
// True once a token is stored — lets the UI skip a re-auth on boot.
export function hasDesktopToken(): boolean {
try {
diff --git a/web/client/src/styles.css b/web/client/src/styles.css
index 916cc30..bee4e4c 100644
--- a/web/client/src/styles.css
+++ b/web/client/src/styles.css
@@ -219,6 +219,28 @@ button {
overflow-y: auto;
}
+/* header back/forward arrows — sticky so they stay put while a view scrolls */
+.nav-arrows {
+ position: sticky;
+ top: 0;
+ z-index: 5;
+ display: flex;
+ gap: 0.25rem;
+ margin: -1.5rem -2rem 0.5rem;
+ padding: 0.5rem 2rem;
+ background: var(--bg);
+}
+
+.nav-arrows .icon-btn {
+ border: 1px solid var(--border);
+ background: var(--panel);
+}
+
+.nav-arrows .icon-btn:disabled {
+ opacity: 0.3;
+ pointer-events: none;
+}
+
.main-head {
display: flex;
justify-content: space-between;
@@ -1278,6 +1300,75 @@ button {
font-size: 0.75rem;
}
+/* --- downloads ("Get the app") --- */
+
+.downloads-sub {
+ color: var(--muted);
+ max-width: 60ch;
+ margin: -0.25rem 0 1.25rem;
+}
+
+.downloads-grid {
+ display: grid;
+ grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
+ gap: 0.75rem;
+ max-width: 720px;
+}
+
+.download-card {
+ display: grid;
+ grid-template-columns: auto 1fr;
+ grid-template-areas:
+ "icon label"
+ "icon file"
+ "go go";
+ column-gap: 0.75rem;
+ row-gap: 0.15rem;
+ padding: 1rem;
+ border: 1px solid var(--border);
+ border-radius: var(--radius);
+ background: var(--panel);
+ color: var(--text);
+ text-decoration: none;
+}
+
+.download-card:hover {
+ border-color: var(--accent);
+ background: var(--panel-2);
+}
+
+.download-card > .bi:first-child {
+ grid-area: icon;
+ font-size: 1.6rem;
+ align-self: center;
+ color: var(--accent);
+}
+
+.download-card .dl-label {
+ grid-area: label;
+ font-weight: 600;
+}
+
+.download-card .dl-file {
+ grid-area: file;
+ color: var(--muted);
+ font-size: 0.75rem;
+ word-break: break-all;
+}
+
+.download-card .dl-go {
+ grid-area: go;
+ margin-top: 0.6rem;
+ color: var(--accent);
+ font-size: 0.9rem;
+}
+
+.downloads-foot {
+ margin-top: 1.5rem;
+ color: var(--muted);
+ font-size: 0.85rem;
+}
+
/* --- responsive --- */
@media (max-width: 768px) {
@@ -1319,6 +1410,14 @@ button {
padding: 3.5rem 1rem 1rem;
}
+ /* static on mobile: sticky would collide with the fixed hamburger */
+ .nav-arrows {
+ position: static;
+ margin: 0 0 0.5rem;
+ padding: 0;
+ background: none;
+ }
+
.main-head {
flex-wrap: wrap;
gap: 0.75rem;
diff --git a/web/server/src/lib/downloads.ts b/web/server/src/lib/downloads.ts
index 4075e36..b531a34 100644
--- a/web/server/src/lib/downloads.ts
+++ b/web/server/src/lib/downloads.ts
@@ -44,6 +44,58 @@ function findVersion(name: string): VersionEntry | undefined {
return Object.values(versions).find((v) => v.tag.toLowerCase() === name);
}
+// Display metadata for the "Get the app" page. Keys match downloads.json's
+// `platforms`; anything not listed falls back to a generic label/icon.
+const PLATFORM_META: Record<string, { label: string; icon: string }> = {
+ windows: { label: "Windows", icon: "windows" },
+ mac: { label: "macOS", icon: "apple" },
+ linux: { label: "Linux · AppImage", icon: "box-seam" },
+ deb: { label: "Linux · Debian / Ubuntu", icon: "ubuntu" },
+ android: { label: "Android · APK", icon: "android2" },
+};
+
+export interface AppDownloadPlatform {
+ key: string;
+ label: string;
+ icon: string;
+ filename: string;
+ url: string;
+}
+
+export interface AppDownloads {
+ codename: string;
+ tag: string;
+ repoUrl: string;
+ releaseUrl: string;
+ platforms: AppDownloadPlatform[];
+}
+
+/**
+ * Every platform's asset URL for whichever version the manifest marks
+ * latest — the data behind the in-app "Get the app" page. Built on top of
+ * resolveDownload() so the filename/override logic lives in one place.
+ */
+export function listLatestDownloads(): AppDownloads {
+ const codename = manifest.latest;
+ const version = findVersion(codename);
+ const tag = version?.tag ?? "";
+
+ const platformList = platformNames.flatMap<AppDownloadPlatform>((key) => {
+ const target = resolveDownload(undefined, key);
+ if (target.kind !== "asset") return [];
+ const meta = PLATFORM_META[key] ?? { label: key, icon: "download" };
+ return [{ key, label: meta.label, icon: meta.icon, filename: target.file, url: target.url }];
+ });
+
+ return {
+ codename,
+ tag,
+ repoUrl,
+ releaseUrl: tag ? `${repoUrl}/releases/tag/${tag}` : repoUrl,
+ platforms: platformList,
+ };
+}
+
export type DownloadTarget =
| { kind: "repo"; url: string }
| { kind: "release"; url: string; tag: string }
diff --git a/web/server/src/server.ts b/web/server/src/server.ts
index a459a83..1032c26 100644
--- a/web/server/src/server.ts
+++ b/web/server/src/server.ts
@@ -13,6 +13,7 @@ import {
} from "./auth/middleware.ts";
import {
resolveDownload,
+ listLatestDownloads,
versionNames,
platformNames,
} from "./lib/downloads.ts";
@@ -136,6 +137,10 @@ app.get("/download", (c) => {
}
});
+// Structured version of the above for the in-app "Get the app" page: every
+// platform's asset URL for the latest release. Open to everyone.
+app.get("/api/downloads", (c) => c.json(listLatestDownloads()));
+
// Shareable per-song link. Must sit before the SPA catch-all.
//
// /song/<id> -> the SPA, with song-specific unfurl metadata
diff --git a/web/shared/src/api-client.ts b/web/shared/src/api-client.ts
index 8bced07..ff5c285 100644
--- a/web/shared/src/api-client.ts
+++ b/web/shared/src/api-client.ts
@@ -16,6 +16,7 @@ import type {
LinkRequest,
DuplicateReview,
Lyrics,
+ AppDownloads,
} from "./types.ts";
let baseUrl = "";
@@ -462,4 +463,10 @@ export const api = {
body: JSON.stringify(track),
});
},
+
+ // Native app builds for the "Get the app" page — latest release's per-
+ // platform asset URLs, resolved server-side from downloads.json.
+ getDownloads(): Promise<AppDownloads> {
+ return fetch(url("/api/downloads")).then(json<AppDownloads>);
+ },
};
diff --git a/web/shared/src/types.ts b/web/shared/src/types.ts
index cd8064e..8c52047 100644
--- a/web/shared/src/types.ts
+++ b/web/shared/src/types.ts
@@ -132,3 +132,19 @@ export type Lyrics = {
synced: SyncedLine[];
plain: string | null;
};
+
+export type AppDownloadPlatform = {
+ key: string;
+ label: string;
+ icon: string; // Bootstrap Icons name, without the "bi-" prefix
+ filename: string;
+ url: string;
+};
+
+export type AppDownloads = {
+ codename: string;
+ tag: string;
+ repoUrl: string;
+ releaseUrl: string;
+ platforms: AppDownloadPlatform[];
+};