First working POC
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use crate::repository::types::MediaItem;
|
||||
|
||||
/// Autoplay decision result - determines what happens after playback ends
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
#[serde(tag = "action", rename_all = "camelCase")]
|
||||
pub enum AutoplayDecision {
|
||||
/// Stop playback (no next item or timer expired)
|
||||
Stop,
|
||||
/// Advance to next track in queue (for audio/movies)
|
||||
AdvanceToNext,
|
||||
/// Show next episode popup with countdown
|
||||
ShowNextEpisodePopup {
|
||||
current_episode: MediaItem,
|
||||
next_episode: MediaItem,
|
||||
countdown_seconds: u32,
|
||||
auto_advance: bool,
|
||||
},
|
||||
}
|
||||
|
||||
/// Autoplay settings (controls next episode behavior)
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct AutoplaySettings {
|
||||
/// Whether autoplay is enabled for next episodes
|
||||
pub enabled: bool,
|
||||
/// Countdown duration in seconds before auto-playing next episode
|
||||
pub countdown_seconds: u32,
|
||||
}
|
||||
|
||||
impl Default for AutoplaySettings {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
enabled: true,
|
||||
countdown_seconds: 10,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AutoplaySettings {
|
||||
/// Validate and clamp countdown seconds to reasonable range (5-30 seconds)
|
||||
pub fn with_validated_countdown(mut self) -> Self {
|
||||
self.countdown_seconds = self.countdown_seconds.clamp(5, 30);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_autoplay_settings_defaults() {
|
||||
let settings = AutoplaySettings::default();
|
||||
assert!(settings.enabled);
|
||||
assert_eq!(settings.countdown_seconds, 10);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_countdown_validation() {
|
||||
let settings = AutoplaySettings {
|
||||
enabled: true,
|
||||
countdown_seconds: 2, // Too short
|
||||
}
|
||||
.with_validated_countdown();
|
||||
assert_eq!(settings.countdown_seconds, 5); // Clamped to min
|
||||
|
||||
let settings = AutoplaySettings {
|
||||
enabled: true,
|
||||
countdown_seconds: 60, // Too long
|
||||
}
|
||||
.with_validated_countdown();
|
||||
assert_eq!(settings.countdown_seconds, 30); // Clamped to max
|
||||
|
||||
let settings = AutoplaySettings {
|
||||
enabled: true,
|
||||
countdown_seconds: 15, // Valid
|
||||
}
|
||||
.with_validated_countdown();
|
||||
assert_eq!(settings.countdown_seconds, 15); // Unchanged
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user