feat: 1:1 Yandex ID account menu, official WordsCard AI replies, VibeResetButton pill, and git.tatar updater
This commit is contained in:
parent
682e3579ab
commit
6c30a33a9b
28 changed files with 2574 additions and 461 deletions
190
src/app/state.rs
190
src/app/state.rs
|
|
@ -1,5 +1,5 @@
|
|||
use crossbeam_channel::{unbounded, Receiver, Sender};
|
||||
use std::collections::HashSet;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::path::PathBuf;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::Arc;
|
||||
|
|
@ -344,6 +344,15 @@ pub enum AppAction {
|
|||
SetEqPopoverOpen(bool),
|
||||
OpenTrackDetailModal(Track),
|
||||
CloseTrackDetailModal,
|
||||
OpenWordsBigCard {
|
||||
track_id: String,
|
||||
},
|
||||
CloseWordsBigCard,
|
||||
SendWordsFeedback {
|
||||
track_id: String,
|
||||
card_id: String,
|
||||
state: String,
|
||||
},
|
||||
DismissOverlays,
|
||||
|
||||
// Account, Settings & Lifecycle
|
||||
|
|
@ -409,6 +418,8 @@ pub(crate) enum ApiEvent {
|
|||
result: Result<ResolvedStream, String>,
|
||||
},
|
||||
LyricsLoaded(TrackLyrics),
|
||||
WordsCardsLoaded(Vec<(String, Option<WordsCard>)>),
|
||||
WordsBigCardLoaded(Option<WordsBigCard>),
|
||||
QueueTracksHydrated(Vec<Track>),
|
||||
OAuthTokenReceived(Result<String, String>),
|
||||
PlaylistCreated {
|
||||
|
|
@ -435,7 +446,7 @@ pub(crate) enum ApiEvent {
|
|||
track: Track,
|
||||
result: Result<PathBuf, String>,
|
||||
},
|
||||
UpdateCheckFinished(Result<Option<String>, String>),
|
||||
UpdateCheckFinished(Result<Option<(String, String)>, String>),
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
|
|
@ -515,6 +526,15 @@ pub struct AppState {
|
|||
pub repeat: RepeatMode,
|
||||
pub current_lyrics: Option<TrackLyrics>,
|
||||
pub modal_lyrics: Option<TrackLyrics>,
|
||||
|
||||
// Official 5.129.0 AI WordsCard state (`POST /words/cards`, `/words/big-cards`, `PUT /words/cards/feedback`)
|
||||
pub words_cards: HashMap<String, WordsCard>,
|
||||
pub words_loading_tracks: HashSet<String>,
|
||||
pub words_empty_tracks: HashSet<String>,
|
||||
pub words_big_card: Option<WordsBigCard>,
|
||||
pub words_big_card_loading: bool,
|
||||
pub words_big_card_open: bool,
|
||||
pub words_feedback_message: Option<(String, Instant)>,
|
||||
pub current_hue: f32,
|
||||
pub target_hue: f32,
|
||||
pub smooth_sat: f32,
|
||||
|
|
@ -554,6 +574,7 @@ pub struct AppState {
|
|||
pub clear_cover_cache_requested: bool,
|
||||
pub cover_cache_capacity_dirty: bool,
|
||||
pub pending_clipboard_text: Option<String>,
|
||||
pub available_update: Option<(String, String)>,
|
||||
pub persist_enabled: bool,
|
||||
}
|
||||
|
||||
|
|
@ -650,6 +671,13 @@ impl AppState {
|
|||
repeat: RepeatMode::Off,
|
||||
current_lyrics: None,
|
||||
modal_lyrics: None,
|
||||
words_cards: HashMap::new(),
|
||||
words_loading_tracks: HashSet::new(),
|
||||
words_empty_tracks: HashSet::new(),
|
||||
words_big_card: None,
|
||||
words_big_card_loading: false,
|
||||
words_big_card_open: false,
|
||||
words_feedback_message: None,
|
||||
current_hue: 0.12,
|
||||
target_hue: 0.12,
|
||||
smooth_sat: 1.0,
|
||||
|
|
@ -683,6 +711,7 @@ impl AppState {
|
|||
clear_cover_cache_requested: false,
|
||||
cover_cache_capacity_dirty: false,
|
||||
pending_clipboard_text: None,
|
||||
available_update: None,
|
||||
persist_enabled: true,
|
||||
};
|
||||
|
||||
|
|
@ -789,6 +818,13 @@ impl AppState {
|
|||
repeat: RepeatMode::Off,
|
||||
current_lyrics: None,
|
||||
modal_lyrics: None,
|
||||
words_cards: HashMap::new(),
|
||||
words_loading_tracks: HashSet::new(),
|
||||
words_empty_tracks: HashSet::new(),
|
||||
words_big_card: None,
|
||||
words_big_card_loading: false,
|
||||
words_big_card_open: false,
|
||||
words_feedback_message: None,
|
||||
current_hue: 0.12,
|
||||
target_hue: 0.12,
|
||||
smooth_sat: 1.0,
|
||||
|
|
@ -822,6 +858,7 @@ impl AppState {
|
|||
clear_cover_cache_requested: false,
|
||||
cover_cache_capacity_dirty: false,
|
||||
pending_clipboard_text: None,
|
||||
available_update: None,
|
||||
persist_enabled: false,
|
||||
}
|
||||
}
|
||||
|
|
@ -1185,43 +1222,52 @@ impl AppState {
|
|||
})
|
||||
}
|
||||
|
||||
/// Shows real version status toast (5.129.0) & checks update endpoint asynchronously.
|
||||
/// Shows version status toast (`APP_VERSION` = `0.1.0`) & checks `git.tatar/marwy/yandex-music-rs` latest release asynchronously.
|
||||
/// If an update was already detected, clicking again opens its release page immediately.
|
||||
pub fn check_for_updates(&mut self) {
|
||||
if let Some((_, ref url)) = self.available_update {
|
||||
open_url_in_browser(url);
|
||||
}
|
||||
self.show_toast(self.i18n().toast_checking_updates());
|
||||
let tx = self.tx_api.clone();
|
||||
self.runtime.spawn(async move {
|
||||
const LATEST_RELEASE_API: &str =
|
||||
"https://git.tatar/api/v1/repos/marwy/yandex-music-rs/releases/latest";
|
||||
const LATEST_RELEASE_WEB: &str =
|
||||
"https://git.tatar/marwy/yandex-music-rs/releases/latest";
|
||||
|
||||
let client = reqwest::Client::builder()
|
||||
.timeout(Duration::from_secs(6))
|
||||
.user_agent(format!("YandexMusicDesktopAppWindows/{}", APP_VERSION))
|
||||
.user_agent(format!("yandex-music-rs/{}", APP_VERSION))
|
||||
.build();
|
||||
let res = match client {
|
||||
Ok(http) => {
|
||||
match http
|
||||
.get("https://music-desktop-application.s3.yandex.net/stable/latest.yml")
|
||||
.send()
|
||||
.await
|
||||
{
|
||||
Ok(resp) if resp.status().is_success() => {
|
||||
let body = resp.text().await.unwrap_or_default();
|
||||
let remote_ver = body.lines().find_map(|l| {
|
||||
l.trim()
|
||||
.strip_prefix("version:")
|
||||
.map(|v| v.trim().trim_matches('"').to_string())
|
||||
});
|
||||
if let Some(ref v) = remote_ver {
|
||||
if v != APP_VERSION && !v.is_empty() {
|
||||
Ok(Some(v.clone()))
|
||||
Ok(http) => match http.get(LATEST_RELEASE_API).send().await {
|
||||
Ok(resp) if resp.status().is_success() => {
|
||||
match resp.json::<serde_json::Value>().await {
|
||||
Ok(val) => {
|
||||
let tag = val["tag_name"]
|
||||
.as_str()
|
||||
.map(|s| s.trim().trim_start_matches(['v', 'V']).to_string())
|
||||
.unwrap_or_default();
|
||||
let html_url = val["html_url"]
|
||||
.as_str()
|
||||
.map(str::trim)
|
||||
.filter(|s| !s.is_empty())
|
||||
.unwrap_or(LATEST_RELEASE_WEB)
|
||||
.to_string();
|
||||
if !tag.is_empty() && is_newer_version(&tag, APP_VERSION) {
|
||||
Ok(Some((tag, html_url)))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
Err(e) => Err(e.to_string()),
|
||||
}
|
||||
Ok(resp) => Err(format!("HTTP {}", resp.status().as_u16())),
|
||||
Err(e) => Err(e.to_string()),
|
||||
}
|
||||
}
|
||||
Ok(resp) if resp.status().as_u16() == 404 => Ok(None),
|
||||
Ok(resp) => Err(format!("HTTP {}", resp.status().as_u16())),
|
||||
Err(e) => Err(e.to_string()),
|
||||
},
|
||||
Err(e) => Err(e.to_string()),
|
||||
};
|
||||
let _ = tx.send(ApiEvent::UpdateCheckFinished(res));
|
||||
|
|
@ -1670,6 +1716,7 @@ impl AppState {
|
|||
ApiEvent::AccountLoaded(Ok(acc)) => {
|
||||
self.show_toast(t.toast_welcome(&acc.display_name));
|
||||
self.account = Some(acc);
|
||||
self.ensure_words_for_current_track();
|
||||
}
|
||||
ApiEvent::AccountLoaded(Err(e)) => {
|
||||
self.show_toast(if t.is_ru() {
|
||||
|
|
@ -1918,6 +1965,23 @@ impl AppState {
|
|||
}
|
||||
}
|
||||
}
|
||||
ApiEvent::WordsCardsLoaded(entries) => {
|
||||
for (track_id, maybe_card) in entries {
|
||||
self.words_loading_tracks.remove(&track_id);
|
||||
if let Some(card) = maybe_card {
|
||||
self.words_empty_tracks.remove(&track_id);
|
||||
self.words_cards.insert(track_id, card);
|
||||
} else {
|
||||
self.words_empty_tracks.insert(track_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
ApiEvent::WordsBigCardLoaded(big) => {
|
||||
self.words_big_card_loading = false;
|
||||
if let Some(bc) = big {
|
||||
self.words_big_card = Some(bc);
|
||||
}
|
||||
}
|
||||
ApiEvent::QueueTracksHydrated(hydrated) => {
|
||||
let mut updated_any = false;
|
||||
for fresh in &hydrated {
|
||||
|
|
@ -1965,6 +2029,7 @@ impl AppState {
|
|||
if updated_any {
|
||||
self.save_playback_state();
|
||||
}
|
||||
self.ensure_words_for_current_track();
|
||||
}
|
||||
ApiEvent::OAuthTokenReceived(res) => match res {
|
||||
Ok(tok) => {
|
||||
|
|
@ -2120,8 +2185,14 @@ impl AppState {
|
|||
}
|
||||
}
|
||||
ApiEvent::UpdateCheckFinished(res) => match res {
|
||||
Ok(Some(newer)) => self.show_toast(t.toast_update_available(&newer)),
|
||||
Ok(None) => self.show_toast(t.toast_up_to_date()),
|
||||
Ok(Some((newer, url))) => {
|
||||
self.available_update = Some((newer.clone(), url));
|
||||
self.show_toast(t.toast_update_available(&newer));
|
||||
}
|
||||
Ok(None) => {
|
||||
self.available_update = None;
|
||||
self.show_toast(t.toast_latest_version());
|
||||
}
|
||||
Err(e) => {
|
||||
log::warn!("Update check failed: {}", e);
|
||||
self.show_toast(t.toast_update_check_failed());
|
||||
|
|
@ -2604,6 +2675,20 @@ impl AppState {
|
|||
AppAction::CloseTrackDetailModal => {
|
||||
self.track_detail_modal = None;
|
||||
}
|
||||
AppAction::OpenWordsBigCard { track_id } => {
|
||||
self.open_words_big_card(track_id);
|
||||
}
|
||||
AppAction::CloseWordsBigCard => {
|
||||
self.words_big_card_open = false;
|
||||
self.words_big_card_loading = false;
|
||||
}
|
||||
AppAction::SendWordsFeedback {
|
||||
track_id,
|
||||
card_id,
|
||||
state,
|
||||
} => {
|
||||
self.send_words_feedback(track_id, card_id, state);
|
||||
}
|
||||
AppAction::DismissOverlays => {
|
||||
self.fullscreen_open = false;
|
||||
self.fullscreen_lyrics_open = false;
|
||||
|
|
@ -2613,6 +2698,8 @@ impl AppState {
|
|||
self.eq_popover_open = false;
|
||||
self.playlist_modal = PlaylistModalState::None;
|
||||
self.track_detail_modal = None;
|
||||
self.words_big_card_open = false;
|
||||
self.words_big_card_loading = false;
|
||||
}
|
||||
|
||||
// Account, Settings & Lifecycle
|
||||
|
|
@ -2625,7 +2712,9 @@ impl AppState {
|
|||
self.config.language = lang;
|
||||
self.save_config();
|
||||
self.api.set_language(lang.api_code());
|
||||
self.clear_words_cache();
|
||||
self.bootstrap_api();
|
||||
self.ensure_words_for_current_track();
|
||||
}
|
||||
AppAction::ToggleLanguage => {
|
||||
let next = if self.config.language.is_ru() {
|
||||
|
|
@ -2636,7 +2725,9 @@ impl AppState {
|
|||
self.config.language = next;
|
||||
self.save_config();
|
||||
self.api.set_language(next.api_code());
|
||||
self.clear_words_cache();
|
||||
self.bootstrap_api();
|
||||
self.ensure_words_for_current_track();
|
||||
}
|
||||
AppAction::SetAudioQuality(q) => {
|
||||
self.config.audio_quality = q;
|
||||
|
|
@ -2706,6 +2797,7 @@ impl AppState {
|
|||
self.save_config();
|
||||
self.api.set_token(None);
|
||||
self.account = None;
|
||||
self.clear_words_cache();
|
||||
self.show_toast(t.toast_signed_out());
|
||||
}
|
||||
AppAction::CheckForUpdates => self.check_for_updates(),
|
||||
|
|
@ -2828,3 +2920,47 @@ pub fn vibe_bucket_primary_rgb(raw_rgb: Option<[u8; 3]>) -> [u8; 3] {
|
|||
[0xF5, 0x00, 0x2E] // carmine (340..360 or 0..2)
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_semver_tuple(raw: &str) -> Option<(u32, u32, u32)> {
|
||||
let trimmed = raw.trim().trim_start_matches(['v', 'V']);
|
||||
let core = trimmed.split(['-', '+']).next()?.trim();
|
||||
if core.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let mut parts = core.split('.');
|
||||
let major = parts.next()?.parse::<u32>().ok()?;
|
||||
let minor = match parts.next() {
|
||||
Some(s) => s.parse::<u32>().ok()?,
|
||||
None => 0,
|
||||
};
|
||||
let patch = match parts.next() {
|
||||
Some(s) => s.parse::<u32>().ok()?,
|
||||
None => 0,
|
||||
};
|
||||
Some((major, minor, patch))
|
||||
}
|
||||
|
||||
/// Returns `true` iff `remote` is strictly newer than `current` by `(major, minor, patch)` semver comparison.
|
||||
pub fn is_newer_version(remote: &str, current: &str) -> bool {
|
||||
match (parse_semver_tuple(remote), parse_semver_tuple(current)) {
|
||||
(Some(r), Some(c)) => r > c,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_is_newer_version_semver() {
|
||||
assert_eq!(APP_VERSION, "0.1.0");
|
||||
assert!(!is_newer_version("v0.1.0", "0.1.0"));
|
||||
assert!(!is_newer_version("0.1.0", "0.1.0"));
|
||||
assert!(is_newer_version("v0.1.1", "0.1.0"));
|
||||
assert!(is_newer_version("v0.2.0", "0.1.0"));
|
||||
assert!(is_newer_version("v1.0.0", "0.9.9"));
|
||||
assert!(!is_newer_version("v0.0.9", "0.1.0"));
|
||||
assert!(!is_newer_version("", "0.1.0"));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue