feat(player): implement playback context system
- Add PlaybackContext module with ContextManager - Context tracks semantic origin (album, playlist, artist top, etc.) - Separate from queue - defines what 'next' means - Backend: Rust struct with track IDs and position tracking - Frontend: Svelte store with reactive subscriptions - Tauri commands for context CRUD operations - Context is nullable (single track playback has no context) cp
This commit is contained in:
1 parent
02469aa7b2
commit
49fe9e6b11
5 files changed
+440
No files matched your search
@@ -10,6 +10,7 @@ pub mod favorites;
|
||||
pub mod lastfm;
|
||||
pub mod notification;
|
||||
pub mod playback;
|
||||
pub mod playback_context;
|
||||
pub mod playlist;
|
||||
pub mod playlist_import;
|
||||
pub mod queue;
|
||||
@@ -24,6 +25,7 @@ pub use favorites::*;
|
||||
pub use lastfm::*;
|
||||
pub use notification::*;
|
||||
pub use playback::*;
|
||||
pub use playback_context::*;
|
||||
pub use playlist::*;
|
||||
pub use playlist_import::*;
|
||||
pub use queue::*;
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
//! Playback context commands
|
||||
|
||||
use tauri::State;
|
||||
use crate::playback_context::{PlaybackContext, ContextType, ContentSource};
|
||||
use crate::AppState;
|
||||
|
||||
/// Get the current playback context
|
||||
#[tauri::command]
|
||||
pub fn get_playback_context(state: State<'_, AppState>) -> Option<PlaybackContext> {
|
||||
state.context.get_context()
|
||||
}
|
||||
|
||||
/// Set a new playback context
|
||||
#[tauri::command]
|
||||
pub fn set_playback_context(
|
||||
context_type: String,
|
||||
id: String,
|
||||
label: String,
|
||||
source: String,
|
||||
track_ids: Vec<u64>,
|
||||
start_position: usize,
|
||||
state: State<'_, AppState>,
|
||||
) -> Result<(), String> {
|
||||
// Parse context type
|
||||
let ctx_type = match context_type.as_str() {
|
||||
"album" => ContextType::Album,
|
||||
"playlist" => ContextType::Playlist,
|
||||
"artist_top" => ContextType::ArtistTop,
|
||||
"home_list" => ContextType::HomeList,
|
||||
"favorites" => ContextType::Favorites,
|
||||
_ => return Err(format!("Invalid context type: {}", context_type)),
|
||||
};
|
||||
|
||||
// Parse source
|
||||
let content_source = match source.as_str() {
|
||||
"qobuz" => ContentSource::Qobuz,
|
||||
"local" => ContentSource::Local,
|
||||
_ => return Err(format!("Invalid source: {}", source)),
|
||||
};
|
||||
|
||||
let context = PlaybackContext::new(
|
||||
ctx_type,
|
||||
id,
|
||||
label,
|
||||
content_source,
|
||||
track_ids,
|
||||
start_position,
|
||||
);
|
||||
|
||||
state.context.set_context(context);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Clear the current playback context
|
||||
#[tauri::command]
|
||||
pub fn clear_playback_context(state: State<'_, AppState>) {
|
||||
state.context.clear_context();
|
||||
}
|
||||
|
||||
/// Check if a playback context is active
|
||||
#[tauri::command]
|
||||
pub fn has_playback_context(state: State<'_, AppState>) -> bool {
|
||||
state.context.has_context()
|
||||
}
|
||||
Reference in new issue
Block a user