diff --git a/CLAUDE.md b/CLAUDE.md index fa98879..743f934 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -64,7 +64,15 @@ Two independent apps that talk over HTTP: state every commit → infinite re-render loop. Keep that reference stable. `SelectionBar` (bulk add-to-playlist), `ContextMenu` + `EditTagsDialog` (right-click → multi-field metadata + album-art edit), `StatusBar`, - `RatingStars` (read-only, or click-to-set when given `onChange`), `Toast`. + `RatingStars` (read-only, or click-to-set when given `onChange`), `Toast`, + `UpdateDialog` (`UpdateCheck`, mounted in `main.tsx` beside `App` so it shows + even on the picker screen: on startup fetches the latest GitHub release and, + if its tag's **semver part** is newer than `__APP_VERSION__` — build-number + `-b` bumps don't count — shows an update dialog with the release's + "What's Changed" bullets; Download opens the release page in the system + browser via `@tauri-apps/plugin-shell` `open` — falls back to `window.open` + outside Tauri; "Skip this version" persists `skippedUpdateVersion` to + userprefs via `/api/prefs`; all failures are silent). - **Prep strip** (DJ deck across the top of the window): `PrepStrip` owns it — transport (play/pause, CUE), two waveforms (`MainWaveform` scrolling+zoomable — its zoom is owned by `PrepStrip` so it survives track switches and persists, @@ -171,6 +179,9 @@ that number and nothing else — everything derives from it: the PyInstaller root via `sys._MEIPASS`, added in `konduktor-sidecar.spec`). `main.py` uses this for the FastAPI `version`. Falls back to `"0.0.0"` if not found (cosmetic, must never crash startup). +- **Frontend / update check** — `vite.config.ts` bakes it in at build time as + the `__APP_VERSION__` global (declared in `src/vite-env.d.ts`); `UpdateCheck` + compares it against the latest GitHub release tag on startup. - **CI release** — `.github/workflows/build.yml` reads it with `jq .version frontend/package.json` and tags each push `v-b` (release name `Konduktor v-b`). diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 34f1ba3..0ea190b 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -1,12 +1,12 @@ { "name": "frontend", - "version": "0.0.0", + "version": "0.1.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "frontend", - "version": "0.0.0", + "version": "0.1.1", "dependencies": { "@dnd-kit/core": "^6.3.1", "@dnd-kit/modifiers": "^9.0.0", @@ -15,6 +15,7 @@ "@tanstack/react-query": "^5.101.2", "@tanstack/react-table": "^8.21.3", "@tanstack/react-virtual": "^3.14.5", + "@tauri-apps/plugin-shell": "^2.3.5", "react": "^19.2.7", "react-dom": "^19.2.7" }, @@ -1229,7 +1230,6 @@ "version": "2.11.1", "resolved": "https://registry.npmjs.org/@tauri-apps/api/-/api-2.11.1.tgz", "integrity": "sha512-M2FPuYND2m+wh5hfW9ZpSdxMPdEJovPBWwoHJmwUpysTYNHaOkVFN419m/K0LIgjb/7KU2vBgsUepJWugQCvAA==", - "dev": true, "license": "Apache-2.0 OR MIT", "funding": { "type": "opencollective", @@ -1468,6 +1468,15 @@ "node": ">= 10" } }, + "node_modules/@tauri-apps/plugin-shell": { + "version": "2.3.5", + "resolved": "https://registry.npmjs.org/@tauri-apps/plugin-shell/-/plugin-shell-2.3.5.tgz", + "integrity": "sha512-jewtULhiQ7lI7+owCKAjc8tYLJr92U16bPOeAa472LHJdgaibLP83NcfAF2e+wkEcA53FxKQAZ7byDzs2eeizg==", + "license": "MIT OR Apache-2.0", + "dependencies": { + "@tauri-apps/api": "^2.10.1" + } + }, "node_modules/@tybys/wasm-util": { "version": "0.10.3", "resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.10.3.tgz", diff --git a/frontend/package.json b/frontend/package.json index 6a56ba6..4163b5c 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,7 +1,7 @@ { "name": "frontend", "private": true, - "version": "0.1.1", + "version": "0.1.2", "type": "module", "scripts": { "dev": "vite", @@ -17,6 +17,7 @@ "@tanstack/react-query": "^5.101.2", "@tanstack/react-table": "^8.21.3", "@tanstack/react-virtual": "^3.14.5", + "@tauri-apps/plugin-shell": "^2.3.5", "react": "^19.2.7", "react-dom": "^19.2.7" }, diff --git a/frontend/src-tauri/capabilities/default.json b/frontend/src-tauri/capabilities/default.json index c135d7f..9f68e87 100644 --- a/frontend/src-tauri/capabilities/default.json +++ b/frontend/src-tauri/capabilities/default.json @@ -6,6 +6,7 @@ "main" ], "permissions": [ - "core:default" + "core:default", + "shell:allow-open" ] } diff --git a/frontend/src/components/UpdateDialog.tsx b/frontend/src/components/UpdateDialog.tsx new file mode 100644 index 0000000..97acf11 --- /dev/null +++ b/frontend/src/components/UpdateDialog.tsx @@ -0,0 +1,211 @@ +import { useState } from 'react' +import { useQuery, useQueryClient } from '@tanstack/react-query' +import { api } from '../api' + +/** + * Startup update check against GitHub Releases. + * + * Compares the running version (`__APP_VERSION__`, baked from package.json at + * build time) with the latest release's tag (`v-b` — only the + * semver part counts, so a new build of the same version is NOT an update). + * Failures are silent: an update check must never nag about itself. + * "Skip this version" persists `skippedUpdateVersion` to userprefs.json via + * the prefs API, keyed by the semver part, so a later version re-triggers. + */ + +const REPO = 'MrPatben8/konduktor' + +interface GithubRelease { + tag_name: string + html_url: string + body: string | null +} + +async function fetchLatestRelease(): Promise { + const res = await fetch(`https://api.github.com/repos/${REPO}/releases/latest`, { + headers: { Accept: 'application/vnd.github+json' }, + }) + if (!res.ok) throw new Error(`GitHub responded ${res.status}`) + return res.json() +} + +/** The semver triple at the start of a version/tag string ("v0.1.2-b7" → [0,1,2]). */ +function parseVersion(s: string): [number, number, number] | null { + const m = /^v?(\d+)\.(\d+)\.(\d+)/.exec(s.trim()) + return m ? [Number(m[1]), Number(m[2]), Number(m[3])] : null +} + +function isNewer(a: [number, number, number], b: [number, number, number]): boolean { + for (let i = 0; i < 3; i++) { + if (a[i] !== b[i]) return a[i] > b[i] + } + return false +} + +/** + * The "What's Changed" bullet lines from an auto-generated release body + * (section ends at the next heading or the Full Changelog link). If the + * section is missing (hand-written notes), fall back to the whole body. + * The auto-generated "by @user in " credit suffix is stripped. + */ +function whatsChanged(body: string | null): string[] { + if (!body) return [] + const lines = body.split(/\r?\n/) + const start = lines.findIndex((l) => /^#{2,4}\s+what'?s changed/i.test(l.trim())) + const out: string[] = [] + for (const raw of lines.slice(start + 1)) { + const line = raw.trim() + if (start !== -1 && (/^#{1,4}\s/.test(line) || line.startsWith('**Full Changelog**'))) break + if (line) { + out.push( + line.replace(/^[*-]\s+/, '').replace(/\s+by\s+@[\w-]+\s+in\s+https?:\/\/\S+$/i, ''), + ) + } + } + return out +} + +/** Open a URL in the system browser (Tauri shell-open in the desktop app). */ +async function openExternal(url: string) { + if ('__TAURI_INTERNALS__' in window) { + try { + const { open } = await import('@tauri-apps/plugin-shell') + await open(url) + return + } catch { + // fall through to window.open + } + } + window.open(url, '_blank', 'noopener') +} + +/** Render a changelog line, turning bare URLs into links (PR URLs as #N). */ +function ChangelogLine({ text }: { text: string }) { + const parts = text.split(/(https?:\/\/\S+)/g) + return ( + <> + {parts.map((part, i) => { + if (!/^https?:\/\//.test(part)) return {part} + const pr = /\/pull\/(\d+)/.exec(part) + return ( + { + e.preventDefault() + openExternal(part) + }} + className="text-accent hover:underline" + > + {pr ? `#${pr[1]}` : part} + + ) + })} + + ) +} + +export function UpdateCheck() { + const qc = useQueryClient() + const [dismissed, setDismissed] = useState(false) + const [skipVersion, setSkipVersion] = useState(false) + + const release = useQuery({ + queryKey: ['latestRelease'], + queryFn: fetchLatestRelease, + staleTime: Infinity, + retry: false, + }) + // Shares App's ['prefs'] cache entry. + const prefs = useQuery({ queryKey: ['prefs'], queryFn: api.getPrefs }) + + const latest = release.data + const latestVer = latest ? parseVersion(latest.tag_name) : null + const currentVer = parseVersion(__APP_VERSION__) + const latestSemver = latestVer?.join('.') + const updateAvailable = !!(latestVer && currentVer && isNewer(latestVer, currentVer)) + const skipped = !!latestSemver && prefs.data?.skippedUpdateVersion === latestSemver + + // Wait for prefs before showing so a skipped version never flashes the dialog. + if (dismissed || !updateAvailable || !latest || !prefs.isSuccess || skipped) return null + + const close = () => { + if (skipVersion && latestSemver) { + api + .patchPrefs({ skippedUpdateVersion: latestSemver }) + .then((p) => qc.setQueryData(['prefs'], p)) + .catch(() => {}) + } + setDismissed(true) + } + + const download = () => { + openExternal(latest.html_url) + setDismissed(true) + } + + const changes = whatsChanged(latest.body) + + return ( +
+
e.stopPropagation()} + > +
+
Update available
+
+ Konduktor {latest.tag_name} is out — you have v + {__APP_VERSION__}. +
+
+ +
+
What's changed
+ {changes.length ? ( +
    + {changes.map((line, i) => ( +
  • + • + + + +
  • + ))} +
+ ) : ( +
No release notes.
+ )} +
+ +
+ +
+ + +
+
+
+ ) +} diff --git a/frontend/src/main.tsx b/frontend/src/main.tsx index ee87744..9b01eb6 100644 --- a/frontend/src/main.tsx +++ b/frontend/src/main.tsx @@ -3,6 +3,7 @@ import { createRoot } from 'react-dom/client' import { QueryClient, QueryClientProvider } from '@tanstack/react-query' import './index.css' import App from './App.tsx' +import { UpdateCheck } from './components/UpdateDialog.tsx' const queryClient = new QueryClient({ defaultOptions: { @@ -17,6 +18,8 @@ createRoot(document.getElementById('root')!).render( + {/* Mounted beside App so the update dialog shows even on the picker screen. */} + , ) diff --git a/frontend/src/vite-env.d.ts b/frontend/src/vite-env.d.ts new file mode 100644 index 0000000..953927d --- /dev/null +++ b/frontend/src/vite-env.d.ts @@ -0,0 +1,4 @@ +/// + +/** The app version from package.json, injected by vite.config.ts `define`. */ +declare const __APP_VERSION__: string diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index 45e215c..c274c75 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -1,9 +1,17 @@ +import { readFileSync } from 'node:fs' import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' +// The app's own version, from the single source of truth (package.json), baked +// in at build time as __APP_VERSION__ (used by the startup update check). +const pkg = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8')) + // Proxy /api to the FastAPI backend so the frontend can use same-origin fetches. export default defineConfig({ plugins: [react()], + define: { + __APP_VERSION__: JSON.stringify(pkg.version), + }, server: { port: 5173, proxy: {