This file provides guidance to Codex (Codex.ai/code) when working with code in this repository.
SPlayer-Next β desktop music player on Electron + Vue 3 + TypeScript, with Rust native modules (NAPI-RS) for audio decoding, system media integration, and Windows taskbar lyric. Successor to SPlayer.
pnpm install # Install deps
pnpm dev # Build native (debug) + start Electron dev
pnpm build # Full build (rimraf β native β typecheck β electron-vite)
pnpm build:{win,mac,linux}# Platform packages
pnpm typecheck # tsc + vue-tsc (node + web targets)
pnpm lint / format # ESLint / Prettier
pnpm build:native # Rust only; add `--dev` for debugSKIP_NATIVE_BUILD=true skips Rust during dev.
audio-engine static-links FFmpeg via the ffmpeg_audio crate (vendor zip + cc-built at compile time). Zero environment dependency β no FFMPEG_DIR / PKG_CONFIG_PATH, no system FFmpeg required.
The development shell is Git Bash on Windows. Write all terminal commands in bash syntax (&&, cd, etc.) β no PowerShell-only constructs. File paths remain in Windows format (backslashes).
- Main (
electron/main/) β windows, IPC, native modules - Preload (
electron/preload/) βcontextBridgeexposingwindow.api(player/config/system/library/streaming/lyrics) - Renderer (
src/) β Vue 3 SPA - Lyric windows (
windows/desktop-lyric,dynamic-island,taskbar-lyric) β independent Vue entries sharingwindows/shared/
Four .node modules in native/, built via scripts/build-native.ts, lazy-loaded by electron/main/utils/nativeLoader.ts. NAPI-RS auto-generates index.d.ts, imported via path aliases @splayer/audio-engine, @splayer/audio-capture, @splayer/media-ctrl, @splayer/taskbar-lyric.
audio-engineβffmpeg_audiodecode (static FFmpeg) + rodio playback + FFT + cover extraction. URLs wrapped asRead + Seekviaffmpeg_audio::HttpAudioSource(usingHttpCancelHandlefor cancellation/reset) β TLS handled in Rust (reqwest+rustls), cross-platform with no system deps. Pushes events (state/position/ended/outputStalled) via ThreadsafeFunction. Has load_token race protection and anHttpCancelHandlehandle injected intoHttpAudioSourcefor instant stop and reset.audio-captureβ System sound / microphone capture for song recognition. Windows uses WASAPI Loopback, Linux uses PulseAudio (libpulse-devat build time), and macOS 14.2+ uses a private Core Audio process tap for system sound and the default input for the microphone. Older Macs use the renderer microphone. All paths deliver 8 kHz mono f32 PCM.media-ctrlβ Cross-platform system media controls (Windows SMTC / Linux MPRIS / macOS MPNowPlaying) + Discord RPC.taskbar-lyricβ Windows taskbar lyric text rendering with RegistryWatcher / UiaWatcher / TrayWatcher.
User action β status store β IPC (player:load/play/pause/seek)
β main process player.ts β audio-engine
β Rust events (stateChanged/position/ended/outputStalled)
β main broadcasts to renderer + syncs to media-ctrl
β status store updates reactive state
β playback.ts updates non-reactive time source
Two-tier position tracking β high-frequency animation vs. low-frequency UI:
src/stores/status.tsβ Pinia reactive.position / duration / state / volume, pushed ~5Hz from main. Drives progress bar, time display, play button.src/services/playback.tsβ Non-reactive plain vars.getCurrentTime()interpolates between pushes;usePlaybackTime()reads in RAF loop for 60fps lyrics/spectrum without Vue reactivity.src/stores/media.tsβ Pinia + shallowRef. CurrentTrack(lightweight) +TrackDetail(lyrics, quality). Onlytrack + activeLyricpersisted to sessionStorage; never persistTrackDetail(large lyric strings cause memory issues).
Server protocol clients live in the main process (electron/main/services/streaming/): Subsonic / Jellyfin / Emby adapters, safeStorage-backed config, Jellyfin/Emby session management, SQLite synchronization, and the authenticated cover protocol. Subsonic family (Navidrome / OpenSubsonic / Airsonic / Gonic / LMS) shares one adapter; types differ only as UI labels.
electron/main/services/streaming/config.tsβ encrypted config and secret-free renderer views.electron/main/services/streaming/connection.tsβ connection tests, connect, and authenticated adapter requests.electron/main/services/streaming/coverProtocol.tsβstreaming-cover://proxy registered for the default andpersist:mainsessions.electron/main/services/streaming/adapters/β Server response β unifiedTrack / Album / Artist / Playlist. Trusts server's artist field; no client-side splitting.electron/main/services/streaming/sync.ts+snapshot.tsβ cancellable enumeration into temporary SQLite staging, then atomically publish all four indexes; failed or interrupted sync keeps the previous snapshotelectron/main/services/streaming/playback.ts+playbackSession.tsβ native event driven playback sessions, unique PlaySessionId per play, Jellyfin/Emby start/progress/stop and Subsonic now-playing/scrobble; download and preload never report playback- Favorites β server responses are authoritative; SQLite and renderer consume per-track updates, with sync-time overrides preventing late pages from overwriting user actions
stores/streaming.tsβ Server list, active state, and complete shallowRef arrays; main-process update events trigger SQLite snapshot reloads, with no polling or direct media-server access.- Credentials β
electron/main/services/streaming/config.tsencrypts via ElectronsafeStorageto{userData}/app-data/config/streaming.json.accessToken / userIdremain in the bounded main-process session cache and are re-acquired on connect.
Playback resolves remote streaming sources in the main process from Track.serverId / originalId; the renderer only passes a streaming:// identity placeholder or a cached local path. Albums, artists, playlists and navigation retain the originating server ID
Server identity changes advance mediaRevision, which is copied to Track.serverRevision and
used to isolate playback, song caches, and completed downloads. Renaming a server preserves
its media identity and active playback. Downloads use the protocol's original-file endpoint,
with authentication recovery and permission checks performed in the main process
windows/desktop-lyric, dynamic-island, taskbar-lyric are independent Vue entries. Always use shared composables from @windows/shared/:
useNowPlayingSyncβ playback sync, lyric index, anchor interpolationgetNowPlayingCurrentMs()β non-reactive current time for RAF char highlight- Line selection:
pickPrimaryIndex(desktop/taskbar, considers overlap) vs.pickLatestStartedIndex(dynamic island, immediate switch)
Don't reimplement these inside individual windows.
shared/types/player.tsβTrack,TrackDetail,Artist,Album,AudioQuality,PlayerState,PlayerStatus,PlayerEvent,LoadOptions,LoadResult,IpcResponseshared/types/lyrics.tsβLyricFormat,LyricSource (external | embedded | online),LyricData,LyricLine,LyricWord,LyricSpanshared/types/platform/βindex.tsdefinesPlatform (netease | qqmusic | kugou);netease.ts / qqmusic.ts / kugou.tshold platform data contracts shared by main and renderershared/types/streaming.tsβStreamingServerType,StreamingServerConfig,StreamingPingResult,StreamingAuthResult, etc.
Track is for queue storage (no heavy data); TrackDetail loads on demand.
Declarative β defined in src/settings/schema.ts, types in src/types/settings-schema.ts (SettingCategory β SettingSection β SettingItem). Items bind via { store: "settings"|"theme", path: "nested.path" }; system.* paths route through IPC to main config. Tag support on section/item via SettingTag = { text; type? } for Beta/experimental badges. i18n keys: settings.section.{id} / settings.{itemKey}.{label,description}.
{userData}/app-data/ # Unified data directory, separate from Chromium cache data
βββ config/
β βββ settings.json # Main config (electron/main/store/)
β βββ streaming.json # Streaming credentials (safeStorage encrypted)
β βββ lastfm.json # Last.fm credentials (safeStorage encrypted)
βββ database/library.db # Music library (better-sqlite3, WAL)
βββ cache/ # covers/ (cover:// protocol) + artists/ backgrounds/ songs/
βββ logs/ # App logs + native/
βββ plugins/ # scripts/ data/ logs/
# All paths are defined centrally in electron/main/utils/paths.ts
Renderer IndexedDB (localforage): splayer/library, splayer/queue. Local playlists are stored in
SQLite through the main-process playlist service; the old splayer/playlists store is migration-only.
Rust extracts 300x300 JPEG thumbnail to {userData}/app-data/cache/covers/ during decode; renderer reads via cover://{filename} protocol. Original via getCoverRaw() for SMTC, never cached. Authenticated streaming covers use the main-process streaming-cover:// proxy.
electron/main/store/ is custom (not electron-store). Reads/writes {userData}/app-data/config/settings.json (path via electron/main/utils/paths.ts), merges with defaults from shared/defaults/settings.ts. Supports dot-path access (store.get("system.taskbarProgress")), atomic writes, schema migrations.
Renderer uses vue-i18n with src/i18n/locales/{zh-CN,en-US}.json. Main process has a lightweight translation table (electron/main/utils/i18n.ts) for tray/thumbar; locale synced via system:setLocale IPC.
@/ β src/ (renderer, tsconfig.web.json)
@shared/ β shared/ (both processes)
@main/ β electron/main/ (main, tsconfig.node.json)
@windows/ β windows/ (lyric windows)
@splayer/audio-engine β native/audio-engine (main)
@splayer/media-ctrl β native/media-ctrl (main)
@splayer/taskbar-lyric β native/taskbar-lyric (main)
All comments in Chinese. Every newly added or modified method must have a concise, meaningful
JSDoc description of its purpose and parameters, using @param name - description and
@returns when meaningful. This applies to internal helpers, class methods, adapter methods,
and exported APIs. Anonymous callbacks do not need redundant explanations of obvious logic
Avoid trailing periods in Chinese comments, JSDoc descriptions, and UI copy whenever possible. Keep the wording concise and natural
/**
* <Chinese method description>
* @param trackId - <Chinese parameter description>
* @returns <Chinese return description>
*/Forbidden: // βββ separator lines (including ones with section titles), prose-style multi-paragraph comments, restating-the-obvious comments, numbered enumerations (1. 2. 3.) inside comments. Write comments only when the why is non-obvious.
Split logic into files rather than separator comments. Don't extract a helper for one-place callers (3+ uses justify it). No "just in case" defensive code or fallbacks for impossible scenarios. No configurable knobs (timeouts / retries / buffer sizes) unless required β write constants. Don't break errors into per-case enums; anyhow or plain Error is usually enough.
Memory is a hard requirement. The main process logs memory usage through app.getAppMetrics()
60 seconds after launch and then every 10 minutes. When a change touches rendering, caching, or
IPC, verify before and after with these samples.
- Images by display size β anything blurred, sampled, or rendered small uses the 300px
coverthumbnail (player blur background, color extraction, lists).coverOriginalonly for the visible large cover and poster export. Large<img>: adddecoding="async"; preload withimg.decode()before fading in. - Compositing layers are budgeted β never put
will-changein CSS on unbounded element collections; promote dynamically and only near the viewport (lyric enginelineWillChangepattern). New full-screenfilter: blur/backdrop-filterlayers need justification. - Hidden = silent β high-frequency pushes (
position/fftData/position-sync) must not reach hidden windows:broadcast(channel, data, true)or anisVisible()gate; consumers recover from the next push (β€200ms), no resync needed. Low-frequency state events (stateChanged/ended/ track-change) always go through. RAF loops and canvases must stop when their surface is hidden (enginefreeze()/visibilitychangepattern). - In-memory caches must be bounded β every module-level Map/array cache needs an eviction rule (subsonic
viewAuthCacheevicts per-server). Never retainTrackDetail-sized data beyond the current track.
Frontend time is milliseconds everywhere. Rust engine uses seconds internally; toMs() in electron/main/ipc/player.ts converts.
Never hand-write native module types β import from @splayer/*. Use shallowRef for Track arrays/collections (avoid deep proxy). Vue proxied objects can't be cloned by IDB (DataCloneError); use toRaw before persisting.
In Vue components, vue / pinia / vue-router / @vueuse/core / vue-i18n are auto-imported, and UI components in src/components/ are auto-registered.
Icon components used only in Vue templates are auto-imported. Do not manually import them in
<script setup>; import an icon explicitly only when it is referenced by script code.
Use scoped loggers from @main/utils/logger (coreLog / playerLog / mediaLog / trayLog / taskbarLog / nativeLog, etc.). Don't import electron-log directly.
In preload's onEvent, always ipcRenderer.removeAllListeners() before adding a new listener (HMR accumulates otherwise). Renderer composables call the returned unsubscribe in onBeforeUnmount.
Double quotes, semicolons, 100-char width, trailing commas.
Before committing, run Prettier on every file included in the commit and verify the formatted working tree before creating the commit. Do not leave formatting-only changes from the current task outside the commit.
Put cross-process types (LocaleCode / SystemConfig / StreamingServerType, etc.) in shared/types/.
Use Conventional Commits with a Chinese summary: <type>: <summary>. Keep the title on one line;
do not add a body or bullets unless explicitly requested. Use the type that matches the change,
such as feat, fix, refactor, perf, docs, test, build, ci, style, or chore.