Skip to content

Split any YouTube song into stems

TypeScript

feat: add About StemKit menu

Daniel Ravina9b0a67bceee5
diff --git a/src/main/index.ts b/src/main/index.ts
index 72fd03d..6d3341c 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -1,4 +1,12 @@
-import { app, BrowserWindow, ipcMain, shell, dialog } from 'electron'
+import {
+ app,
+ BrowserWindow,
+ ipcMain,
+ shell,
+ dialog,
+ Menu,
+ type MenuItemConstructorOptions
+} from 'electron'
import { join, normalize, extname } from 'path'
import { existsSync, copyFileSync, mkdirSync, createReadStream, statSync } from 'fs'
import { spawn } from 'child_process'
@@ -81,6 +89,57 @@ function sanitizeName(name: string): string {
return clean.length > 0 ? clean.slice(0, 120) : 'stems'
}
+function showAboutWindow(): void {
+ if (!mainWindow) return
+ if (mainWindow.isMinimized()) mainWindow.restore()
+ mainWindow.show()
+ mainWindow.focus()
+ mainWindow.webContents.send('app:show-about')
+}
+
+function installApplicationMenu(): void {
+ const aboutItem: MenuItemConstructorOptions = {
+ label: 'About StemKit',
+ click: showAboutWindow
+ }
+ const template: MenuItemConstructorOptions[] =
+ process.platform === 'darwin'
+ ? [
+ {
+ label: app.name,
+ submenu: [
+ aboutItem,
+ { type: 'separator' },
+ { role: 'services', submenu: [] },
+ { type: 'separator' },
+ { role: 'hide' },
+ { role: 'hideOthers' },
+ { role: 'unhide' },
+ { type: 'separator' },
+ { role: 'quit' }
+ ]
+ },
+ {
+ label: 'Edit',
+ submenu: [
+ { role: 'undo' },
+ { role: 'redo' },
+ { type: 'separator' },
+ { role: 'cut' },
+ { role: 'copy' },
+ { role: 'paste' },
+ { role: 'selectAll' }
+ ]
+ },
+ { label: 'Window', submenu: [{ role: 'minimize' }, { role: 'zoom' }, { role: 'front' }] }
+ ]
+ : [
+ { label: 'File', submenu: [{ role: 'quit' }] },
+ { label: 'Help', submenu: [aboutItem] }
+ ]
+ Menu.setApplicationMenu(Menu.buildFromTemplate(template))
+}
+
function requireExportFfmpeg(): string {
const ffmpeg = getStatus().ffmpeg.path
if (!ffmpeg) {
@@ -146,6 +205,8 @@ app.whenReady().then(async () => {
return
}
+ installApplicationMenu()
+
// existing install (e.g. right after an update): pre-fetch the engine
// checkpoints the user opted into, in the background, so the first split
// doesn't stall on a download. Nothing is fetched while both toggles are
@@ -292,9 +353,18 @@ app.whenReady().then(async () => {
initUpdater()
// anonymous usage heartbeat: one POST per install per day
maybePing()
- ipcMain.handle('open-external', (_e, url: string) => {
- if (/^https:\/\/(www\.)?(youtube\.com|youtu\.be)\//.test(url)) {
- shell.openExternal(url)
+ ipcMain.handle('open-external', (_e, value: string) => {
+ try {
+ const url = new URL(value)
+ const youtube = ['youtube.com', 'www.youtube.com', 'youtu.be'].includes(url.hostname)
+ const website = url.hostname === 'stemkit.pages.dev'
+ const projectGithub =
+ url.hostname === 'github.com' && /^\/danvelope\/stemkit(?:\/|$)/.test(url.pathname)
+ if (url.protocol === 'https:' && (youtube || website || projectGithub)) {
+ shell.openExternal(url.toString())
+ }
+ } catch {
+ // Ignore malformed or unsupported external URLs.
}
})
diff --git a/src/main/updater.ts b/src/main/updater.ts
index 69b4e3c..c99dae9 100644
--- a/src/main/updater.ts
+++ b/src/main/updater.ts
@@ -8,6 +8,16 @@ function send(status: string, payload?: Record<string, unknown>): void {
}
export function initUpdater(): void {
+ ipcMain.handle('update:check', async () => {
+ if (!app.isPackaged) return { ok: false }
+ try {
+ await autoUpdater.checkForUpdates()
+ return { ok: true }
+ } catch {
+ return { ok: false }
+ }
+ })
+
if (!app.isPackaged) return
autoUpdater.autoDownload = true
@@ -34,15 +44,6 @@ export function initUpdater(): void {
ipcMain.handle('update:install', () => {
autoUpdater.quitAndInstall()
})
- ipcMain.handle('update:check', async () => {
- try {
- await autoUpdater.checkForUpdates()
- return { ok: true }
- } catch {
- return { ok: false }
- }
- })
-
// electron-updater only supports AppImage on linux — deb installs update
// by re-downloading, so no automatic checks there (the handlers above
// stay registered and simply report no update)
diff --git a/src/preload/index.ts b/src/preload/index.ts
index a0902c8..d456a56 100644
--- a/src/preload/index.ts
+++ b/src/preload/index.ts
@@ -25,6 +25,7 @@ const api: StemKitApi = {
cancelJob: (videoId?: string) => ipcRenderer.invoke('jobs:cancel', videoId),
openExternal: (url) => ipcRenderer.invoke('open-external', url),
getAppVersion: () => ipcRenderer.invoke('app:version'),
+ checkForUpdates: () => ipcRenderer.invoke('update:check'),
installUpdate: () => ipcRenderer.invoke('update:install'),
getSettings: () => ipcRenderer.invoke('settings:get'),
setSettings: (patch) => ipcRenderer.invoke('settings:set', patch),
@@ -33,6 +34,7 @@ const api: StemKitApi = {
enginesStatus: () => ipcRenderer.invoke('engines:status'),
fetchEngine: (which) => ipcRenderer.invoke('engines:fetch', which),
onUpdateEvent: (cb) => subscribe<UpdateEvent>('update:event', cb),
+ onShowAbout: (cb) => subscribe<void>('app:show-about', cb),
onJobEvent: (cb) => subscribe<JobEvent>('job:event', cb),
onEnvEvent: (cb) => subscribe<EnvEvent>('env:event', cb),
onSettingsChange: (cb) => subscribe<AppSettings>('settings:changed', cb)
diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx
index e106542..3cdea8d 100644
--- a/src/renderer/src/App.tsx
+++ b/src/renderer/src/App.tsx
@@ -9,6 +9,7 @@ import { Processing } from './components/Processing'
import { Player } from './components/Player'
import { Setup } from './components/Setup'
import { Settings } from './components/Settings'
+import { About } from './components/About'
import { LogoMark } from './components/Icons'
interface EnvLog {
@@ -53,6 +54,7 @@ export default function App(): React.ReactElement {
const [appVersion, setAppVersion] = useState<string | undefined>(undefined)
const [settings, setSettings] = useState<AppSettings | null>(null)
const [settingsOpen, setSettingsOpen] = useState(false)
+ const [aboutOpen, setAboutOpen] = useState(false)
useEffect(() => {
void window.stemkit.envStatus().then(setStatus)
@@ -78,11 +80,13 @@ export default function App(): React.ReactElement {
setEnvLogs((l) => [...l.slice(-300), { message: e.message, level: e.level }])
)
const offUpdate = window.stemkit.onUpdateEvent((e) => setUpdate(e))
+ const offAbout = window.stemkit.onShowAbout(() => setAboutOpen(true))
void window.stemkit.getAppVersion().then(setAppVersion)
return () => {
offJob()
offEnv()
offUpdate()
+ offAbout()
offSettings()
}
}, [])
@@ -209,21 +213,27 @@ export default function App(): React.ReactElement {
if (!status) {
return (
- <div className="h-full flex items-center justify-center">
- <LogoMark className="w-12 h-12 animate-pulse" />
- </div>
+ <>
+ <div className="h-full flex items-center justify-center">
+ <LogoMark className="w-12 h-12 animate-pulse" />
+ </div>
+ {aboutOpen && <About version={appVersion} onClose={() => setAboutOpen(false)} />}
+ </>
)
}
if (!status.ready) {
return (
- <Setup
- status={status}
- logs={envLogs}
- onInstall={() => {
- void window.stemkit.envBootstrap().then(() => window.stemkit.envStatus().then(setStatus))
- }}
- />
+ <>
+ <Setup
+ status={status}
+ logs={envLogs}
+ onInstall={() => {
+ void window.stemkit.envBootstrap().then(() => window.stemkit.envStatus().then(setStatus))
+ }}
+ />
+ {aboutOpen && <About version={appVersion} onClose={() => setAboutOpen(false)} />}
+ </>
)
}
@@ -291,6 +301,7 @@ export default function App(): React.ReactElement {
onClose={() => setSettingsOpen(false)}
/>
)}
+ {aboutOpen && <About version={appVersion} onClose={() => setAboutOpen(false)} />}
</div>
)
}
diff --git a/src/renderer/src/components/About.tsx b/src/renderer/src/components/About.tsx
new file mode 100644
index 0000000..3da78a7
--- /dev/null
+++ b/src/renderer/src/components/About.tsx
@@ -0,0 +1,124 @@
+import { useEffect, useState } from 'react'
+import { LogoMark, XIcon } from './Icons'
+
+interface Props {
+ version?: string
+ onClose: () => void
+}
+
+export function About({ version, onClose }: Props): React.ReactElement {
+ const [checkingUpdates, setCheckingUpdates] = useState(false)
+ const [updateMessage, setUpdateMessage] = useState('')
+
+ useEffect(() => {
+ const off = window.stemkit.onUpdateEvent((event) => {
+ switch (event.status) {
+ case 'checking':
+ setCheckingUpdates(true)
+ setUpdateMessage('Checking for updates…')
+ break
+ case 'available':
+ setCheckingUpdates(false)
+ setUpdateMessage(`Version ${event.version} is available and downloading.`)
+ break
+ case 'none':
+ setCheckingUpdates(false)
+ setUpdateMessage('StemKit is up to date.')
+ break
+ case 'progress':
+ setCheckingUpdates(false)
+ setUpdateMessage(`Downloading update… ${event.pct ?? 0}%`)
+ break
+ case 'downloaded':
+ setCheckingUpdates(false)
+ setUpdateMessage(`Version ${event.version} is ready. Restart StemKit to install it.`)
+ break
+ case 'error':
+ setCheckingUpdates(false)
+ setUpdateMessage('Could not check for updates. Try again later.')
+ break
+ }
+ })
+ return off
+ }, [])
+
+ useEffect(() => {
+ const onKey = (event: KeyboardEvent): void => {
+ if (event.key === 'Escape') onClose()
+ }
+ window.addEventListener('keydown', onKey)
+ return () => window.removeEventListener('keydown', onKey)
+ }, [onClose])
+
+ const checkForUpdates = async (): Promise<void> => {
+ setCheckingUpdates(true)
+ setUpdateMessage('Checking for updates…')
+ try {
+ const result = await window.stemkit.checkForUpdates()
+ if (result.ok) return
+ } catch {
+ // Show the same message if the updater IPC call itself fails.
+ }
+ setCheckingUpdates(false)
+ setUpdateMessage('Could not check for updates. Try again later.')
+ }
+
+ return (
+ <div
+ className="fixed inset-0 z-[60] flex items-center justify-center bg-black/60 backdrop-blur-sm"
+ onClick={onClose}
+ >
+ <div
+ role="dialog"
+ aria-modal="true"
+ aria-labelledby="about-title"
+ className="relative w-full max-w-sm mx-4 rounded-2xl border border-white/[0.08] bg-[#16151d] p-6 text-center shadow-2xl rise-in"
+ onClick={(event) => event.stopPropagation()}
+ >
+ <button
+ onClick={onClose}
+ title="Close"
+ className="no-drag absolute right-3 top-3 w-7 h-7 rounded-lg hover:bg-white/10 text-white/50 hover:text-white flex items-center justify-center transition-colors"
+ >
+ <XIcon className="w-3.5 h-3.5" />
+ </button>
+ <LogoMark className="mx-auto h-11 w-11" />
+ <h2 id="about-title" className="mt-3 text-lg font-semibold tracking-tight">
+ About StemKit
+ </h2>
+ {version && <p className="mt-1 text-xs text-white/40">Version {version}</p>}
+ <p className="mt-4 text-[12px] leading-relaxed text-white/50">
+ Split songs into stems and play them locally.
+ </p>
+
+ <div className="mt-5 flex justify-center gap-2">
+ <button
+ onClick={() => void window.stemkit.openExternal('https://stemkit.pages.dev')}
+ className="no-drag px-3 py-1.5 rounded-lg bg-white/[0.06] hover:bg-white/10 text-white/70 hover:text-white text-[12px] transition-colors"
+ >
+ StemKit website ↗
+ </button>
+ <button
+ onClick={() => void window.stemkit.openExternal('https://github.com/danvelope/stemkit/issues')}
+ className="no-drag px-3 py-1.5 rounded-lg bg-white/[0.06] hover:bg-white/10 text-white/70 hover:text-white text-[12px] transition-colors"
+ >
+ Get help ↗
+ </button>
+ </div>
+
+ <div className="mt-5 border-t border-white/[0.07] pt-4">
+ <p role="status" className="min-h-4 text-[11px] text-white/40">
+ {updateMessage || 'Check whether a newer version is available.'}
+ </p>
+ <button
+ onClick={() => void checkForUpdates()}
+ disabled={checkingUpdates}
+ className="no-drag mt-3 px-3 py-1.5 rounded-lg bg-violet-500/90 hover:bg-violet-500 disabled:opacity-50 disabled:cursor-wait text-white text-[12px] font-semibold transition-colors"
+ >
+ {checkingUpdates ? 'Checking…' : 'Check for updates'}
+ </button>
+ </div>
+ </div>
+ </div>
+ )
+}
diff --git a/src/shared/types.ts b/src/shared/types.ts
index f751ea7..b446aed 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -131,6 +131,7 @@ export interface StemKitApi {
cancelJob(videoId?: string): Promise<void>
openExternal(url: string): Promise<void>
getAppVersion(): Promise<string>
+ checkForUpdates(): Promise<{ ok: boolean }>
installUpdate(): void
getSettings(): Promise<AppSettings>
setSettings(patch: Partial<AppSettings>): Promise<AppSettings>
@@ -139,6 +140,7 @@ export interface StemKitApi {
enginesStatus(): Promise<EngineStatus>
fetchEngine(which: 'vocals' | 'ft' | 'gpu'): Promise<void>
onUpdateEvent(cb: (ev: UpdateEvent) => void): () => void
+ onShowAbout(cb: () => void): () => void
onJobEvent(cb: (ev: JobEvent) => void): () => void
onEnvEvent(cb: (ev: EnvEvent) => void): () => void
onSettingsChange(cb: (settings: AppSettings) => void): () => void