Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,014 changes: 898 additions & 116 deletions src-tauri/src/audio.rs

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions src-tauri/src/commands/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,11 +473,12 @@ pub async fn logout(state: State<'_, AppState>) -> Result<(), SoneError> {
/// purges them) and does NOT lock `tidal_client` (callers hold that lock).
pub(crate) async fn restore_session_services(app: &AppHandle) {
let state = app.state::<AppState>();
let discord_rpc = state.load_settings().map(|s| s.discord_rpc).unwrap_or(false);
let discord_rpc = state
.load_settings()
.map(|s| s.discord_rpc)
.unwrap_or(false);
if discord_rpc {
state
.discord
.send(crate::discord::DiscordCommand::Connect);
state.discord.send(crate::discord::DiscordCommand::Connect);
}
crate::mcp::ensure_mcp_started(app).await;
}
Expand Down
93 changes: 58 additions & 35 deletions src-tauri/src/commands/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ pub async fn get_all_playlists(
) -> Result<crate::tidal_api::PaginatedResponse<TidalPlaylist>, SoneError> {
log::debug!(
"[get_all_playlists]: user_id={}, offset={}, limit={}",
user_id, offset, limit
user_id,
offset,
limit
);

let cache_key = format!(
Expand All @@ -123,16 +125,10 @@ pub async fn get_all_playlists(
}
CacheResult::Stale(bytes) => {
if let Ok(data) =
serde_json::from_slice::<crate::tidal_api::PaginatedResponse<TidalPlaylist>>(
&bytes,
)
serde_json::from_slice::<crate::tidal_api::PaginatedResponse<TidalPlaylist>>(&bytes)
{
if state.disk_cache.mark_in_flight(&cache_key).await {
if state
.disk_cache
.should_retry_refresh(&cache_key, 300)
.await
{
if state.disk_cache.should_retry_refresh(&cache_key, 300).await {
state.disk_cache.mark_refresh_attempt(&cache_key).await;
let handle = app_handle.clone();
let key = cache_key.clone();
Expand All @@ -153,10 +149,7 @@ pub async fn get_all_playlists(
&key,
&json,
CacheTier::UserContent,
&[
"all-playlists",
&format!("user:{}", user_id),
],
&["all-playlists", &format!("user:{}", user_id)],
)
.await
.ok();
Expand Down Expand Up @@ -496,7 +489,10 @@ pub async fn get_favorite_albums(
order_direction
);

let cache_key = format!("fav-albums:{}:{}:{}:{}:{}", user_id, offset, limit, order, order_direction);
let cache_key = format!(
"fav-albums:{}:{}:{}:{}:{}",
user_id, offset, limit, order, order_direction
);
match state
.disk_cache
.get(&cache_key, CacheTier::UserContent)
Expand All @@ -523,7 +519,9 @@ pub async fn get_favorite_albums(
let st = handle.state::<AppState>();
let result = {
let mut client = st.tidal_client.lock().await;
client.get_favorite_albums(user_id, offset, limit, &order_bg, &dir_bg).await
client
.get_favorite_albums(user_id, offset, limit, &order_bg, &dir_bg)
.await
};
if let Ok(fresh) = result {
if let Ok(json) = serde_json::to_vec(&fresh) {
Expand Down Expand Up @@ -551,7 +549,9 @@ pub async fn get_favorite_albums(
}

let mut client = state.tidal_client.lock().await;
let data = client.get_favorite_albums(user_id, offset, limit, &order, &order_direction).await?;
let data = client
.get_favorite_albums(user_id, offset, limit, &order, &order_direction)
.await?;
drop(client);

if let Ok(json) = serde_json::to_vec(&data) {
Expand All @@ -576,7 +576,11 @@ pub async fn create_playlist(
description: String,
access_type: String,
) -> Result<TidalPlaylist, SoneError> {
log::debug!("[create_playlist]: title={}, access_type={}", title, access_type);
log::debug!(
"[create_playlist]: title={}, access_type={}",
title,
access_type
);
let client = state.tidal_client.lock().await;
let playlist = client
.create_playlist(&title, &description, &access_type)
Expand All @@ -585,7 +589,10 @@ pub async fn create_playlist(
let user_id = client.tokens.as_ref().and_then(|t| t.user_id);
drop(client);
if let Some(uid) = user_id {
state.disk_cache.invalidate_tag(&format!("user:{}", uid)).await;
state
.disk_cache
.invalidate_tag(&format!("user:{}", uid))
.await;
}
state.disk_cache.invalidate_tag("folders").await;
Ok(playlist)
Expand All @@ -599,15 +606,22 @@ pub async fn update_playlist(
description: String,
access_type: String,
) -> Result<TidalPlaylist, SoneError> {
log::debug!("[update_playlist]: playlist_id={}, title={}", playlist_id, title);
log::debug!(
"[update_playlist]: playlist_id={}, title={}",
playlist_id,
title
);
let client = state.tidal_client.lock().await;
let playlist = client
.update_playlist(&playlist_id, &title, &description, &access_type)
.await?;
let user_id = client.tokens.as_ref().and_then(|t| t.user_id);
drop(client);
if let Some(uid) = user_id {
state.disk_cache.invalidate_tag(&format!("user:{}", uid)).await;
state
.disk_cache
.invalidate_tag(&format!("user:{}", uid))
.await;
}
state.disk_cache.invalidate_tag("folders").await;
Ok(playlist)
Expand Down Expand Up @@ -1054,7 +1068,10 @@ pub async fn get_favorite_mixes(
order_direction
);

let cache_key = format!("fav-mixes:{}:{}:{}:{}", offset, limit, order, order_direction);
let cache_key = format!(
"fav-mixes:{}:{}:{}:{}",
offset, limit, order, order_direction
);
match state
.disk_cache
.get(&cache_key, CacheTier::UserContent)
Expand All @@ -1081,7 +1098,9 @@ pub async fn get_favorite_mixes(
let st = handle.state::<AppState>();
let result = {
let mut client = st.tidal_client.lock().await;
client.get_favorite_mixes(offset, limit, &order_bg, &dir_bg).await
client
.get_favorite_mixes(offset, limit, &order_bg, &dir_bg)
.await
};
if let Ok(fresh) = result {
if let Ok(json) = serde_json::to_vec(&fresh) {
Expand All @@ -1104,7 +1123,9 @@ pub async fn get_favorite_mixes(
}

let mut client = state.tidal_client.lock().await;
let data = client.get_favorite_mixes(offset, limit, &order, &order_direction).await?;
let data = client
.get_favorite_mixes(offset, limit, &order, &order_direction)
.await?;
drop(client);

if let Ok(json) = serde_json::to_vec(&data) {
Expand Down Expand Up @@ -1160,7 +1181,10 @@ pub async fn get_favorite_artists(
order_direction
);

let cache_key = format!("fav-artists:{}:{}:{}:{}:{}", user_id, offset, limit, order, order_direction);
let cache_key = format!(
"fav-artists:{}:{}:{}:{}:{}",
user_id, offset, limit, order, order_direction
);
match state
.disk_cache
.get(&cache_key, CacheTier::UserContent)
Expand All @@ -1187,7 +1211,11 @@ pub async fn get_favorite_artists(
let st = handle.state::<AppState>();
let result = {
let mut client = st.tidal_client.lock().await;
client.get_favorite_artists(user_id, offset, limit, &order_bg, &dir_bg).await
client
.get_favorite_artists(
user_id, offset, limit, &order_bg, &dir_bg,
)
.await
};
if let Ok(fresh) = result {
if let Ok(json) = serde_json::to_vec(&fresh) {
Expand Down Expand Up @@ -1215,7 +1243,9 @@ pub async fn get_favorite_artists(
}

let mut client = state.tidal_client.lock().await;
let data = client.get_favorite_artists(user_id, offset, limit, &order, &order_direction).await?;
let data = client
.get_favorite_artists(user_id, offset, limit, &order, &order_direction)
.await?;
drop(client);

if let Ok(json) = serde_json::to_vec(&data) {
Expand Down Expand Up @@ -1271,11 +1301,7 @@ pub async fn get_playlist_folders(
CacheResult::Stale(bytes) => {
if let Ok(val) = serde_json::from_slice::<serde_json::Value>(&bytes) {
if state.disk_cache.mark_in_flight(&cache_key).await {
if state
.disk_cache
.should_retry_refresh(&cache_key, 300)
.await
{
if state.disk_cache.should_retry_refresh(&cache_key, 300).await {
state.disk_cache.mark_refresh_attempt(&cache_key).await;
let handle = app_handle.clone();
let key = cache_key.clone();
Expand Down Expand Up @@ -1315,10 +1341,7 @@ pub async fn get_playlist_folders(
}
}
Err(e) => {
log::warn!(
"[get_playlist_folders] bg refresh failed: {}",
e
);
log::warn!("[get_playlist_folders] bg refresh failed: {}", e);
}
}
st.disk_cache.clear_in_flight(&key).await;
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/commands/mcp.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use serde::Serialize;
use tauri::State;

use crate::AppState;
use crate::error::SoneError;
use crate::mcp::{NowPlayingSnapshot, QueueTrackSnapshot};
use crate::AppState;

#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
Expand Down
1 change: 0 additions & 1 deletion src-tauri/src/commands/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,3 @@ pub async fn get_track_credits(
}
Ok(credits)
}

35 changes: 20 additions & 15 deletions src-tauri/src/commands/playback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ pub async fn play_tidal_track(
resolve_play_uri(state.inner(), track_id, use_track_gain).await?;

// Store selected values for live toggle
state.last_replay_gain.store(rg.to_bits(), Ordering::Relaxed);
state
.last_replay_gain
.store(rg.to_bits(), Ordering::Relaxed);
state
.last_peak_amplitude
.store(peak.to_bits(), Ordering::Relaxed);
Expand All @@ -163,9 +165,9 @@ pub async fn play_tidal_track(
player.set_normalization_gain(norm_gain)?;
player.play_url(&uri)
})
.await
.map_err(|e| SoneError::Audio(e.to_string()))?
.map_err(SoneError::Audio)?;
.await
.map_err(|e| SoneError::Audio(e.to_string()))?
.map_err(SoneError::Audio)?;

// Save last played track
if let Some(mut settings) = state.load_settings() {
Expand Down Expand Up @@ -194,7 +196,10 @@ pub async fn set_next_track(

#[tauri::command]
pub fn clear_next_track(state: State<'_, AppState>) -> Result<(), SoneError> {
state.audio_player.clear_next_track().map_err(SoneError::Audio)
state
.audio_player
.clear_next_track()
.map_err(SoneError::Audio)
}

/// Pure resolver: returns `StreamInfo` WITHOUT arming the gapless slot or
Expand Down Expand Up @@ -397,10 +402,7 @@ pub fn update_mpris_playback_status(

#[tauri::command]
#[allow(unused_variables)]
pub fn update_mpris_shuffle(
state: State<'_, AppState>,
enabled: bool,
) -> Result<(), SoneError> {
pub fn update_mpris_shuffle(state: State<'_, AppState>, enabled: bool) -> Result<(), SoneError> {
#[cfg(target_os = "linux")]
state
.mpris
Expand All @@ -423,10 +425,7 @@ pub fn update_mpris_fullscreen(

#[tauri::command]
#[allow(unused_variables)]
pub fn update_mpris_loop_status(
state: State<'_, AppState>,
mode: u8,
) -> Result<(), SoneError> {
pub fn update_mpris_loop_status(state: State<'_, AppState>, mode: u8) -> Result<(), SoneError> {
#[cfg(target_os = "linux")]
state
.mpris
Expand All @@ -449,7 +448,10 @@ mod tests {
#[test]
fn ceiling_max_without_secret_drops_hires() {
// Reproduces the legacy no-secret branch exactly.
assert_eq!(quality_tiers("HI_RES_LOSSLESS", false), vec!["LOSSLESS", "HIGH"]);
assert_eq!(
quality_tiers("HI_RES_LOSSLESS", false),
vec!["LOSSLESS", "HIGH"]
);
}

#[test]
Expand Down Expand Up @@ -477,7 +479,10 @@ mod tests {
for ceiling in ["HI_RES_LOSSLESS", "LOSSLESS", "HIGH", "GARBAGE"] {
for has_secret in [true, false] {
let tiers = quality_tiers(ceiling, has_secret);
assert!(tiers.contains(&"HIGH"), "ceiling={ceiling} secret={has_secret}");
assert!(
tiers.contains(&"HIGH"),
"ceiling={ceiling} secret={has_secret}"
);
}
}
}
Expand Down
12 changes: 10 additions & 2 deletions src-tauri/src/commands/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ pub async fn update_profile_meta(
handle: Option<String>,
dry_run: bool,
) -> Result<(), SoneError> {
log::debug!("[update_profile_meta]: artist_id={}, dry_run={}", artist_id, dry_run);
log::debug!(
"[update_profile_meta]: artist_id={}, dry_run={}",
artist_id,
dry_run
);
let client = state.tidal_client.lock().await;
client
.update_artist_meta(artist_id, name.as_deref(), handle.as_deref(), dry_run)
Expand All @@ -44,7 +48,11 @@ pub async fn update_profile_links(
artist_id: u64,
links: Vec<ExternalLink>,
) -> Result<(), SoneError> {
log::debug!("[update_profile_links]: artist_id={}, n={}", artist_id, links.len());
log::debug!(
"[update_profile_links]: artist_id={}, n={}",
artist_id,
links.len()
);
let client = state.tidal_client.lock().await;
client.update_external_links(artist_id, links).await
}
Expand Down
Loading