commit
aaa
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index e10cd13..5399fde 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -79,6 +79,16 @@ jobs:
- run: bun install
+ # electron-updater compares the running app's version against the one in
+ # the published latest*.yml, so the packaged build has to carry the tag's
+ # version (the checked-in package.json is only ever a floor).
+ - name: stamp desktop version
+ working-directory: apps/desktop
+ shell: bash
+ run: npm version --no-git-tag-version --allow-same-version "${VERSION#v}"
+ env:
+ VERSION: ${{ inputs.version || github.ref_name }}
+
# Compiles apps/desktop/src -> dist, then electron-builder packages it.
# electron-builder reads apps/desktop/package.json `dependencies` to
# bundle @xhayper/discord-rpc. Artifact names are pinned (version-less)
@@ -101,6 +111,8 @@ jobs:
apps/desktop/release/*.exe
apps/desktop/release/*.AppImage
apps/desktop/release/*.deb
+ apps/desktop/release/*.blockmap
+ apps/desktop/release/latest*.yml
android:
# Builds and publishes the SIGNED native Android APK (apps/android): a
diff --git a/ReadMe.md b/ReadMe.md
index f6354f8..8525a96 100644
--- a/ReadMe.md
+++ b/ReadMe.md
@@ -30,7 +30,7 @@ account system.
| Runtime | [Bun](https://bun.sh) |
| Backend | [Hono](https://hono.dev) · PostgreSQL · Redis · `jose` (OIDC/JWT) |
| Web app | Vanilla TypeScript (no framework), bundled by Bun · Bootstrap Icons |
-| Desktop | [Electron](https://www.electronjs.org/) (TypeScript) · Discord Rich Presence over IPC |
+| Desktop | [Electron](https://www.electronjs.org/) (TypeScript) · Discord Rich Presence over IPC · auto-update from GitHub Releases |
| Android | Native Kotlin · WebView UI + Media3/ExoPlayer for background playback |
| Auth | Pocket ID (OIDC) — session cookie for web, bearer token for native apps |
| Media | FFmpeg (Opus transcode) · `yt-dlp` (YouTube import) · optional nginx `X-Accel-Redirect` offload |
@@ -105,9 +105,12 @@ cd apps/android && gradle assembleRelease
```
The desktop app is a thin shell: it loads the live site (default
-`https://doughmination.me`, overridable via `DMND_SERVER_URL` or **File → Set
-Server URL…**) and adds `doughmination://` deep-link sign-in plus Discord Rich
-Presence over the local Discord IPC socket.
+`https://doughmination.me`, overridable via `DMND_SERVER_URL`, or **File → Set
+Server URL…** on macOS / **Ctrl+Alt+S** on Windows/Linux) and adds
+`doughmination://` deep-link sign-in (and Last.fm connect), Discord Rich
+Presence over the local Discord IPC socket, and background auto-update from
+this repo's GitHub Releases. Windows/Linux builds run without a menu bar;
+macOS keeps the standard application menu.
### Arch: install from the AUR
diff --git a/apps/desktop/electron-builder.yml b/apps/desktop/electron-builder.yml
index 03c0a4d..0936fcc 100644
--- a/apps/desktop/electron-builder.yml
+++ b/apps/desktop/electron-builder.yml
@@ -7,11 +7,23 @@ directories:
buildResources: build
# The compiled main/preload plus package.json (electron-builder reads
-# `dependencies` from it to bundle @xhayper/discord-rpc).
+# `dependencies` from it to bundle @xhayper/discord-rpc + electron-updater).
+# icon.* rides along so the runtime BrowserWindow `icon` (title bar / taskbar
+# on Linux, dev on every OS) resolves inside app.asar.
files:
- dist/**/*
+ - build/icon.png
+ - build/icon.ico
- package.json
+# Where electron-updater looks for new versions. The release workflow publishes
+# every build to this repo's GitHub Releases, including the latest*.yml update
+# feeds electron-builder emits alongside the installers.
+publish:
+ provider: github
+ owner: Clove-Web
+ repo: pocket-id-music-player
+
# Register doughmination:// so the SSO deep link comes back to the app
# (writes the nsis registry keys / Info.plist CFBundleURLTypes / .desktop
# MimeType).
diff --git a/apps/desktop/package.json b/apps/desktop/package.json
index 2d982af..6b437d8 100644
--- a/apps/desktop/package.json
+++ b/apps/desktop/package.json
@@ -18,7 +18,8 @@
"typecheck": "tsc --noEmit"
},
"dependencies": {
- "@xhayper/discord-rpc": "^1.2.1"
+ "@xhayper/discord-rpc": "^1.2.1",
+ "electron-updater": "^6.3.9"
},
"devDependencies": {
"@types/node": "^22.10.0",
diff --git a/apps/desktop/src/main.ts b/apps/desktop/src/main.ts
index 5e532b6..23d71cf 100644
--- a/apps/desktop/src/main.ts
+++ b/apps/desktop/src/main.ts
@@ -1,17 +1,39 @@
// Electron shell for Doughmination Music. Replaces the old Tauri/Rust shell:
-// a single window pointed at the live web player, plus the two things a plain
+// a single window pointed at the live web player, plus the few things a plain
// browser tab can't do —
// * catch the doughmination://auth/callback deep link from the SSO round trip
+// * catch the doughmination://lastfm/callback deep link (Last.fm connect runs
+// in the system browser too — see routes/lastfm.ts)
// * push Discord Rich Presence (see discord.ts)
+// * pull app updates from GitHub Releases (electron-updater)
// Everything else (library, queue, playback, UI) is the web app, unchanged.
-import { app, BrowserWindow, Menu, shell, ipcMain, type MenuItemConstructorOptions } from "electron";
+import {
+ app,
+ BrowserWindow,
+ Menu,
+ shell,
+ ipcMain,
+ dialog,
+ type MenuItemConstructorOptions,
+} from "electron";
import { join } from "node:path";
+// CJS module with no default export; `autoUpdater` is a lazy getter that
+// builds the platform updater on first access, so it's only read inside
+// setupAutoUpdate() (after app is ready), never at module load.
+import * as electronUpdater from "electron-updater";
import { registerIpc } from "./ipc";
import { getServerUrl, setServerUrl } from "./settings";
const isDev = !app.isPackaged;
+const isMac = process.platform === "darwin";
+
+// Bundled into app.asar/build/ via electron-builder `files` (see
+// electron-builder.yml). __dirname is app.asar/dist at runtime, and
+// apps/desktop/dist in dev — both resolve one level up into build/.
+const WINDOW_ICON = join(__dirname, "..", "build", process.platform === "win32" ? "icon.ico" : "icon.png");
+
let win: BrowserWindow | null = null;
// Deep links that arrive before the window/page is ready are queued and
@@ -52,8 +74,9 @@ if (!app.requestSingleInstanceLock()) {
app.whenReady().then(() => {
app.setAsDefaultProtocolClient("doughmination");
registerIpc();
- buildMenu();
+ setupMenu();
createWindow();
+ setupAutoUpdate();
// Windows/Linux: the deep link may be in this very process's argv (app
// launched by the browser handing off the callback URL).
@@ -66,7 +89,7 @@ if (!app.requestSingleInstanceLock()) {
});
app.on("window-all-closed", () => {
- if (process.platform !== "darwin") app.quit();
+ if (!isMac) app.quit();
});
}
@@ -77,7 +100,11 @@ function createWindow(): void {
minWidth: 720,
minHeight: 480,
title: "Doughmination Music",
+ icon: WINDOW_ICON,
backgroundColor: "#0a0b10",
+ // No native menu bar on Windows/Linux (see setupMenu) — hide the empty
+ // strip and stop Alt from summoning it.
+ autoHideMenuBar: !isMac,
webPreferences: {
preload: join(__dirname, "preload.js"),
contextIsolation: true,
@@ -86,11 +113,31 @@ function createWindow(): void {
},
});
- // Outbound links (and the SSO "open in your browser" click) leave the app.
+ // The window only ever shows the player's own origin. Anything else — an
+ // outbound link, the SSO "open in your browser" hop, Last.fm's auth page —
+ // goes to the system browser instead of navigating the app away. Origin is
+ // read fresh each call so it stays right after "Set Server URL…".
+ const routeExternal = (url: string): boolean => {
+ if (!/^https?:\/\//i.test(url)) return false;
+ if (originOf(url) === originOf(getServerUrl())) return false;
+ void shell.openExternal(url);
+ return true;
+ };
+
win.webContents.setWindowOpenHandler(({ url }) => {
- if (/^https?:\/\//i.test(url)) shell.openExternal(url);
+ if (/^https?:\/\//i.test(url)) void shell.openExternal(url);
return { action: "deny" };
});
+ win.webContents.on("will-navigate", (event, url) => {
+ if (routeExternal(url)) event.preventDefault();
+ });
+ win.webContents.on("will-redirect", (event, url) => {
+ if (routeExternal(url)) event.preventDefault();
+ });
+
+ // With no menu on Windows/Linux there are no accelerators, so wire the
+ // handful of shortcuts people expect straight to the webContents.
+ if (!isMac) win.webContents.on("before-input-event", handleShortcut);
win.webContents.on("did-finish-load", () => {
pageReady = true;
@@ -105,34 +152,81 @@ function createWindow(): void {
void win.loadURL(getServerUrl());
}
-function buildMenu(): void {
+function originOf(url: string): string {
+ try {
+ return new URL(url).origin;
+ } catch {
+ return "";
+ }
+}
+
+// --- keyboard shortcuts (Windows/Linux, menu-less) ------------------------
+
+function handleShortcut(
+ event: Electron.Event,
+ input: Electron.Input,
+): void {
+ if (input.type !== "keyDown" || !win) return;
+ const ctrl = input.control || input.meta;
+ const key = input.key.toLowerCase();
+
+ const reload = () => {
+ event.preventDefault();
+ win!.webContents.reload();
+ };
+
+ if (key === "f5") return reload();
+ if (ctrl && key === "r") {
+ event.preventDefault();
+ if (input.shift) win.webContents.reloadIgnoringCache();
+ else win.webContents.reload();
+ return;
+ }
+ if (isDev && (key === "f12" || (ctrl && input.shift && key === "i"))) {
+ event.preventDefault();
+ win.webContents.toggleDevTools();
+ return;
+ }
+ if (ctrl && input.alt && key === "s") {
+ event.preventDefault();
+ void promptServerUrl();
+ }
+}
+
+// --- menu ----------------------------------------------------------------
+
+function setupMenu(): void {
+ // Windows/Linux: no application menu at all (the "File / View / Window"
+ // strip). macOS keeps one because the platform genuinely needs it (Cmd+Q,
+ // Cmd+C/V, Hide, the Services menu, …).
+ if (!isMac) {
+ Menu.setApplicationMenu(null);
+ return;
+ }
+
const template: MenuItemConstructorOptions[] = [
- ...(process.platform === "darwin"
- ? [{ role: "appMenu" as const }]
- : []),
+ { role: "appMenu" },
{
label: "File",
submenu: [
- {
- label: "Set Server URL…",
- click: () => void promptServerUrl(),
- },
- { type: "separator" as const },
- { role: "quit" as const },
+ { label: "Set Server URL…", click: () => void promptServerUrl() },
+ { type: "separator" },
+ { role: "close" },
],
},
+ { role: "editMenu" },
{
label: "View",
submenu: [
- { role: "reload" as const },
- { role: "forceReload" as const },
+ { role: "reload" },
+ { role: "forceReload" },
...(isDev ? [{ role: "toggleDevTools" as const }] : []),
- { type: "separator" as const },
- { role: "resetZoom" as const },
- { role: "zoomIn" as const },
- { role: "zoomOut" as const },
- { type: "separator" as const },
- { role: "togglefullscreen" as const },
+ { type: "separator" },
+ { role: "resetZoom" },
+ { role: "zoomIn" },
+ { role: "zoomOut" },
+ { type: "separator" },
+ { role: "togglefullscreen" },
],
},
{ role: "windowMenu" },
@@ -140,6 +234,45 @@ function buildMenu(): void {
Menu.setApplicationMenu(Menu.buildFromTemplate(template));
}
+// --- auto-update -------------------------------------------------------------
+// Pulls from the GitHub Releases feed configured in electron-builder.yml
+// (`publish`). Silent download, then a prompt to restart. Unsigned macOS
+// builds can't self-update (Squirrel.Mac requires a signature) — the check
+// just no-ops there.
+
+function setupAutoUpdate(): void {
+ if (isDev) return;
+
+ const { autoUpdater } = electronUpdater;
+ autoUpdater.autoDownload = true;
+ autoUpdater.autoInstallOnAppQuit = true;
+
+ autoUpdater.on("update-downloaded", (info) => {
+ if (!win) return;
+ void dialog
+ .showMessageBox(win, {
+ type: "info",
+ buttons: ["Restart now", "Later"],
+ defaultId: 0,
+ cancelId: 1,
+ title: "Update ready",
+ message: `Doughmination Music ${info.version} is ready to install.`,
+ detail: "Restart the app to finish updating.",
+ })
+ .then(({ response }) => {
+ if (response === 0) autoUpdater.quitAndInstall();
+ });
+ });
+
+ autoUpdater.on("error", (err) => {
+ console.error("auto-update failed:", err);
+ });
+
+ const check = () => autoUpdater.checkForUpdates().catch(() => {});
+ void check();
+ setInterval(check, 6 * 60 * 60 * 1000); // re-check every 6h
+}
+
// Tiny modal input window — Electron's dialog has no text field, so this is
// our own ~1-screen HTML form. It's local content, so nodeIntegration here is
// safe (unlike the remote page the main window loads).
diff --git a/bun.lock b/bun.lock
index c2794be..d626f9b 100644
--- a/bun.lock
+++ b/bun.lock
@@ -15,9 +15,10 @@
},
"apps/desktop": {
"name": "@musicapp/desktop",
- "version": "1.0.0",
+ "version": "3.0.0",
"dependencies": {
"@xhayper/discord-rpc": "^1.2.1",
+ "electron-updater": "^6.3.9",
},
"devDependencies": {
"@types/node": "^22.10.0",
@@ -395,6 +396,8 @@
"electron-publish": ["[email protected]", "", { "dependencies": { "@types/fs-extra": "^9.0.11", "builder-util": "25.1.7", "builder-util-runtime": "9.2.10", "chalk": "^4.1.2", "fs-extra": "^10.1.0", "lazy-val": "^1.0.5", "mime": "^2.5.2" } }, "sha512-+jbTkR9m39eDBMP4gfbqglDd6UvBC7RLh5Y0MhFSsc6UkGHj9Vj9TWobxevHYMMqmoujL11ZLjfPpMX+Pt6YEg=="],
+ "electron-updater": ["[email protected]", "", { "dependencies": { "builder-util-runtime": "9.7.0", "fs-extra": "^10.1.0", "js-yaml": "^4.1.0", "lazy-val": "^1.0.5", "lodash.escaperegexp": "^4.1.2", "lodash.isequal": "^4.5.0", "semver": "~7.7.3", "tiny-typed-emitter": "^2.1.0" } }, "sha512-ZhVxM9iGONUpZGI1FxdMRgJjUFXi7AYGVa5PwKlO1tV1/4zDxQmfKpXOHVztKrd6L9rLcFjERvi1Mf2vxyTkig=="],
+
"emoji-regex": ["[email protected]", "", {}, "sha512-toUI84YS5YmxW219erniWD0CIVOo46xGKColeNQRgOzDorgBi1v4D71/OFzgD9GO2UGKIv1C3Sp8DAn0+j5w7A=="],
"encoding": ["[email protected]", "", { "dependencies": { "iconv-lite": "^0.6.2" } }, "sha512-ETBauow1T35Y/WZMkio9jiM0Z5xjHHmJ4XmjZOq1l/dXz3lr2sRn87nJy20RupqSh1F2m3HHPSp8ShIPQJrJ3A=="],
@@ -565,8 +568,12 @@
"lodash.difference": ["[email protected]", "", {}, "sha512-dS2j+W26TQ7taQBGN8Lbbq04ssV3emRw4NY58WErlTO29pIqS0HmoT5aJ9+TUQ1N3G+JOZSji4eugsWwGp9yPA=="],
+ "lodash.escaperegexp": ["[email protected]", "", {}, "sha512-TM9YBvyC84ZxE3rgfefxUWiQKLilstD6k7PTGt6wfbtXF8ixIJLOL3VYyV/z+ZiPLsVxAsKAFVwWlWeb2Y8Yyw=="],
+
"lodash.flatten": ["[email protected]", "", {}, "sha512-C5N2Z3DgnnKr0LOpv/hKCgKdb7ZZwafIrsesve6lmzvZIRZRGaZ/l6Q8+2W7NaT+ZwO3fFlSCzCzrDCFdJfZ4g=="],
+ "lodash.isequal": ["[email protected]", "", {}, "sha512-pDo3lu8Jhfjqls6GkMgpahsF9kCyayhgykjyLMNFTKWrpVdAQtYyB4muAMWozBB4ig/dtWAmsMxLEI8wuz+DYQ=="],
+
"lodash.isplainobject": ["[email protected]", "", {}, "sha512-oSXzaWypCMHkPC3NvBEaPHf0KsA5mvPrOPgQWDsbg8n7orZ290M0BmC/jgRZ4vcJ6DTAhjrsSYgdsW/F+MFOBA=="],
"lodash.union": ["[email protected]", "", {}, "sha512-c4pB2CdGrGdjMKYLA+XiRDO7Y0PRQbm/Gzg8qMj+QH+pFVAoTp5sBpO0odL3FjoPCGjK96p6qsP+yQoiLoOBcw=="],
@@ -719,7 +726,7 @@
"sax": ["[email protected]", "", {}, "sha512-42tBVwLWnaQvW5zc4HbZrTuWccECCZfBi92FDuwtqxasH+JbPB3/FOKb1m222K42R4WxuxzzMsTswfzgtSu64Q=="],
- "semver": ["[email protected]", "", { "bin": { "semver": "bin/semver.js" } }, "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA=="],
+ "semver": ["[email protected]", "", { "bin": { "semver": "bin/semver.js" } }, "sha512-vFKC2IEtQnVhpT78h1Yp8wzwrf8CM+MzKMHGJZfBtzhZNycRFnXsHk6E5TxIkkMsgNS7mdX3AGB7x2QM2di4lA=="],
"semver-compare": ["[email protected]", "", {}, "sha512-YM3/ITh2MJ5MtzaM429anh+x2jiLVjqILF4m4oyQB18W7Ggea7BfqdH/wGMK7dDiMghv/6WG7znWMwUDzJiXow=="],
@@ -779,6 +786,8 @@
"temp-file": ["[email protected]", "", { "dependencies": { "async-exit-hook": "^2.0.1", "fs-extra": "^10.0.0" } }, "sha512-C5tjlC/HCtVUOi3KWVokd4vHVViOmGjtLwIh4MuzPo/nMYTV/p1urt3RnMz2IWXDdKEGJH3k5+KPxtqRsUYGtg=="],
+ "tiny-typed-emitter": ["[email protected]", "", {}, "sha512-qVtvMxeXbVej0cQWKqVSSAHmKZEHAvxdF8HEUBFWts8h+xEo5m/lEiPakuyZ3BnCBjOD8i24kzNOiOLLgsSxhA=="],
+
"tmp": ["[email protected]", "", {}, "sha512-e0votIpp4Uo2AJYSzVHV6xCcawuiez3DzqDAbrTc3YxBkplN6e+dM13ZeIcZnDg/QpSuU2zfZ3rzwY8ukEnaXw=="],
"tmp-promise": ["[email protected]", "", { "dependencies": { "tmp": "^0.2.0" } }, "sha512-RwM7MoPojPxsOBYnyd2hy0bxtIlVrihNs9pj5SUvY8Zz1sQcQG2tG1hSr8PDxfgEB8RNKDhqbIlroIarSNDNsQ=="],
@@ -857,6 +866,8 @@
"@electron/get/fs-extra": ["[email protected]", "", { "dependencies": { "graceful-fs": "^4.2.0", "jsonfile": "^4.0.0", "universalify": "^0.1.0" } }, "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g=="],
+ "@electron/get/semver": ["[email protected]", "", { "bin": { "semver": "bin/semver.js" } }, "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA=="],
+
"@electron/notarize/fs-extra": ["[email protected]", "", { "dependencies": { "at-least-node": "^1.0.0", "graceful-fs": "^4.2.0", "jsonfile": "^6.0.1", "universalify": "^2.0.0" } }, "sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ=="],
"@electron/osx-sign/isbinaryfile": ["[email protected]", "", {}, "sha512-iHrqe5shvBUcFbmZq9zOQHBoeOhZJu6RQGrDpBgenUm/Am+F3JM2MgQj+rK3Z601fzrL5gLZWtAPH2OBaSVcyw=="],
@@ -923,6 +934,8 @@
"electron-publish/chalk": ["[email protected]", "", { "dependencies": { "ansi-styles": "^4.1.0", "supports-color": "^7.1.0" } }, "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA=="],
+ "electron-updater/builder-util-runtime": ["[email protected]", "", { "dependencies": { "debug": "^4.3.4", "sax": "^1.2.4" } }, "sha512-g/kR520giAFYkSXTzcmF3kqQq7wi8F6N6SzeDgZrqTBN+VHdmgWOyTdD1yD7AATDId/yXLvuP34CxW46/BwCdw=="],
+
"filelist/minimatch": ["[email protected]", "", { "dependencies": { "brace-expansion": "^2.0.1" } }, "sha512-7o1wEA2RyMP7Iu7GNba9vc0RWWGACJOCZBJX2GJWip0ikV+wcOsgVuY9uE8CPiyQhkGFSlhuSkZPavN7u1c2Fw=="],
"fs-minipass/minipass": ["[email protected]", "", { "dependencies": { "yallist": "^4.0.0" } }, "sha512-DxiNidxSEK+tHG6zOIklvNOwm3hvCrbUrdtzY74U6HKTJxvIDfOUL5W5P2Ghd3DTkhhKPYGqeNUIh5qcM4YBfw=="],
diff --git a/web/client/src/app.ts b/web/client/src/app.ts
index b022ce1..9624ebc 100644
--- a/web/client/src/app.ts
+++ b/web/client/src/app.ts
@@ -23,6 +23,8 @@ import {
initDesktopBridge,
initDesktopAuth,
startDesktopLogin,
+ startDesktopLastfmConnect,
+ onLastfmConnect,
clearDesktopToken,
isDesktop,
openExternal,
@@ -400,7 +402,9 @@ async function refreshAdminCounts(): Promise<void> {
function render(): void {
root.innerHTML = `
<button class="hamburger" id="hamburger" aria-label="Menu"><i class="bi bi-list"></i></button>
- <img class="app-logo-corner" src="/favicon.png" alt="Doughmination Music" />
+ <button class="app-logo-corner" id="logo-home" aria-label="Home" title="Home">
+ <img src="/favicon.png" alt="Doughmination Music" />
+ </button>
<div class="layout">
<aside class="sidebar" id="sidebar"></aside>
<div class="scrim" id="scrim"></div>
@@ -445,6 +449,11 @@ function render(): void {
sidebar
?.querySelectorAll("[data-view],[data-playlist],#upload-btn")
.forEach((b) => b.addEventListener("click", closeDrawer));
+
+ document.getElementById("logo-home")?.addEventListener("click", () => {
+ closeDrawer();
+ navigate({ kind: "library" });
+ });
}
// Web navigates the same tab straight to the login route (cookie flow).
@@ -517,7 +526,9 @@ function renderSidebar(): void {
</button>`;
el.innerHTML = `
- <div class="brand"><img class="brand-logo" src="/favicon.png" alt="" /> Doughmination Music</div>
+ <button class="brand" id="brand-home" title="Home">
+ <img class="brand-logo" src="/favicon.png" alt="" /> Doughmination Music
+ </button>
${nav("library", "Library")}
${state.me ? nav("liked", `<i class="bi bi-heart-fill"></i> Liked Songs`) : ""}
${
@@ -582,6 +593,7 @@ function renderSidebar(): void {
});
});
+ document.getElementById("brand-home")?.addEventListener("click", () => navigate({ kind: "library" }));
document.getElementById("upload-btn")?.addEventListener("click", openUploadModal);
wireSignIn("sidebar-signin");
@@ -2194,13 +2206,36 @@ async function renderSettings(el: HTMLElement): Promise<void> {
`
: `
<p>Connect your Last.fm account to scrobble what you play here.</p>
- <a class="btn btn-primary" href="${api.lastfmConnectUrl()}">Connect Last.fm</a>
+ ${
+ isDesktop
+ ? `<button class="btn btn-primary" id="lastfm-connect">Connect Last.fm</button>`
+ : `<a class="btn btn-primary" href="${api.lastfmConnectUrl()}">Connect Last.fm</a>`
+ }
`
}
<span id="lastfm-status" class="upload-status"></span>
</section>
`;
+ // Desktop: the connect flow runs in the system browser and returns via the
+ // doughmination://lastfm/callback deep link (see desktop.ts).
+ document.getElementById("lastfm-connect")?.addEventListener("click", () => {
+ const s = document.getElementById("lastfm-status");
+ if (s) s.textContent = "Opening Last.fm in your browser…";
+ onLastfmConnect((r) => {
+ if (r.ok) {
+ flash("Last.fm connected.");
+ if (state.view.kind === "settings") void renderSettings(el);
+ } else {
+ flash("Couldn't connect Last.fm. Try again?");
+ if (s) s.textContent = "";
+ }
+ });
+ if (!startDesktopLastfmConnect(api.lastfmConnectUrl(true)) && s) {
+ s.textContent = "Couldn't open the browser.";
+ }
+ });
+
document.getElementById("lastfm-disconnect")?.addEventListener("click", async () => {
const s = document.getElementById("lastfm-status");
try {
diff --git a/web/client/src/desktop.ts b/web/client/src/desktop.ts
index eb78d0f..7cefbd1 100644
--- a/web/client/src/desktop.ts
+++ b/web/client/src/desktop.ts
@@ -9,6 +9,7 @@
// Tauri local-bundle build needed.
import {
+ api,
configureAuthToken,
startNativeLogin,
completeNativeLogin,
@@ -71,6 +72,27 @@ export function openExternal(url: string): boolean {
return true;
}
+<<<<<<< Updated upstream
+=======
+// Last.fm connect on desktop runs entirely in the system browser (same reason
+// as SSO — no passkeys / wrong cookie jar in the webview). It returns via
+// doughmination://lastfm/callback?token=… which initDesktopAuth catches and
+// routes to this handler.
+type LastfmResult = { ok: true; username?: string } | { ok: false };
+let lastfmHandler: ((r: LastfmResult) => void) | null = null;
+
+export function onLastfmConnect(cb: (r: LastfmResult) => void): void {
+ lastfmHandler = cb;
+}
+
+// Kick off Last.fm's auth page in the system browser.
+export function startDesktopLastfmConnect(connectUrl: string): boolean {
+ if (!bridge) return false;
+ void bridge.openExternal(connectUrl);
+ return true;
+}
+
+>>>>>>> Stashed changes
// True once a token is stored — lets the UI skip a re-auth on boot.
export function hasDesktopToken(): boolean {
try {
@@ -110,12 +132,33 @@ export async function initDesktopAuth(onLoggedIn: () => void): Promise<void> {
}
bridge.onDeepLink(async (raw) => {
- let code: string | null = null;
+ let link: URL | null = null;
try {
- code = new URL(raw).searchParams.get("code");
+ link = new URL(raw);
} catch {
/* not a URL we care about */
}
+ if (!link) return;
+
+ // doughmination://lastfm/callback?token=… — finish a Last.fm connect that
+ // ran in the system browser.
+ if (link.host === "lastfm") {
+ const token = link.searchParams.get("token");
+ if (!token || link.searchParams.get("error")) {
+ lastfmHandler?.({ ok: false });
+ return;
+ }
+ try {
+ const res = await api.lastfmNativeComplete(token);
+ lastfmHandler?.({ ok: true, username: res.username });
+ } catch (err) {
+ console.error("lastfm native connect failed", err);
+ lastfmHandler?.({ ok: false });
+ }
+ return;
+ }
+
+ const code = link.searchParams.get("code");
if (!code) return;
let verifier = "";
diff --git a/web/client/src/styles.css b/web/client/src/styles.css
index bee4e4c..fbae8c9 100644
--- a/web/client/src/styles.css
+++ b/web/client/src/styles.css
@@ -50,6 +50,8 @@
* {
box-sizing: border-box;
+ scrollbar-width: thin;
+ scrollbar-color: var(--panel-2) transparent;
}
body {
@@ -60,6 +62,39 @@ body {
overflow-x: hidden;
}
+/* --- scrollbars + selection: match the dark palette instead of the OS default
+ (the pale native scrollbar and blue highlight look broken on this bg,
+ especially in the Electron shell). `scrollbar-*` for Firefox lives on the
+ `*` rule above. --- */
+
+::-webkit-scrollbar {
+ width: 12px;
+ height: 12px;
+}
+
+::-webkit-scrollbar-track {
+ background: var(--bg);
+}
+
+::-webkit-scrollbar-thumb {
+ background: var(--panel-2);
+ border: 3px solid var(--bg);
+ border-radius: 8px;
+}
+
+::-webkit-scrollbar-thumb:hover {
+ background: #2b3040;
+}
+
+::-webkit-scrollbar-corner {
+ background: var(--bg);
+}
+
+::selection {
+ background: var(--accent);
+ color: var(--bg);
+}
+
button {
font: inherit;
cursor: pointer;
@@ -1515,10 +1550,23 @@ button {
/* --- app icon / brand --- */
+/* Both brand marks are <button>s that navigate home — strip the native
+ chrome. The sidebar `.brand` rule above still sets the type scale (font
+ size / weight / margin), so don't reset `font` here. */
.brand {
display: flex;
align-items: center;
gap: 0.5rem;
+ width: 100%;
+ background: none;
+ border: none;
+ padding: 0;
+ color: inherit;
+ text-align: left;
+}
+
+.brand:hover {
+ color: var(--accent);
}
.brand-logo {
@@ -1537,10 +1585,19 @@ button {
right: 0.9rem;
width: 2rem;
height: 2rem;
- border-radius: 8px;
+ padding: 0;
+ border: none;
+ background: none;
z-index: 46;
}
+.app-logo-corner img {
+ width: 100%;
+ height: 100%;
+ border-radius: 8px;
+ display: block;
+}
+
@media (max-width: 768px) {
.app-logo-corner {
display: block;
diff --git a/web/server/src/routes/lastfm.ts b/web/server/src/routes/lastfm.ts
index f443e8f..6ff4004 100644
--- a/web/server/src/routes/lastfm.ts
+++ b/web/server/src/routes/lastfm.ts
@@ -7,6 +7,37 @@ import * as lastfm from "../lib/lastfm.ts";
export const lastfmRoutes = new Hono<AppEnv>();
+// --- unauthenticated: the desktop "connect in the system browser" hops ------
+// The system browser has no session, so these two can't sit behind
+// requireAuth. Neither touches user data: /connect only builds the Last.fm
+// redirect, and /native-callback only bounces the returned token back into
+// the app via the doughmination:// deep link. The app then finishes the
+// exchange with an authenticated POST /native-complete.
+
+lastfmRoutes.get("/connect", (c) => {
+ if (!lastfm.isConfigured()) {
+ return c.json({ error: "lastfm_not_configured" }, 400);
+ }
+ const native = c.req.query("native") != null;
+ const callbackUrl = `${config.appUrl}/api/lastfm/${native ? "native-callback" : "callback"}`;
+ return c.redirect(lastfm.getAuthUrl(callbackUrl));
+});
+
+lastfmRoutes.get("/native-callback", (c) => {
+ const token = c.req.query("token");
+ const target = token
+ ? `doughmination://lastfm/callback?token=${encodeURIComponent(token)}`
+ : `doughmination://lastfm/callback?error=1`;
+ const esc = target.replace(/"/g, """);
+ return c.html(
+ `<!doctype html><html><head><meta charset="utf-8"><title>Last.fm</title>
+<meta http-equiv="refresh" content="0;url=${esc}">
+<style>body{font:14px system-ui,sans-serif;background:#0a0b10;color:#f4f6fb;
+display:grid;place-items:center;height:100vh;margin:0}a{color:#f5a9b8}</style>
+</head><body><p>Returning to Doughmination Music… <a href="${esc}">continue</a></p></body></html>`,
+ );
+});
+
lastfmRoutes.use("*", requireAuth);
lastfmRoutes.get("/status", (c) => {
@@ -18,17 +49,10 @@ lastfmRoutes.get("/status", (c) => {
});
});
-// Kicks off Last.fm's "Web Application" auth flow: redirect the browser to
-// Last.fm with our callback URL, the user approves there, Last.fm redirects
-// back to /callback with a token we exchange for a session key.
-lastfmRoutes.get("/connect", (c) => {
- if (!lastfm.isConfigured()) {
- return c.json({ error: "lastfm_not_configured" }, 400);
- }
- const callbackUrl = `${config.appUrl}/api/lastfm/callback`;
- return c.redirect(lastfm.getAuthUrl(callbackUrl));
-});
-
+// The web flow's return leg: the browser still has the session cookie, so we
+// exchange the token and attach the session key right here, then redirect
+// back into the app. (The /connect that kicks this off is registered above,
+// unauthenticated.)
lastfmRoutes.get("/callback", async (c) => {
const user = c.get("user")!;
const token = c.req.query("token");
@@ -49,6 +73,32 @@ lastfmRoutes.get("/callback", async (c) => {
}
});
+// The desktop flow's return leg: /native-callback bounced the Last.fm token
+// back through the doughmination:// deep link, and the app POSTs it here with
+// its bearer token so we know which user to bind the session key to.
+lastfmRoutes.post("/native-complete", async (c) => {
+ const user = c.get("user")!;
+ const body = await c.req
+ .json<{ token?: string }>()
+ .catch(() => ({}) as { token?: string });
+ const token = typeof body.token === "string" ? body.token.trim() : "";
+ if (!token) return c.json({ error: "token_required" }, 400);
+
+ try {
+ const session = await lastfm.getSession(token);
+ await sql`
+ UPDATE users
+ SET lastfm_session_key = ${session.key},
+ lastfm_username = ${session.username}
+ WHERE id = ${user.id}
+ `;
+ return c.json({ ok: true, username: session.username });
+ } catch (err) {
+ console.error("lastfm: native connect failed:", err);
+ return c.json({ error: "lastfm_connect_failed" }, 502);
+ }
+});
+
lastfmRoutes.post("/disconnect", async (c) => {
const user = c.get("user")!;
await sql`
diff --git a/web/shared/src/api-client.ts b/web/shared/src/api-client.ts
index ff5c285..e5bd37b 100644
--- a/web/shared/src/api-client.ts
+++ b/web/shared/src/api-client.ts
@@ -428,9 +428,22 @@ export const api = {
},
// Not fetched — Last.fm's own auth page needs a real browser navigation,
- // not an XHR/fetch redirect.
- lastfmConnectUrl(): string {
- return url("/api/lastfm/connect");
+ // not an XHR/fetch redirect. `native` routes the return leg back through the
+ // doughmination:// deep link (desktop: the whole flow runs in the system
+ // browser, which has no session) instead of the cookie-authenticated
+ // /callback.
+ lastfmConnectUrl(native = false): string {
+ return url(`/api/lastfm/connect${native ? "?native=1" : ""}`);
+ },
+
+ // Desktop only: finish a native connect by handing the Last.fm token the
+ // deep link carried back to an authenticated endpoint.
+ lastfmNativeComplete(token: string): Promise<{ ok: boolean; username: string }> {
+ return fetch(url("/api/lastfm/native-complete"), {
+ method: "POST",
+ headers: { "content-type": "application/json" },
+ body: JSON.stringify({ token }),
+ }).then(json<{ ok: boolean; username: string }>);
},
lastfmDisconnect(): Promise<Response> {