fix(playlist): fix state management in playlist commands
- Change playlist commands to use AppState instead of direct Arc<Mutex> - Add playlist management endpoint paths for future use
This commit is contained in:
1 parent
8f4a47b2d8
commit
83654866f1
2 files changed
+12
-8
No files matched your search
@@ -24,6 +24,11 @@ pub mod paths {
|
|||||||
pub const PLAYLIST_GET: &str = "/playlist/get";
|
pub const PLAYLIST_GET: &str = "/playlist/get";
|
||||||
pub const PLAYLIST_SEARCH: &str = "/playlist/search";
|
pub const PLAYLIST_SEARCH: &str = "/playlist/search";
|
||||||
pub const PLAYLIST_GET_USER_PLAYLISTS: &str = "/playlist/getUserPlaylists";
|
pub const PLAYLIST_GET_USER_PLAYLISTS: &str = "/playlist/getUserPlaylists";
|
||||||
|
pub const PLAYLIST_CREATE: &str = "/playlist/create";
|
||||||
|
pub const PLAYLIST_DELETE: &str = "/playlist/delete";
|
||||||
|
pub const PLAYLIST_ADD_TRACKS: &str = "/playlist/addTracks";
|
||||||
|
pub const PLAYLIST_DELETE_TRACKS: &str = "/playlist/deleteTracks";
|
||||||
|
pub const PLAYLIST_UPDATE: &str = "/playlist/update";
|
||||||
|
|
||||||
// Favorites
|
// Favorites
|
||||||
pub const FAVORITE_GET_USER_FAVORITES: &str = "/favorite/getUserFavorites";
|
pub const FAVORITE_GET_USER_FAVORITES: &str = "/favorite/getUserFavorites";
|
||||||
|
|||||||
@@ -1,19 +1,18 @@
|
|||||||
//! Playlist-related Tauri commands
|
//! Playlist-related Tauri commands
|
||||||
|
|
||||||
use tauri::State;
|
use tauri::State;
|
||||||
use tokio::sync::Mutex;
|
|
||||||
|
|
||||||
use crate::api::client::QobuzClient;
|
|
||||||
use crate::api::models::{Playlist, SearchResultsPage};
|
use crate::api::models::{Playlist, SearchResultsPage};
|
||||||
|
use crate::AppState;
|
||||||
|
|
||||||
/// Get user's playlists
|
/// Get user's playlists
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn get_user_playlists(
|
pub async fn get_user_playlists(
|
||||||
client: State<'_, std::sync::Arc<Mutex<QobuzClient>>>,
|
state: State<'_, AppState>,
|
||||||
) -> Result<Vec<Playlist>, String> {
|
) -> Result<Vec<Playlist>, String> {
|
||||||
log::info!("Command: get_user_playlists");
|
log::info!("Command: get_user_playlists");
|
||||||
|
|
||||||
let client = client.lock().await;
|
let client = state.client.lock().await;
|
||||||
client
|
client
|
||||||
.get_user_playlists()
|
.get_user_playlists()
|
||||||
.await
|
.await
|
||||||
@@ -24,11 +23,11 @@ pub async fn get_user_playlists(
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn get_playlist(
|
pub async fn get_playlist(
|
||||||
playlist_id: u64,
|
playlist_id: u64,
|
||||||
client: State<'_, std::sync::Arc<Mutex<QobuzClient>>>,
|
state: State<'_, AppState>,
|
||||||
) -> Result<Playlist, String> {
|
) -> Result<Playlist, String> {
|
||||||
log::info!("Command: get_playlist {}", playlist_id);
|
log::info!("Command: get_playlist {}", playlist_id);
|
||||||
|
|
||||||
let client = client.lock().await;
|
let client = state.client.lock().await;
|
||||||
client
|
client
|
||||||
.get_playlist(playlist_id)
|
.get_playlist(playlist_id)
|
||||||
.await
|
.await
|
||||||
@@ -40,11 +39,11 @@ pub async fn get_playlist(
|
|||||||
pub async fn search_playlists(
|
pub async fn search_playlists(
|
||||||
query: String,
|
query: String,
|
||||||
limit: Option<u32>,
|
limit: Option<u32>,
|
||||||
client: State<'_, std::sync::Arc<Mutex<QobuzClient>>>,
|
state: State<'_, AppState>,
|
||||||
) -> Result<SearchResultsPage<Playlist>, String> {
|
) -> Result<SearchResultsPage<Playlist>, String> {
|
||||||
log::info!("Command: search_playlists \"{}\"", query);
|
log::info!("Command: search_playlists \"{}\"", query);
|
||||||
|
|
||||||
let client = client.lock().await;
|
let client = state.client.lock().await;
|
||||||
client
|
client
|
||||||
.search_playlists(&query, limit.unwrap_or(20))
|
.search_playlists(&query, limit.unwrap_or(20))
|
||||||
.await
|
.await
|
||||||
|
|||||||
Reference in new issue
Block a user