tauri_plugin_musickit/
models.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize)]
4#[serde(rename_all = "camelCase")]
5pub struct MusicKitTrack {
6    pub id: String,
7    pub title: String,
8    pub artist: String,
9    pub album: String,
10    pub duration: f64,
11    pub artwork_url: Option<String>,
12    pub is_explicit: bool,
13    pub is_playable: bool,
14}
15
16impl Default for MusicKitTrack {
17    fn default() -> Self {
18        Self {
19            id: String::new(),
20            title: String::new(),
21            artist: String::new(),
22            album: String::new(),
23            duration: 0.0,
24            artwork_url: None,
25            is_explicit: false,
26            is_playable: true,
27        }
28    }
29}
30
31#[derive(Debug, Clone, Serialize, Deserialize)]
32#[serde(rename_all = "camelCase")]
33pub struct MusicKitTrackData {
34    pub id: String,
35    pub title: String,
36    pub artist_name: String,
37    pub album_name: String,
38    pub genre_names: String,
39    pub artwork: String,
40    pub duration_in_millis: i32,
41}
42
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(rename_all = "camelCase")]
45pub struct AuthorizationResponse {
46    pub status: String, // "authorized", "notAuthorized", "error"
47    pub error: Option<String>,
48}
49
50#[derive(Debug, Clone, Serialize, Deserialize)]
51#[serde(rename_all = "camelCase")]
52pub struct UnauthorizeResponse {
53    pub status: String, // "unauthorized", "error"
54    pub error: Option<String>,
55}
56
57#[derive(Debug, Clone, Serialize, Deserialize)]
58#[serde(rename_all = "camelCase")]
59pub struct AuthorizationStatusResponse {
60    pub status: String, // "authorized", "notAuthorized", "notInitialized"
61}
62
63#[derive(Debug, Clone, Serialize, Deserialize)]
64#[serde(rename_all = "camelCase")]
65pub struct QueueResponse {
66    pub items: Vec<MusicKitTrack>,
67    pub position: usize,
68}
69
70#[derive(Debug, Clone, Serialize, Deserialize)]
71#[serde(rename_all = "camelCase")]
72pub struct QueueOperationResponse {
73    pub success: bool,
74    pub error: Option<String>,
75}
76
77#[derive(Debug, Clone, Serialize, Deserialize)]
78#[serde(rename_all = "camelCase")]
79pub struct StateUpdateEvent {
80    pub playing: bool,
81    pub paused: bool,
82    pub current_track: Option<MusicKitTrackData>,
83    pub current_time: f64,
84    pub duration: f64,
85    pub progress: f64, // Add progress calculation
86    pub queue_position: usize,
87    pub shuffle_mode: String,
88    pub repeat_mode: String,
89    pub volume: f64,
90}
91
92#[derive(Debug, Clone, Serialize, Deserialize)]
93#[serde(rename_all = "camelCase")]
94pub struct QueueUpdateEvent {
95    pub items: Vec<MusicKitTrack>,
96    pub position: usize,
97}
98
99#[derive(Debug, Clone, Serialize, Deserialize)]
100#[serde(rename_all = "camelCase")]
101pub struct TrackChangeEvent {
102    pub track: MusicKitTrack,
103}
104
105#[derive(Debug, Clone, Serialize, Deserialize)]
106#[serde(rename_all = "camelCase")]
107pub struct ErrorEvent {
108    pub error: String,
109    pub code: Option<String>,
110}