Fixed linux build
This commit is contained in:
+7
-2
@@ -301,17 +301,21 @@ impl ApiClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Report a finished/aborted listen to the play history.
|
/// Report a finished/aborted listen to the play history.
|
||||||
|
/// Body shape is the backend's HistoryEntry; `completed` marks a full
|
||||||
|
/// play (vs a manual skip).
|
||||||
pub async fn report_history(
|
pub async fn report_history(
|
||||||
&self,
|
&self,
|
||||||
track_id: i64,
|
track_id: i64,
|
||||||
started_at: Option<i64>,
|
started_at: Option<i64>,
|
||||||
listened_seconds: i32,
|
listened_seconds: i32,
|
||||||
|
completed: bool,
|
||||||
) -> Result<(), ApiError> {
|
) -> Result<(), ApiError> {
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
struct Body {
|
struct Body {
|
||||||
track_id: i64,
|
track_id: i64,
|
||||||
started_at: Option<i64>,
|
started_at: Option<i64>,
|
||||||
listened_seconds: i32,
|
duration_listened: Option<i32>,
|
||||||
|
completed: bool,
|
||||||
}
|
}
|
||||||
let _: serde_json::Value = self
|
let _: serde_json::Value = self
|
||||||
.post_json(
|
.post_json(
|
||||||
@@ -319,7 +323,8 @@ impl ApiClient {
|
|||||||
&Body {
|
&Body {
|
||||||
track_id,
|
track_id,
|
||||||
started_at,
|
started_at,
|
||||||
listened_seconds,
|
duration_listened: Some(listened_seconds),
|
||||||
|
completed,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|||||||
+14
-3
@@ -412,6 +412,7 @@ fn play_current(state: &mut AppState, runtime: &Runtime) {
|
|||||||
previous.id,
|
previous.id,
|
||||||
state.player.track_started_at,
|
state.player.track_started_at,
|
||||||
state.player.position_secs.round() as i32,
|
state.player.position_secs.round() as i32,
|
||||||
|
false,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -518,7 +519,13 @@ fn push_state_now(state: &AppState, runtime: &mut Runtime) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Fire-and-forget history report; listens shorter than 5s are noise.
|
/// Fire-and-forget history report; listens shorter than 5s are noise.
|
||||||
fn report_history(runtime: &Runtime, track_id: i64, started_at: Option<i64>, listened: i32) {
|
fn report_history(
|
||||||
|
runtime: &Runtime,
|
||||||
|
track_id: i64,
|
||||||
|
started_at: Option<i64>,
|
||||||
|
listened: i32,
|
||||||
|
completed: bool,
|
||||||
|
) {
|
||||||
if listened < 5 {
|
if listened < 5 {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -526,7 +533,10 @@ fn report_history(runtime: &Runtime, track_id: i64, started_at: Option<i64>, lis
|
|||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
if let Err(err) = api.report_history(track_id, started_at, listened).await {
|
if let Err(err) = api
|
||||||
|
.report_history(track_id, started_at, listened, completed)
|
||||||
|
.await
|
||||||
|
{
|
||||||
tracing::warn!(%err, "history report failed");
|
tracing::warn!(%err, "history report failed");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -745,13 +755,14 @@ fn handle_app_event(state: &mut AppState, runtime: &mut Runtime, event: AppEvent
|
|||||||
state.art.insert(key, entry);
|
state.art.insert(key, entry);
|
||||||
}
|
}
|
||||||
AppEvent::Player(player::PlayerEvent::TrackFinished { has_next }) => {
|
AppEvent::Player(player::PlayerEvent::TrackFinished { has_next }) => {
|
||||||
// The finished track gets a full-duration history entry.
|
// The finished track gets a full-duration, completed entry.
|
||||||
if let Some(finished) = state.player.current.clone() {
|
if let Some(finished) = state.player.current.clone() {
|
||||||
report_history(
|
report_history(
|
||||||
runtime,
|
runtime,
|
||||||
finished.id,
|
finished.id,
|
||||||
state.player.track_started_at,
|
state.player.track_started_at,
|
||||||
finished.duration_seconds.round() as i32,
|
finished.duration_seconds.round() as i32,
|
||||||
|
true,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if has_next {
|
if has_next {
|
||||||
|
|||||||
Reference in New Issue
Block a user