Skip to main content

app_tauri_plugin_player/
models.rs

1//! Data models for the player plugin.
2//!
3//! This module defines the data structures used for player state management,
4//! including tracks, playlists, state updates, and media control events.
5
6use serde::{Deserialize, Serialize};
7use tauri::ipc::Channel;
8
9/// Represents a music track with metadata.
10#[derive(Debug, Deserialize, Serialize)]
11#[serde(rename_all = "camelCase")]
12pub struct Track {
13    /// Unique identifier for the track.
14    pub id: String,
15    /// Track number in the album.
16    pub number: u32,
17    /// Title of the track.
18    pub title: String,
19    /// Album name.
20    pub album: String,
21    /// Optional URL to the album cover image.
22    pub album_cover: Option<String>,
23    /// Artist name.
24    pub artist: String,
25    /// Optional URL to the artist cover image.
26    pub artist_cover: Option<String>,
27    /// Duration of the track in seconds.
28    pub duration: f64,
29}
30
31/// Represents a playlist containing multiple tracks.
32#[derive(Debug, Deserialize, Serialize)]
33#[serde(rename_all = "camelCase")]
34pub struct Playlist {
35    /// List of tracks in the playlist.
36    pub tracks: Vec<Track>,
37}
38
39/// State update request for the player.
40#[derive(Debug, Deserialize, Serialize)]
41#[serde(rename_all = "camelCase")]
42pub struct UpdateState {
43    /// Whether the player should be playing.
44    #[serde(skip_serializing_if = "Option::is_none")]
45    pub playing: Option<bool>,
46    /// Position in the playlist (track index).
47    #[serde(skip_serializing_if = "Option::is_none")]
48    pub position: Option<u16>,
49    /// Seek position in seconds.
50    #[serde(skip_serializing_if = "Option::is_none")]
51    pub seek: Option<f64>,
52    /// Volume level (0.0 to 1.0).
53    #[serde(skip_serializing_if = "Option::is_none")]
54    pub volume: Option<f64>,
55    /// Playlist to set.
56    #[serde(skip_serializing_if = "Option::is_none")]
57    pub playlist: Option<Playlist>,
58}
59
60/// Response from a state update operation.
61#[derive(Debug, Clone, Default, Deserialize, Serialize)]
62#[serde(rename_all = "camelCase")]
63pub struct StateResponse {}
64
65/// Request to initialize a communication channel.
66#[derive(Serialize)]
67#[serde(rename_all = "camelCase")]
68pub struct InitChannel {
69    /// The IPC channel to initialize.
70    pub channel: Channel,
71}
72
73/// Response from a channel initialization operation.
74#[derive(Debug, Clone, Default, Deserialize, Serialize)]
75#[serde(rename_all = "camelCase")]
76pub struct InitChannelResponse {}
77
78/// Media control event from the platform.
79#[derive(Debug, Deserialize, Serialize)]
80#[serde(rename_all = "camelCase")]
81pub struct MediaEvent {
82    /// Play/pause event.
83    #[serde(skip_serializing_if = "Option::is_none")]
84    pub play: Option<bool>,
85    /// Next track event.
86    #[serde(skip_serializing_if = "Option::is_none")]
87    pub next_track: Option<bool>,
88    /// Previous track event.
89    #[serde(skip_serializing_if = "Option::is_none")]
90    pub prev_track: Option<bool>,
91}