mirror of
https://github.com/MrPatben8/konduktor.git
synced 2026-11-27 18:22:53 +01:00
Implemented update checking
This commit is contained in:
1 parent
f19a662bd3
commit
ed2b72c749
8 files changed
+254
-6
No files matched your search
@@ -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<N>` 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<version>-b<run_number>` (release name `Konduktor v<version>-b<run_number>`).
|
||||
|
||||
Generated
+12
-3
@@ -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",
|
||||
|
||||
@@ -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"
|
||||
},
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
"main"
|
||||
],
|
||||
"permissions": [
|
||||
"core:default"
|
||||
"core:default",
|
||||
"shell:allow-open"
|
||||
]
|
||||
}
|
||||
@@ -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<version>-b<N>` — 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<GithubRelease> {
|
||||
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 <PR url>" 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 <span key={i}>{part}</span>
|
||||
const pr = /\/pull\/(\d+)/.exec(part)
|
||||
return (
|
||||
<a
|
||||
key={i}
|
||||
href={part}
|
||||
onClick={(e) => {
|
||||
e.preventDefault()
|
||||
openExternal(part)
|
||||
}}
|
||||
className="text-accent hover:underline"
|
||||
>
|
||||
{pr ? `#${pr[1]}` : part}
|
||||
</a>
|
||||
)
|
||||
})}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
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 (
|
||||
<div
|
||||
className="fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-6"
|
||||
onClick={close}
|
||||
>
|
||||
<div
|
||||
className="flex max-h-[80vh] w-full max-w-md flex-col overflow-hidden rounded-xl border border-line bg-ink-900 shadow-2xl"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<div className="border-b border-line px-5 py-4">
|
||||
<div className="text-[15px] font-semibold tracking-tight">Update available</div>
|
||||
<div className="text-xs text-muted">
|
||||
Konduktor <span className="text-accent">{latest.tag_name}</span> is out — you have v
|
||||
{__APP_VERSION__}.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="min-h-0 flex-1 overflow-y-auto px-5 py-4">
|
||||
<div className="mb-2 text-xs font-medium text-muted">What's changed</div>
|
||||
{changes.length ? (
|
||||
<ul className="space-y-1.5">
|
||||
{changes.map((line, i) => (
|
||||
<li key={i} className="flex gap-2 text-sm text-text">
|
||||
<span className="text-faint">•</span>
|
||||
<span className="min-w-0 break-words">
|
||||
<ChangelogLine text={line} />
|
||||
</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
) : (
|
||||
<div className="text-sm text-faint">No release notes.</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-3 border-t border-line px-5 py-3">
|
||||
<label className="flex cursor-pointer items-center gap-2 text-xs text-muted">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={skipVersion}
|
||||
onChange={(e) => setSkipVersion(e.target.checked)}
|
||||
className="accent-accent"
|
||||
/>
|
||||
Skip this version
|
||||
</label>
|
||||
<div className="flex-1" />
|
||||
<button
|
||||
onClick={close}
|
||||
className="rounded-md px-3 py-1.5 text-sm text-muted hover:bg-ink-800 hover:text-text"
|
||||
>
|
||||
Skip
|
||||
</button>
|
||||
<button
|
||||
onClick={download}
|
||||
className="rounded-md bg-accent px-3 py-1.5 text-sm font-medium text-ink-950 hover:brightness-110"
|
||||
>
|
||||
Download
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -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(
|
||||
<StrictMode>
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<App />
|
||||
{/* Mounted beside App so the update dialog shows even on the picker screen. */}
|
||||
<UpdateCheck />
|
||||
</QueryClientProvider>
|
||||
</StrictMode>,
|
||||
)
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
/// <reference types="vite/client" />
|
||||
|
||||
/** The app version from package.json, injected by vite.config.ts `define`. */
|
||||
declare const __APP_VERSION__: string
|
||||
@@ -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: {
|
||||
|
||||
Reference in new issue
Block a user