From 6c30a33a9b377aa626ae0147f39c40b333c5ae05 Mon Sep 17 00:00:00 2001 From: marwy Date: Fri, 27 Nov 2026 13:43:33 +0300 Subject: [PATCH] feat: 1:1 Yandex ID account menu, official WordsCard AI replies, VibeResetButton pill, and git.tatar updater --- assets/icons/profile_account_xxs.svg | 7 +- assets/icons/profile_add_account_xxs.svg | 6 + assets/icons/profile_globe_xxs.svg | 6 +- assets/icons/profile_logout_xxs.svg | 6 +- assets/icons/profile_plus_xxs.svg | 11 + assets/icons/profile_settings_xxs.svg | 4 + assets/icons/profile_support_xxs.svg | 7 +- assets/icons/theme_dark_xxs.svg | 4 +- assets/icons/theme_light_xxs.svg | 7 +- assets/icons/theme_system_xxs.svg | 6 +- assets/icons/thumb_down_xxs.svg | 3 + assets/icons/thumb_up_xxs.svg | 3 + assets/icons/yandex_id_logo_en_dark.svg | 5 + assets/icons/yandex_id_logo_en_light.svg | 5 + assets/icons/yandex_id_logo_ru_dark.svg | 5 + assets/icons/yandex_id_logo_ru_light.svg | 5 + src/api/mod.rs | 314 ++++++++ src/api/models.rs | 60 ++ src/app/i18n.rs | 46 +- src/app/playback.rs | 273 +++++++ src/app/state.rs | 190 ++++- src/icons.rs | 33 +- src/views/my_vibe.rs | 942 +++++++++++++++++++---- src/views/overlays.rs | 2 + src/views/settings.rs | 62 +- src/views/sidebar.rs | 836 ++++++++++++++------ tests/common/mod.rs | 1 + tests/parity_extended.rs | 186 +++++ 28 files changed, 2574 insertions(+), 461 deletions(-) create mode 100644 assets/icons/profile_add_account_xxs.svg create mode 100644 assets/icons/profile_plus_xxs.svg create mode 100644 assets/icons/profile_settings_xxs.svg create mode 100644 assets/icons/thumb_down_xxs.svg create mode 100644 assets/icons/thumb_up_xxs.svg create mode 100644 assets/icons/yandex_id_logo_en_dark.svg create mode 100644 assets/icons/yandex_id_logo_en_light.svg create mode 100644 assets/icons/yandex_id_logo_ru_dark.svg create mode 100644 assets/icons/yandex_id_logo_ru_light.svg diff --git a/assets/icons/profile_account_xxs.svg b/assets/icons/profile_account_xxs.svg index 7c386d9..f4f0295 100644 --- a/assets/icons/profile_account_xxs.svg +++ b/assets/icons/profile_account_xxs.svg @@ -1,4 +1,5 @@ - - - + + + + diff --git a/assets/icons/profile_add_account_xxs.svg b/assets/icons/profile_add_account_xxs.svg new file mode 100644 index 0000000..a48312c --- /dev/null +++ b/assets/icons/profile_add_account_xxs.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/assets/icons/profile_globe_xxs.svg b/assets/icons/profile_globe_xxs.svg index d92bc72..b37d0ff 100644 --- a/assets/icons/profile_globe_xxs.svg +++ b/assets/icons/profile_globe_xxs.svg @@ -1,5 +1,3 @@ - - - - + + diff --git a/assets/icons/profile_logout_xxs.svg b/assets/icons/profile_logout_xxs.svg index 58e78e8..59b3d6b 100644 --- a/assets/icons/profile_logout_xxs.svg +++ b/assets/icons/profile_logout_xxs.svg @@ -1,4 +1,4 @@ - - - + + + diff --git a/assets/icons/profile_plus_xxs.svg b/assets/icons/profile_plus_xxs.svg new file mode 100644 index 0000000..a59e83f --- /dev/null +++ b/assets/icons/profile_plus_xxs.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/assets/icons/profile_settings_xxs.svg b/assets/icons/profile_settings_xxs.svg new file mode 100644 index 0000000..94a2620 --- /dev/null +++ b/assets/icons/profile_settings_xxs.svg @@ -0,0 +1,4 @@ + + + + diff --git a/assets/icons/profile_support_xxs.svg b/assets/icons/profile_support_xxs.svg index 8f760be..16bd5b0 100644 --- a/assets/icons/profile_support_xxs.svg +++ b/assets/icons/profile_support_xxs.svg @@ -1,6 +1,3 @@ - - - - - + + diff --git a/assets/icons/theme_dark_xxs.svg b/assets/icons/theme_dark_xxs.svg index 28fbbaf..24e39d0 100644 --- a/assets/icons/theme_dark_xxs.svg +++ b/assets/icons/theme_dark_xxs.svg @@ -1,3 +1,3 @@ - - + + diff --git a/assets/icons/theme_light_xxs.svg b/assets/icons/theme_light_xxs.svg index 1019525..f041a12 100644 --- a/assets/icons/theme_light_xxs.svg +++ b/assets/icons/theme_light_xxs.svg @@ -1,4 +1,5 @@ - - - + + + + diff --git a/assets/icons/theme_system_xxs.svg b/assets/icons/theme_system_xxs.svg index 825e04f..4e20154 100644 --- a/assets/icons/theme_system_xxs.svg +++ b/assets/icons/theme_system_xxs.svg @@ -1,4 +1,4 @@ - - - + + + diff --git a/assets/icons/thumb_down_xxs.svg b/assets/icons/thumb_down_xxs.svg new file mode 100644 index 0000000..e0b5649 --- /dev/null +++ b/assets/icons/thumb_down_xxs.svg @@ -0,0 +1,3 @@ + + + diff --git a/assets/icons/thumb_up_xxs.svg b/assets/icons/thumb_up_xxs.svg new file mode 100644 index 0000000..47ad589 --- /dev/null +++ b/assets/icons/thumb_up_xxs.svg @@ -0,0 +1,3 @@ + + + diff --git a/assets/icons/yandex_id_logo_en_dark.svg b/assets/icons/yandex_id_logo_en_dark.svg new file mode 100644 index 0000000..1589681 --- /dev/null +++ b/assets/icons/yandex_id_logo_en_dark.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/assets/icons/yandex_id_logo_en_light.svg b/assets/icons/yandex_id_logo_en_light.svg new file mode 100644 index 0000000..d90a60a --- /dev/null +++ b/assets/icons/yandex_id_logo_en_light.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/assets/icons/yandex_id_logo_ru_dark.svg b/assets/icons/yandex_id_logo_ru_dark.svg new file mode 100644 index 0000000..432a5c9 --- /dev/null +++ b/assets/icons/yandex_id_logo_ru_dark.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/assets/icons/yandex_id_logo_ru_light.svg b/assets/icons/yandex_id_logo_ru_light.svg new file mode 100644 index 0000000..50f67c9 --- /dev/null +++ b/assets/icons/yandex_id_logo_ru_light.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/src/api/mod.rs b/src/api/mod.rs index 5b0951c..476b289 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -245,12 +245,19 @@ impl YandexApiClient { .as_str() .filter(|s| !s.is_empty()) .map(|id| format!("https://avatars.yandex.net/get-yapic/{}/islands-200", id)); + let default_email = res["defaultEmail"] + .as_str() + .or_else(|| res["account"]["defaultEmail"].as_str()) + .or_else(|| res["email"].as_str()) + .filter(|s| !s.is_empty()) + .map(String::from); return Ok(UserAccount { uid, login, display_name, has_plus, avatar_uri, + default_email, }); } } @@ -269,12 +276,19 @@ impl YandexApiClient { let avatar_uri = acc["avatarHash"] .as_str() .map(|h| format!("https://avatars.yandex.net/get-yapic/{}/islands-200", h)); + let default_email = acc["defaultEmail"] + .as_str() + .or_else(|| res["defaultEmail"].as_str()) + .or_else(|| acc["email"].as_str()) + .filter(|s| !s.is_empty()) + .map(String::from); Ok(UserAccount { uid, login, display_name, has_plus, avatar_uri, + default_email, }) } @@ -2362,6 +2376,234 @@ impl YandexApiClient { writers, }) } + + // ========================================================================= + // 10. OFFICIAL 5.129.0 AI WORDS CARDS (`POST /words/cards`, `/words/big-cards`, `PUT /words/cards/feedback`) + // ========================================================================= + + pub async fn fetch_words_cards( + &self, + track_ids: &[String], + wave_seeds: Option<&[String]>, + ) -> Result)>> { + if !self.has_token() || track_ids.is_empty() { + return Ok(Vec::new()); + } + let mut body = json!({ + "trackIds": track_ids, + "viewedCards": [], + "viewedBigCards": [], + "actionProvider": "alice", + }); + if let Some(seeds) = wave_seeds { + if !seeds.is_empty() { + body["waveContext"] = json!({ "seeds": seeds }); + } + } + let res = self.post_json("/words/cards", &body, false).await?; + Ok(parse_words_cards_response(&res, track_ids)) + } + + pub async fn fetch_words_big_card( + &self, + big_card_id: &str, + track_id: &str, + card_id: &str, + ) -> Result> { + if !self.has_token() || big_card_id.is_empty() { + return Ok(None); + } + let clean_track_id = track_id.split(':').next().unwrap_or(track_id); + let body = json!({ + "bigCardIds": [big_card_id], + "bigCardContexts": [{ + "bigCardId": big_card_id, + "trackId": clean_track_id, + "cardId": card_id, + }], + "actionProvider": "alice", + }); + let res = self.post_json("/words/big-cards", &body, false).await?; + Ok(parse_words_big_card_response(&res)) + } + + pub async fn send_words_feedback(&self, card_id: &str, feedback_state: &str) -> Result<()> { + if !self.has_token() || card_id.is_empty() { + return Ok(()); + } + let body = json!({ + "feedback": [{ + "id": card_id, + "feedbackState": feedback_state, + }], + }); + let _ = self.put_json("/words/cards/feedback", &body).await?; + Ok(()) + } +} + +fn parse_words_card_source(v: &Value) -> Option { + let title = v["title"].as_str().map(str::trim).filter(|s| !s.is_empty())?.to_string(); + let url = v["url"] + .as_str() + .or_else(|| v["weblink"].as_str()) + .or_else(|| v["link"].as_str()) + .map(str::trim) + .filter(|s| !s.is_empty())? + .to_string(); + let favicon_url = v["faviconUrl"] + .as_str() + .or_else(|| v["favicon_url"].as_str()) + .map(str::trim) + .filter(|s| !s.is_empty()) + .map(String::from); + Some(WordsCardSource { + title, + url, + favicon_url, + }) +} + +fn parse_words_card_entry(item: &Value, clean_track_id: &str) -> Option { + let card_obj = if item.get("card").map_or(false, Value::is_object) { + &item["card"] + } else { + item + }; + let id = value_id(&card_obj["id"]).or_else(|| value_id(&item["id"]))?; + let text = card_obj["text"] + .as_str() + .map(str::trim) + .filter(|s| !s.is_empty())? + .to_string(); + let tags = card_obj["tags"] + .as_array() + .map(|arr| { + arr.iter() + .filter_map(|t| t.as_str().map(String::from)) + .collect() + }) + .unwrap_or_default(); + let action = card_obj.get("action").and_then(|a| { + let title = a["title"].as_str().map(str::trim).filter(|s| !s.is_empty())?; + let url = a["weblink"] + .as_str() + .or_else(|| a["link"].as_str()) + .or_else(|| a["url"].as_str()) + .map(str::trim) + .filter(|s| !s.is_empty())?; + Some(WordsCardAction { + title: title.to_string(), + url: url.to_string(), + }) + }); + let actions = card_obj["actions"] + .as_array() + .map(|arr| arr.iter().filter_map(parse_words_card_source).collect()) + .unwrap_or_default(); + let big_card_ids = card_obj["bigCardIds"] + .as_array() + .map(|arr| arr.iter().filter_map(value_id).collect()) + .unwrap_or_default(); + let feedback_state = item["feedbackState"] + .as_str() + .or_else(|| card_obj["feedbackState"].as_str()) + .map(str::trim) + .filter(|s| !s.is_empty() && !s.eq_ignore_ascii_case("neutral")) + .map(String::from); + + Some(WordsCard { + id, + track_id: clean_track_id.to_string(), + text, + tags, + action, + actions, + big_card_ids, + feedback_state, + }) +} + +fn parse_words_cards_response( + val: &Value, + requested_ids: &[String], +) -> Vec<(String, Option)> { + let mut parsed_map: std::collections::HashMap> = + std::collections::HashMap::new(); + let entries = val + .as_array() + .or_else(|| val["result"].as_array()) + .or_else(|| val["tracks"].as_array()); + if let Some(arr) = entries { + for entry in arr { + let Some(raw_id) = value_id(&entry["id"]).or_else(|| value_id(&entry["trackId"])) + else { + continue; + }; + let clean_id = raw_id.split(':').next().unwrap_or(&raw_id).to_string(); + let mut chosen: Option = None; + if let Some(cards) = entry["cards"].as_array() { + let mut fallback_first: Option = None; + for c in cards { + if let Some(wc) = parse_words_card_entry(c, &clean_id) { + if !wc.is_disliked() { + chosen = Some(wc); + break; + } + if fallback_first.is_none() { + fallback_first = Some(wc); + } + } + } + if chosen.is_none() { + chosen = fallback_first; + } + } + parsed_map.insert(clean_id, chosen); + } + } + + let mut out = Vec::new(); + let mut seen = HashSet::new(); + for req in requested_ids { + let clean = req.split(':').next().unwrap_or(req).to_string(); + if seen.insert(clean.clone()) { + let card = parsed_map.remove(&clean).flatten(); + out.push((clean, card)); + } + } + for (id, card) in parsed_map { + if seen.insert(id.clone()) { + out.push((id, card)); + } + } + out +} + +fn parse_words_big_card_response(val: &Value) -> Option { + let first = val + .as_array() + .and_then(|arr| arr.first()) + .or_else(|| val["result"].as_array().and_then(|arr| arr.first())) + .unwrap_or(val); + let obj = if first.get("bigCard").map_or(false, Value::is_object) { + &first["bigCard"] + } else if first.get("card").map_or(false, Value::is_object) { + &first["card"] + } else { + first + }; + let id = value_id(&obj["id"]).or_else(|| value_id(&first["id"]))?; + let text = obj["text"] + .as_str() + .map(str::trim) + .filter(|s| !s.is_empty())? + .to_string(); + let actions = obj["actions"] + .as_array() + .map(|arr| arr.iter().filter_map(parse_words_card_source).collect()) + .unwrap_or_default(); + Some(WordsBigCard { id, text, actions }) } fn parse_writers_field(v: &Value) -> Option { @@ -2710,4 +2952,76 @@ mod tests { assert_eq!(tr.derived_average_hex.as_deref(), Some("#F56E00")); assert!(tr.has_lyrics); } + + #[test] + fn test_parse_words_cards_and_big_card() { + let payload = json!([ + { + "id": "101:555", + "cards": [ + { + "card": { + "id": "card-1", + "text": "Этот трек записали за одну ночь в студии.", + "tags": ["FACT", "HISTORY"], + "action": { + "title": "Подробнее", + "weblink": "https://music.yandex.ru/album/555" + }, + "actions": [ + { + "title": "Wikipedia", + "url": "https://ru.wikipedia.org/wiki/Test", + "faviconUrl": "https://ru.wikipedia.org/favicon.ico" + } + ], + "bigCardIds": ["big-99"] + }, + "feedbackState": "like" + } + ] + }, + { + "id": "102", + "cards": [] + } + ]); + let requested = vec!["101".to_string(), "102".to_string(), "103".to_string()]; + let parsed = parse_words_cards_response(&payload, &requested); + assert_eq!(parsed.len(), 3); + + assert_eq!(parsed[0].0, "101"); + let card = parsed[0].1.as_ref().expect("track 101 should have card"); + assert_eq!(card.id, "card-1"); + assert_eq!(card.track_id, "101"); + assert!(card.is_fact()); + assert!(card.is_liked()); + assert!(!card.is_disliked()); + assert!(card.has_big_card()); + assert_eq!(card.big_card_ids, vec!["big-99"]); + assert_eq!( + card.action.as_ref().map(|a| (a.title.as_str(), a.url.as_str())), + Some(("Подробнее", "https://music.yandex.ru/album/555")) + ); + assert_eq!(card.actions.len(), 1); + assert_eq!(card.actions[0].title, "Wikipedia"); + + assert_eq!(parsed[1], ("102".to_string(), None)); + assert_eq!(parsed[2], ("103".to_string(), None)); + + let big_payload = json!([ + { + "id": "big-99", + "text": "Полная история создания трека в деталях.", + "actions": [ + { "title": "Genius", "url": "https://genius.com/test" } + ] + } + ]); + let big = parse_words_big_card_response(&big_payload).expect("big card should parse"); + assert_eq!(big.id, "big-99"); + assert_eq!(big.text, "Полная история создания трека в деталях."); + assert_eq!(big.actions.len(), 1); + assert_eq!(big.actions[0].url, "https://genius.com/test"); + } } diff --git a/src/api/models.rs b/src/api/models.rs index df79252..a1c68c3 100644 --- a/src/api/models.rs +++ b/src/api/models.rs @@ -8,6 +8,8 @@ pub struct UserAccount { pub display_name: String, pub has_plus: bool, pub avatar_uri: Option, + #[serde(default)] + pub default_email: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -393,3 +395,61 @@ pub struct MetatagDetail { pub artists: Vec, pub playlists: Vec, } + +/// Optional clickable action link attached to an AI WordsCard (`card.action`). +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct WordsCardAction { + pub title: String, + pub url: String, +} + +/// External source citation attached to an AI WordsCard / WordsBigCard (`actions[]`). +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct WordsCardSource { + pub title: String, + pub url: String, + pub favicon_url: Option, +} + +/// Official 5.129.0 AI Track Fact / Reply card returned by `POST /words/cards`. +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct WordsCard { + pub id: String, + pub track_id: String, + pub text: String, + pub tags: Vec, + pub action: Option, + pub actions: Vec, + pub big_card_ids: Vec, + pub feedback_state: Option, +} + +impl WordsCard { + pub fn is_fact(&self) -> bool { + self.tags.iter().any(|t| t == "FACT") + } + + pub fn is_liked(&self) -> bool { + self.feedback_state + .as_deref() + .map_or(false, |s| s.eq_ignore_ascii_case("like")) + } + + pub fn is_disliked(&self) -> bool { + self.feedback_state + .as_deref() + .map_or(false, |s| s.eq_ignore_ascii_case("dislike")) + } + + pub fn has_big_card(&self) -> bool { + !self.big_card_ids.is_empty() + } +} + +/// Expanded full-screen AI fact/story card returned by `POST /words/big-cards`. +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct WordsBigCard { + pub id: String, + pub text: String, + pub actions: Vec, +} diff --git a/src/app/i18n.rs b/src/app/i18n.rs index 3a9330b..be19907 100644 --- a/src/app/i18n.rs +++ b/src/app/i18n.rs @@ -4,7 +4,7 @@ use crate::config::{Language, ThemeMode}; -pub const APP_VERSION: &str = "5.129.0"; +pub const APP_VERSION: &str = env!("CARGO_PKG_VERSION"); /// Lightweight zero-allocation localization helper bound to a `Language`. #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -589,6 +589,36 @@ impl I18n { self.pick("Неизвестный исполнитель", "Unknown artist") } + // ------------------------------------------------------------------------- + // Official 5.129.0 AI WordsCard Strings + // ------------------------------------------------------------------------- + + pub const fn words_feedback_like(self) -> &'static str { + self.pick("Спасибо за оценку", "Thank you for your rating!") + } + + pub const fn words_feedback_dislike(self) -> &'static str { + self.pick( + "Спасибо, что помогаете мне стать лучше", + "Thank you for making me become better!", + ) + } + + pub const fn words_more_similar(self) -> &'static str { + self.pick("Больше такого", "More similar replies") + } + + pub const fn words_not_cool(self) -> &'static str { + self.pick("Мимо", "Not cool") + } + + pub const fn words_ai_disclaimer(self) -> &'static str { + self.pick( + "AI может ошибаться, проверяйте важное", + "AI may make mistakes, be sure to double-check important information", + ) + } + // ------------------------------------------------------------------------- // Formatted Labels & Official Toasts (§2.7) // ------------------------------------------------------------------------- @@ -838,11 +868,21 @@ impl I18n { } } + pub fn toast_latest_version(self) -> String { + self.toast_up_to_date() + } + pub fn toast_update_available(self, newer: &str) -> String { if self.is_ru() { - format!("Доступно обновление: {} (текущая {})", newer, APP_VERSION) + format!( + "Доступно обновление: {} (текущая {}) — нажмите снова, чтобы открыть", + newer, APP_VERSION + ) } else { - format!("Update available: {} (current {})", newer, APP_VERSION) + format!( + "Update available: {} (current {}) — click again to open", + newer, APP_VERSION + ) } } diff --git a/src/app/playback.rs b/src/app/playback.rs index 76353e7..10a1999 100644 --- a/src/app/playback.rs +++ b/src/app/playback.rs @@ -76,12 +76,14 @@ impl AppState { track.r128_tp, ); self.fetch_lyrics_async(&track); + self.ensure_words_for_current_track(); return; } // Report track start to `POST /plays` self.send_play_telemetry("start"); self.fetch_lyrics_async(&track); + self.ensure_words_for_current_track(); if self.api.has_token() { let api = self.api.clone(); @@ -618,6 +620,189 @@ impl AppState { self.start_vibe_by_seeds(default_vibe, vec!["user:onyourwave".to_string()]); } + // ========================================================================= + // 1b. OFFICIAL 5.129.0 AI WORDS CARDS (Facts, Replies, BigCard & Feedback) + // ========================================================================= + + pub fn current_words_card(&self) -> Option<&WordsCard> { + let tr = self.current_track()?; + let clean_id = tr.id.split(':').next().unwrap_or(&tr.id); + self.words_cards + .get(&tr.id) + .or_else(|| self.words_cards.get(clean_id)) + } + + pub fn current_words_feedback_message(&self) -> Option<&str> { + let (ref msg, at) = self.words_feedback_message.as_ref()?; + if at.elapsed() < Duration::from_secs(3) { + Some(msg.as_str()) + } else { + None + } + } + + pub fn clear_words_cache(&mut self) { + self.words_cards.clear(); + self.words_loading_tracks.clear(); + self.words_empty_tracks.clear(); + self.words_big_card = None; + self.words_big_card_loading = false; + self.words_big_card_open = false; + self.words_feedback_message = None; + } + + pub fn ensure_words_for_current_track(&mut self) { + if !self.api.has_token() { + return; + } + let Some(curr) = self.current_track() else { + return; + }; + let curr_clean = curr.id.split(':').next().unwrap_or(&curr.id).to_string(); + if self.words_cards.contains_key(&curr_clean) + || self.words_loading_tracks.contains(&curr_clean) + || self.words_empty_tracks.contains(&curr_clean) + { + return; + } + + // Batch current track + up to 2 upcoming tracks so skipping on My Vibe feels instant! + let mut req_ids: Vec = Vec::new(); + for offset in 0..3 { + if let Some(tr) = self.queue.get(self.queue_index + offset) { + let clean = tr.id.split(':').next().unwrap_or(&tr.id).to_string(); + if !clean.is_empty() + && !self.words_cards.contains_key(&clean) + && !self.words_loading_tracks.contains(&clean) + && !self.words_empty_tracks.contains(&clean) + && !req_ids.contains(&clean) + { + self.words_loading_tracks.insert(clean.clone()); + req_ids.push(clean); + } + } + } + if req_ids.is_empty() { + return; + } + + let wave_seeds: Option> = if self.is_vibe_active { + let parsed: Vec = self + .context_key + .strip_prefix("vibe:") + .map(|s| { + s.split(',') + .map(str::trim) + .filter(|p| !p.is_empty()) + .map(String::from) + .collect() + }) + .unwrap_or_default(); + if parsed.is_empty() { + Some(vec!["user:onyourwave".to_string()]) + } else { + Some(parsed) + } + } else { + None + }; + + let api = self.api.clone(); + let tx = self.tx_api.clone(); + self.runtime.spawn(async move { + match api + .fetch_words_cards(&req_ids, wave_seeds.as_deref()) + .await + { + Ok(entries) => { + let _ = tx.send(ApiEvent::WordsCardsLoaded(entries)); + } + Err(e) => { + log::debug!("[words] /words/cards failed: {}", e); + let empty = req_ids.into_iter().map(|id| (id, None)).collect(); + let _ = tx.send(ApiEvent::WordsCardsLoaded(empty)); + } + } + }); + } + + pub fn open_words_big_card(&mut self, track_id: String) { + let clean_id = track_id.split(':').next().unwrap_or(&track_id).to_string(); + self.words_big_card_open = true; + let maybe_req = self + .words_cards + .get(&track_id) + .or_else(|| self.words_cards.get(&clean_id)) + .and_then(|c| c.big_card_ids.first().map(|bid| (bid.clone(), c.id.clone()))); + + let Some((big_card_id, card_id)) = maybe_req else { + self.words_big_card_loading = false; + return; + }; + + if self + .words_big_card + .as_ref() + .map_or(false, |bc| bc.id == big_card_id) + { + self.words_big_card_loading = false; + return; + } + + self.words_big_card = None; + if !self.api.has_token() { + self.words_big_card_loading = false; + return; + } + + self.words_big_card_loading = true; + let api = self.api.clone(); + let tx = self.tx_api.clone(); + self.runtime.spawn(async move { + let res = api + .fetch_words_big_card(&big_card_id, &clean_id, &card_id) + .await + .ok() + .flatten(); + let _ = tx.send(ApiEvent::WordsBigCardLoaded(res)); + }); + } + + pub fn send_words_feedback(&mut self, track_id: String, card_id: String, state: String) { + let clean_id = track_id.split(':').next().unwrap_or(&track_id).to_string(); + let norm_state = if state.eq_ignore_ascii_case("neutral") { + None + } else { + Some(state.clone()) + }; + let lookup_key = if self.words_cards.contains_key(&track_id) { + &track_id + } else { + &clean_id + }; + if let Some(card) = self.words_cards.get_mut(lookup_key) { + card.feedback_state = norm_state; + } + + let t = self.i18n(); + if state.eq_ignore_ascii_case("dislike") { + self.words_big_card_open = false; + self.words_big_card_loading = false; + self.words_feedback_message = + Some((t.words_feedback_dislike().to_string(), Instant::now())); + } else if state.eq_ignore_ascii_case("like") { + self.words_feedback_message = + Some((t.words_feedback_like().to_string(), Instant::now())); + } + + if self.api.has_token() && !card_id.is_empty() { + let api = self.api.clone(); + self.runtime.spawn(async move { + let _ = api.send_words_feedback(&card_id, &state).await; + }); + } + } + // ========================================================================= // 2. LIKES, DISLIKES & PINS (Playlist, Album, Artist, Liked, Wave) // ========================================================================= @@ -2272,4 +2457,92 @@ mod tests { assert!(!app.shuffle); assert_eq!(app.repeat, RepeatMode::Off); } + + #[test] + fn test_words_card_state_feedback_and_big_card() { + let tracks = vec![make_track("w1", "Track One"), make_track("w2", "Track Two")]; + let (_rt, mut app) = make_test_state(tracks); + + // Simulate WordsCardsLoaded delivering a FACT card for w1 and empty for w2 + app.words_loading_tracks.insert("w1".into()); + app.words_loading_tracks.insert("w2".into()); + let card = WordsCard { + id: "c_1".into(), + track_id: "w1".into(), + text: "Факт о треке".into(), + tags: vec!["FACT".into()], + action: None, + actions: vec![WordsCardSource { + title: "Wiki".into(), + url: "https://wikipedia.org".into(), + favicon_url: None, + }], + big_card_ids: vec!["big_1".into()], + feedback_state: None, + }; + let _ = app.tx_api.send(ApiEvent::WordsCardsLoaded(vec![ + ("w1".into(), Some(card)), + ("w2".into(), None), + ])); + assert!(app.poll_async_events()); + assert!(app.words_loading_tracks.is_empty()); + assert!(app.words_empty_tracks.contains("w2")); + + let cur = app.current_words_card().expect("w1 card should be active"); + assert!(cur.is_fact()); + assert!(cur.has_big_card()); + assert!(!cur.is_liked()); + assert!(!cur.is_disliked()); + + // Open big card & load content + app.dispatch(AppAction::OpenWordsBigCard { + track_id: "w1".into(), + }); + assert!(app.words_big_card_open); + let _ = app.tx_api.send(ApiEvent::WordsBigCardLoaded(Some(WordsBigCard { + id: "big_1".into(), + text: "Полный рассказ о треке".into(), + actions: vec![], + }))); + assert!(app.poll_async_events()); + assert!(!app.words_big_card_loading); + assert_eq!( + app.words_big_card.as_ref().map(|b| b.id.as_str()), + Some("big_1") + ); + + // Like feedback sets localized toast message + app.dispatch(AppAction::SendWordsFeedback { + track_id: "w1".into(), + card_id: "c_1".into(), + state: "like".into(), + }); + assert!(app.current_words_card().unwrap().is_liked()); + assert_eq!( + app.current_words_feedback_message(), + Some("Спасибо за оценку") + ); + + // Dislike feedback closes big card modal and sets EN message after SetLanguage(En) + app.config.language = crate::config::Language::En; + app.dispatch(AppAction::SendWordsFeedback { + track_id: "w1".into(), + card_id: "c_1".into(), + state: "dislike".into(), + }); + assert!(app.current_words_card().unwrap().is_disliked()); + assert!(!app.words_big_card_open); + assert_eq!( + app.current_words_feedback_message(), + Some("Thank you for making me become better!") + ); + + // CloseWordsBigCard & DismissOverlays clear open state + app.words_big_card_open = true; + app.dispatch(AppAction::CloseWordsBigCard); + assert!(!app.words_big_card_open); + app.words_big_card_open = true; + app.dispatch(AppAction::DismissOverlays); + assert!(!app.words_big_card_open); + } } diff --git a/src/app/state.rs b/src/app/state.rs index 5bd9caf..1de5093 100644 --- a/src/app/state.rs +++ b/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, }, LyricsLoaded(TrackLyrics), + WordsCardsLoaded(Vec<(String, Option)>), + WordsBigCardLoaded(Option), QueueTracksHydrated(Vec), OAuthTokenReceived(Result), PlaylistCreated { @@ -435,7 +446,7 @@ pub(crate) enum ApiEvent { track: Track, result: Result, }, - UpdateCheckFinished(Result, String>), + UpdateCheckFinished(Result, String>), } // ============================================================================= @@ -515,6 +526,15 @@ pub struct AppState { pub repeat: RepeatMode, pub current_lyrics: Option, pub modal_lyrics: Option, + + // Official 5.129.0 AI WordsCard state (`POST /words/cards`, `/words/big-cards`, `PUT /words/cards/feedback`) + pub words_cards: HashMap, + pub words_loading_tracks: HashSet, + pub words_empty_tracks: HashSet, + pub words_big_card: Option, + 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, + 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::().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::().ok()?; + let minor = match parts.next() { + Some(s) => s.parse::().ok()?, + None => 0, + }; + let patch = match parts.next() { + Some(s) => s.parse::().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")); + } +} diff --git a/src/icons.rs b/src/icons.rs index 7798f39..091f4da 100644 --- a/src/icons.rs +++ b/src/icons.rs @@ -113,15 +113,24 @@ pub enum Icon { PauseFilledXs, LinkXxs, YandexPlusEn, - // Dedicated Yandex ID Profile & Appearance icons + // Dedicated Yandex ID Profile & Appearance icons (v2.79.0) + WordsCard thumbs ProfileAccountXxs, + ProfileSettingsXxs, ProfileSupportXxs, ProfileGlobeXxs, ProfileAppearanceXxs, + ProfileAddAccountXxs, ProfileLogoutXxs, + ProfilePlusXxs, ThemeSystemXxs, ThemeDarkXxs, ThemeLightXxs, + ThumbUpXxs, + ThumbDownXxs, + YandexIdLogoRuDark, + YandexIdLogoRuLight, + YandexIdLogoEnDark, + YandexIdLogoEnLight, } impl Icon { @@ -234,13 +243,22 @@ impl Icon { Icon::LinkXxs => include_bytes!("../assets/icons/link_xxs.svg"), Icon::YandexPlusEn => include_bytes!("../assets/icons/yandexPlusEn.svg"), Icon::ProfileAccountXxs => include_bytes!("../assets/icons/profile_account_xxs.svg"), + Icon::ProfileSettingsXxs => include_bytes!("../assets/icons/profile_settings_xxs.svg"), Icon::ProfileSupportXxs => include_bytes!("../assets/icons/profile_support_xxs.svg"), Icon::ProfileGlobeXxs => include_bytes!("../assets/icons/profile_globe_xxs.svg"), Icon::ProfileAppearanceXxs => include_bytes!("../assets/icons/profile_appearance_xxs.svg"), + Icon::ProfileAddAccountXxs => include_bytes!("../assets/icons/profile_add_account_xxs.svg"), Icon::ProfileLogoutXxs => include_bytes!("../assets/icons/profile_logout_xxs.svg"), + Icon::ProfilePlusXxs => include_bytes!("../assets/icons/profile_plus_xxs.svg"), Icon::ThemeSystemXxs => include_bytes!("../assets/icons/theme_system_xxs.svg"), Icon::ThemeDarkXxs => include_bytes!("../assets/icons/theme_dark_xxs.svg"), Icon::ThemeLightXxs => include_bytes!("../assets/icons/theme_light_xxs.svg"), + Icon::ThumbUpXxs => include_bytes!("../assets/icons/thumb_up_xxs.svg"), + Icon::ThumbDownXxs => include_bytes!("../assets/icons/thumb_down_xxs.svg"), + Icon::YandexIdLogoRuDark => include_bytes!("../assets/icons/yandex_id_logo_ru_dark.svg"), + Icon::YandexIdLogoRuLight => include_bytes!("../assets/icons/yandex_id_logo_ru_light.svg"), + Icon::YandexIdLogoEnDark => include_bytes!("../assets/icons/yandex_id_logo_en_dark.svg"), + Icon::YandexIdLogoEnLight => include_bytes!("../assets/icons/yandex_id_logo_en_light.svg"), } } @@ -249,6 +267,10 @@ impl Icon { Icon::MusicLogoLeftEn => (276, 96), Icon::MusicLogoLeftRu => (256, 72), Icon::YandexPlusRu | Icon::YandexPlusEn => (160, 44), + Icon::YandexIdLogoRuDark + | Icon::YandexIdLogoRuLight + | Icon::YandexIdLogoEnDark + | Icon::YandexIdLogoEnLight => (124, 60), Icon::MusicLogo | Icon::PlayFilled | Icon::PauseFilled | Icon::PlayLarge | Icon::PauseLarge => (72, 72), _ => (48, 48), } @@ -368,13 +390,22 @@ impl Icon { Icon::LinkXxs, Icon::YandexPlusEn, Icon::ProfileAccountXxs, + Icon::ProfileSettingsXxs, Icon::ProfileSupportXxs, Icon::ProfileGlobeXxs, Icon::ProfileAppearanceXxs, + Icon::ProfileAddAccountXxs, Icon::ProfileLogoutXxs, + Icon::ProfilePlusXxs, Icon::ThemeSystemXxs, Icon::ThemeDarkXxs, Icon::ThemeLightXxs, + Icon::ThumbUpXxs, + Icon::ThumbDownXxs, + Icon::YandexIdLogoRuDark, + Icon::YandexIdLogoRuLight, + Icon::YandexIdLogoEnDark, + Icon::YandexIdLogoEnLight, ]; } diff --git a/src/views/my_vibe.rs b/src/views/my_vibe.rs index 27c158f..d8002bb 100644 --- a/src/views/my_vibe.rs +++ b/src/views/my_vibe.rs @@ -1,6 +1,6 @@ use std::cell::RefCell; -use crate::api::models::{format_ms, Track, VibeStationSummary}; +use crate::api::models::{format_ms, Track, VibeStationSummary, WordsCard}; use crate::api::YandexApiClient; use crate::app::i18n::APP_VERSION; use crate::app::state::{ @@ -14,8 +14,8 @@ use crate::engine::types::{ css_rgba, Color, CornerRadii, CursorKind, Pos2, Rect, Vec2, VIBE_TEXTURE_ID, }; use crate::engine::widgets::{ - draw_cover_art, ym_menu_divider, ym_menu_frame, ym_menu_item, ym_menu_item_ex, - ym_volume_capsule, + draw_cover_art, secondary_pill_button, ym_menu_divider, ym_menu_frame, ym_menu_item, + ym_menu_item_ex, ym_volume_capsule, }; use crate::engine::UiContext; use crate::icons::Icon; @@ -35,6 +35,8 @@ struct VibePageLocalState { wheel_scroll_target: Option, submenu: VibeSubmenu, submenu_anchor_y: f32, + words_popover_open: bool, + words_popover_track_id: String, } impl Default for VibePageLocalState { @@ -45,10 +47,28 @@ impl Default for VibePageLocalState { wheel_scroll_target: None, submenu: VibeSubmenu::None, submenu_anchor_y: 0.0, + words_popover_open: false, + words_popover_track_id: String::new(), } } } +const WORDS_LOADING_PHRASES_RU: &[&str] = &[ + "Собираю интересное силой ИИ", + "Настраиваюсь", + "Ловлю ритм", + "Читаю про артиста", + "Изучаю звучание", +]; + +const WORDS_LOADING_PHRASES_EN: &[&str] = &[ + "Using the AI power to collect interesting stuff", + "Getting ready", + "Getting in the rhythm", + "Reading about the artist", + "Analyzing the sound", +]; + thread_local! { static VIBE_LOCAL: RefCell = RefCell::new(VibePageLocalState::default()); } @@ -234,111 +254,74 @@ pub fn render_my_vibe( "Reset to My Vibe" }; - if is_non_vibe_context { - let ctx_style = TextStyle::bold(16.0, pal.text_bright); - let max_pill_w = (hero_rect.width() - 120.0).clamp(140.0, 420.0); - let text_w = ctx - .measure_text(&app.context_name, ctx_style, None) - .x - .min(max_pill_w - 28.0); - let pill_w = (text_w + 28.0).clamp(72.0, max_pill_w); - let total_w = pill_w + 8.0 + 28.0; - let start_x = cx - total_w * 0.5; - - let pill_r = Rect::from_xywh(start_x, top_y - 16.0, pill_w, 32.0); - let pill_resp = ctx.interact(WidgetId::new("vb_ctx_source_pill"), pill_r); - let pill_bg = if pill_resp.hovered { - pal.surface_hover + if is_non_vibe_context || is_custom_vibe_station { + // Exact official 5.129.0 `.VibeResetButton_button__i8Cvy` + `.VibeResetButton_context__hsTlv`: + // ONE unified dark translucent 44px pill (radius 22px) with electric yellow 19px Headline text + // and a filled 22px yellow circle (`×` dark `#141414` inside) on the right of the SAME pill! + let pill_label = if is_non_vibe_context { + app.context_name.as_str() } else { - pal.surface_secondary + vibe_label }; - ctx.dl().push_rect(pill_r, 16.0, pill_bg); + let yellow = if pal.is_dark { + Color::rgb(0xFF, 0xFF, 0x00) + } else { + Color::rgb(0xFF, 0xEE, 0x00) + }; + let lbl_style = TextStyle::headline(19.0, yellow); + let max_pill_w = (hero_rect.width() - 80.0).clamp(160.0, 440.0); + let max_text_w = (max_pill_w - 64.0).max(40.0); + let text_w = ctx.measure_text(pill_label, lbl_style, None).x.min(max_text_w); + let pill_w = (20.0 + text_w + 10.0 + 22.0 + 12.0).clamp(96.0, max_pill_w); + let pill_r = Rect::from_center_size(Pos2::new(cx, top_y), Vec2::new(pill_w, 44.0)); + + let close_center = Pos2::new(pill_r.right() - 12.0 - 11.0, pill_r.center_y()); + let reset_r = Rect::from_center_size(close_center, Vec2::splat(32.0)); + let reset_resp = ctx.interact(WidgetId::new("vb_ctx_reset_btn"), reset_r); + let pill_resp = ctx.interact(WidgetId::new("vb_ctx_source_pill"), pill_r); + + let pill_bg = if pill_resp.pressed || reset_resp.pressed { + css_rgba(0, 0, 0, 153) // rgba(0,0,0,0.60) + } else if pill_resp.hovered || reset_resp.hovered { + css_rgba(0, 0, 0, 102) // rgba(0,0,0,0.40) + } else { + css_rgba(0, 0, 0, 77) // rgba(0,0,0,0.30) + }; + ctx.dl().push_rect(pill_r, 22.0, pill_bg); ctx.draw_text_ellipsis( - &app.context_name, - ctx_style, + pill_label, + lbl_style, Rect::from_xywh( - pill_r.left() + 14.0, + pill_r.left() + 20.0, pill_r.top(), - (pill_r.width() - 28.0).max(20.0), + (text_w + 4.0).min(pill_r.width() - 56.0).max(20.0), pill_r.height(), ), - TextAlign::Center, + TextAlign::Left, ); - if pill_resp.hovered { - ctx.set_cursor(CursorKind::Pointer); - } - if pill_resp.clicked { - actions.push(AppAction::NavigateToCurrentContext); - } - let reset_r = Rect::from_xywh(pill_r.right() + 8.0, top_y - 14.0, 28.0, 28.0); - let reset_resp = ctx.interact(WidgetId::new("vb_ctx_reset_btn"), reset_r); - ctx.dl().push_circle( - reset_r.center(), - 14.0, - if reset_resp.hovered { - pal.surface_hover - } else { - pal.surface_secondary - }, - ); + let close_rad = if reset_resp.hovered { 11.5 } else { 11.0 }; + ctx.dl().push_circle(close_center, close_rad, yellow); ctx.draw_icon( Icon::Close, - Rect::from_center_size(reset_r.center(), Vec2::splat(14.0)), - if reset_resp.hovered { - pal.text_bright - } else { - pal.text_secondary - }, + Rect::from_center_size(close_center, Vec2::splat(12.0)), + Color::rgb(0x14, 0x14, 0x14), ); + if reset_resp.hovered { ctx.set_cursor(CursorKind::Pointer); ctx.show_tooltip(reset_r, reset_tooltip); - } - if reset_resp.clicked { - actions.push(AppAction::ResetContextToMyVibe); - } - } else if is_custom_vibe_station { - let lbl_col = if has_active_track { - pal.logo_text - } else { - pal.text_primary - }; - let lbl_style = TextStyle::headline(18.0, lbl_col); - let max_lbl_w = (hero_rect.width() - 120.0).clamp(140.0, 420.0); - let text_w = ctx.measure_text(vibe_label, lbl_style, None).x.min(max_lbl_w); - let total_w = text_w + 10.0 + 28.0; - let start_x = cx - total_w * 0.5; - - let lbl_r = Rect::from_xywh(start_x, top_y - 14.0, text_w + 4.0, 28.0); - ctx.draw_text_ellipsis(vibe_label, lbl_style, lbl_r, TextAlign::Center); - - let reset_r = Rect::from_xywh(lbl_r.right() + 8.0, top_y - 14.0, 28.0, 28.0); - let reset_resp = ctx.interact(WidgetId::new("vb_ctx_reset_btn"), reset_r); - ctx.dl().push_circle( - reset_r.center(), - 14.0, - if reset_resp.hovered { - pal.surface_hover - } else { - pal.surface_secondary - }, - ); - ctx.draw_icon( - Icon::Close, - Rect::from_center_size(reset_r.center(), Vec2::splat(14.0)), - if reset_resp.hovered { - pal.text_bright - } else { - pal.text_secondary - }, - ); - if reset_resp.hovered { + } else if pill_resp.hovered { ctx.set_cursor(CursorKind::Pointer); - ctx.show_tooltip(reset_r, reset_tooltip); } if reset_resp.clicked { actions.push(AppAction::ResetContextToMyVibe); + } else if pill_resp.clicked { + if is_non_vibe_context { + actions.push(AppAction::NavigateToCurrentContext); + } else { + actions.push(AppAction::ResetContextToMyVibe); + } } } else if playing_alpha > 0.005 && current_track.is_some() { // Default My Vibe playing: top Vibe label (`pal.logo_text`: #FFFF00 dark / #000000 light) @@ -897,83 +880,251 @@ pub fn render_my_vibe( actions.push(AppAction::Next); } - // 8. AI METEOR GLOW SETTINGS BUTTON - // Verified verbatim from `5b3a6ee99e2bd1b8.css`: + // 8. OFFICIAL 5.129.0 `WordsCard` (AI Track Facts / Replies — `4874` mod `78572`, `5b3a6ee99e2bd1b8.css`) // `.AiBadge_root__EfKG1 { width: 48px; height: 48px; }` // `.AiBadge_glow__R6cQa { opacity: 0.65; transform: translate3d(-25%, -43%, 0); }` - // `.WordsCard_root__6r3u2`: 14px medium, subtle 1.02 hover scale let ai_y = (tr_y + 100.0).min(rect.bottom() - 68.0); - let ai_rect = Rect::from_center_size(Pos2::new(cx, ai_y), Vec2::new(380.0, 48.0)); - let ai_resp = ctx.interact(WidgetId::new("vb_ai_settings"), ai_rect); - let ai_hov = ctx.animate_bool(WidgetId::new("vb_ai_hov"), ai_resp.hovered, 0.18); - let ai_scale = 1.0 + 0.02 * ai_hov; - let sp_c = Pos2::new(ai_rect.left() + 29.0, ai_y); let meteor_tex = ctx.icons.get_official_meteor_glow(&mut ctx.textures); - // Exact 180px base size at t=0 (matches lossless CDP reference) with subtle 1.0..1.04 breathing - let pulse_t = 0.5 - 0.5 * ((ctx.input.time as f32) * 1.6).cos(); + // Exact 180px base size at t=0 (matches lossless CDP reference) with gentle 1.25s alternate breathing + let pulse_t = 0.5 - 0.5 * ((ctx.input.time as f32) * (std::f32::consts::TAU / 2.5)).cos(); let glow_sz = 180.0_f32 * (1.0 + 0.04 * pulse_t); - let badge_tl = Pos2::new(sp_c.x - 24.0, sp_c.y - 24.0); - let meteor_r = Rect::from_xywh( - badge_tl.x - glow_sz * 0.25, - badge_tl.y - glow_sz * 0.43, - glow_sz, - glow_sz, - ); - ctx.dl() - .push_image(meteor_r, meteor_tex, 0.0, Color::WHITE.with_alpha(166)); - ctx.draw_icon( - Icon::AiSparkles, - Rect::from_center_size(sp_c, Vec2::splat(24.0 * ai_scale)), - pal.text_bright, - ); - let ai_lead = if ru { "Настроить " } else { "Using the " }; - let ai_rest = if ru { - "Мою волну по настроению и характеру" + + let active_words_card: Option = app.current_words_card().cloned(); + let feedback_msg: Option = app.current_words_feedback_message().map(str::to_string); + let current_tid = current_track.as_ref().map(|tr| tr.id.as_str()).unwrap_or(""); + let words_is_empty = !current_tid.is_empty() && app.words_empty_tracks.contains(current_tid); + + // Auto-close WordsCard popover whenever the active track changes or feedback toast activates + VIBE_LOCAL.with(|s| { + let mut st = s.borrow_mut(); + if st.words_popover_open && (st.words_popover_track_id != current_tid || feedback_msg.is_some()) { + st.words_popover_open = false; + } + }); + + let mut words_popover_anchor: Option<(Rect, WordsCard)> = None; + + if let Some(ref msg) = feedback_msg { + // State A — Feedback toast active (< 3s): sparkle + centered feedback message (non-clickable) + let msg_style = TextStyle::medium(14.0, pal.text_primary); + let msg_w = ctx + .measure_text(msg, msg_style, None) + .x + .min((hero_rect.width() - 120.0).max(160.0)); + let block_w = 44.0 + msg_w; + let block_l = cx - block_w * 0.5; + let sp_c = Pos2::new(block_l + 18.0, ai_y); + let badge_tl = Pos2::new(sp_c.x - 24.0, sp_c.y - 24.0); + let meteor_r = Rect::from_xywh( + badge_tl.x - glow_sz * 0.25, + badge_tl.y - glow_sz * 0.43, + glow_sz, + glow_sz, + ); + ctx.dl() + .push_image(meteor_r, meteor_tex, 0.0, Color::WHITE.with_alpha(166)); + ctx.draw_icon( + Icon::AiSparkles, + Rect::from_center_size(sp_c, Vec2::splat(24.0)), + pal.text_bright, + ); + ctx.draw_text_ellipsis( + msg, + msg_style, + Rect::from_xywh(block_l + 40.0, ai_y - 16.0, msg_w + 8.0, 32.0), + TextAlign::Left, + ); + ctx.request_repaint_after(std::time::Duration::from_millis(250)); + } else if let Some(ref card) = active_words_card.as_ref().filter(|c| !c.is_disliked()) { + // State B — Real `WordsCard` loaded for current track & not disliked! + let max_card_w = (hero_rect.width() - 64.0).clamp(320.0, 480.0); + let text_max_w = (max_card_w - 60.0).max(200.0); + let text_style_base = TextStyle::medium(14.0, pal.text_primary).with_line_height(19.0); + let measured_text = ctx.measure_text(&card.text, text_style_base, Some(text_max_w)); + let text_h = measured_text.y.clamp(20.0, 58.0); + let has_action = card.action.is_some(); + let action_h = if has_action { 22.0 } else { 0.0 }; + let card_h = (text_h + action_h + 10.0).clamp(48.0, 92.0); + let card_w = (measured_text.x + 64.0).clamp(240.0, max_card_w); + let card_cy = ai_y.min(rect.bottom() - card_h * 0.5 - 12.0); + let card_r = Rect::from_center_size(Pos2::new(cx, card_cy), Vec2::new(card_w, card_h)); + + let card_resp = ctx.interact(WidgetId::new("vb_words_card"), card_r); + let ai_hov = ctx.animate_bool(WidgetId::new("vb_words_hov"), card_resp.hovered, 0.18); + let ai_scale = 1.0 + 0.02 * ai_hov; + + let sp_c = Pos2::new(card_r.left() + 24.0, card_r.center_y()); + let badge_tl = Pos2::new(sp_c.x - 24.0, sp_c.y - 24.0); + let meteor_r = Rect::from_xywh( + badge_tl.x - glow_sz * 0.25, + badge_tl.y - glow_sz * 0.43, + glow_sz, + glow_sz, + ); + ctx.dl() + .push_image(meteor_r, meteor_tex, 0.0, Color::WHITE.with_alpha(166)); + ctx.draw_icon( + Icon::AiSparkles, + Rect::from_center_size(sp_c, Vec2::splat(24.0 * ai_scale)), + pal.text_bright, + ); + + let text_x = card_r.left() + 50.0; + let text_w = (card_r.right() - text_x - 8.0).max(120.0); + let text_top = card_r.center_y() - (text_h + action_h) * 0.5; + let card_text_col = if card_resp.hovered { + pal.text_bright + } else { + pal.text_primary + }; + let card_text_style = TextStyle::medium(14.0 * ai_scale, card_text_col) + .with_line_height(19.0 * ai_scale); + ctx.draw_text_wrapped( + &card.text, + card_text_style, + Rect::from_xywh(text_x, text_top, text_w, text_h + 4.0), + Some(3), + TextAlign::Left, + ); + + let mut action_clicked = false; + if let Some(ref act) = card.action { + let act_r = Rect::from_xywh(text_x, text_top + text_h + 2.0, text_w, 20.0); + let act_resp = ctx.interact(WidgetId::new("vb_words_action"), act_r); + ctx.draw_text_ellipsis( + &act.title, + TextStyle::medium( + 13.0, + if act_resp.hovered { + pal.text_bright + } else { + pal.logo_text + }, + ), + act_r, + TextAlign::Left, + ); + if act_resp.hovered { + ctx.set_cursor(CursorKind::Pointer); + } + if act_resp.clicked && !act.url.is_empty() { + actions.push(AppAction::OpenUrl(act.url.clone())); + action_clicked = true; + } + } + + if card_resp.hovered { + ctx.set_cursor(CursorKind::Pointer); + } + if card_resp.clicked && !action_clicked { + if card.has_big_card() { + VIBE_LOCAL.with(|s| s.borrow_mut().words_popover_open = false); + actions.push(AppAction::OpenWordsBigCard { + track_id: card.track_id.clone(), + }); + } else { + shell.close_all_menus(); + VIBE_LOCAL.with(|s| { + let mut st = s.borrow_mut(); + st.words_popover_open = !st.words_popover_open; + st.words_popover_track_id = card.track_id.clone(); + }); + } + } + + words_popover_anchor = Some((card_r, (*card).clone())); + } else if words_is_empty || active_words_card.as_ref().map_or(false, |c| c.is_disliked()) { + // State C — Resolved empty OR card disliked: centered dimmed sparkle badge (opacity 0.50, non-clickable) + let sp_c = Pos2::new(cx, ai_y); + let badge_tl = Pos2::new(sp_c.x - 24.0, sp_c.y - 24.0); + let meteor_r = Rect::from_xywh( + badge_tl.x - glow_sz * 0.25, + badge_tl.y - glow_sz * 0.43, + glow_sz, + glow_sz, + ); + ctx.dl() + .push_image(meteor_r, meteor_tex, 0.0, Color::WHITE.with_alpha(72)); + ctx.draw_icon( + Icon::AiSparkles, + Rect::from_center_size(sp_c, Vec2::splat(24.0)), + pal.text_bright.scale_alpha(0.50), + ); } else { - "AI power to collect interesting stuff" - }; - let ai_fs = 14.0 * ai_scale; - let ai_spans = [ - RichSpan::new( - ai_lead, - TextStyle::medium( - ai_fs, - if ai_resp.hovered { - pal.text_primary - } else { - pal.text_secondary - }, - ), - ), - RichSpan::new( - ai_rest, - TextStyle::medium( - ai_fs, - if ai_resp.hovered { - pal.text_bright - } else { - pal.text_primary - }, - ), - ), - ]; - let ai_text_r = Rect::from_xywh( - ai_rect.left() + 56.0, - ai_rect.top(), - ai_rect.width() - 60.0, - ai_rect.height(), - ); - ctx.draw_rich_text(&ai_spans, ai_text_r, Some(1), TextAlign::Left); - if ai_resp.hovered { - ctx.set_cursor(CursorKind::Pointer); - } - if ai_resp.clicked { - actions.push(AppAction::SetVibeModalOpen(true)); + // State D — Loading OR offline visual fixture: official rotating 5.129.0 `words.loading-phrase-*` + // (Index 0 at `t == 0.0` matches `my_vibe.jpg` & lossless CDP `test_ext_02` pixel-for-pixel; + // clicking while loading does NOTHING — zero fake Vibe-settings modal!) + let ai_rect = Rect::from_center_size(Pos2::new(cx, ai_y), Vec2::new(380.0, 48.0)); + let sp_c = Pos2::new(ai_rect.left() + 29.0, ai_y); + let badge_tl = Pos2::new(sp_c.x - 24.0, sp_c.y - 24.0); + let meteor_r = Rect::from_xywh( + badge_tl.x - glow_sz * 0.25, + badge_tl.y - glow_sz * 0.43, + glow_sz, + glow_sz, + ); + ctx.dl() + .push_image(meteor_r, meteor_tex, 0.0, Color::WHITE.with_alpha(166)); + ctx.draw_icon( + Icon::AiSparkles, + Rect::from_center_size(sp_c, Vec2::splat(24.0)), + pal.text_bright, + ); + let phrases = if ru { + WORDS_LOADING_PHRASES_RU + } else { + WORDS_LOADING_PHRASES_EN + }; + let phrase_idx = if ctx.input.time <= 0.001 { + 0 + } else { + ((ctx.input.time / 2.5).floor() as usize) % phrases.len() + }; + let ai_text_r = Rect::from_xywh( + ai_rect.left() + 56.0, + ai_rect.top(), + ai_rect.width() - 60.0, + ai_rect.height(), + ); + if phrase_idx == 0 { + let (lead, rest) = if ru { + ("Собираю ", "интересное силой ИИ") + } else { + ("Using the ", "AI power to collect interesting stuff") + }; + let ai_spans = [ + RichSpan::new(lead, TextStyle::medium(14.0, pal.text_secondary)), + RichSpan::new(rest, TextStyle::medium(14.0, pal.text_primary)), + ]; + ctx.draw_rich_text(&ai_spans, ai_text_r, Some(1), TextAlign::Left); + } else { + ctx.draw_text_ellipsis( + phrases[phrase_idx], + TextStyle::medium(14.0, pal.text_primary), + ai_text_r, + TextAlign::Left, + ); + } + if ctx.input.time > 0.001 && !current_tid.is_empty() && app.words_loading_tracks.contains(current_tid) { + ctx.request_repaint_after(std::time::Duration::from_millis(80)); + } } - // 9. BOTTOM-RIGHT VERSION BADGE (`5.129.0`, theme-aware `pal.surface_secondary` + `pal.text_secondary`) - let ver_style = TextStyle::medium(13.0, pal.text_secondary); - let ver_w = (ctx.measure_text(APP_VERSION, ver_style, None).x + 22.0) + // 9. BOTTOM-RIGHT VERSION BADGE (`APP_VERSION` = `0.1.0`, or `0.1.0 → {ver}` when update available!) + let (ver_label, ver_col) = if let Some((ref new_ver, _)) = app.available_update { + ( + format!("{} → {}", APP_VERSION, new_ver), + if pal.is_dark { + pal.yellow + } else { + pal.outline_selected + }, + ) + } else { + (APP_VERSION.to_string(), pal.text_secondary) + }; + let ver_style = TextStyle::medium(13.0, ver_col); + let ver_w = (ctx.measure_text(&ver_label, ver_style, None).x + 22.0) .max(68.0) .ceil(); let ver_r = Rect::from_xywh( @@ -992,7 +1143,7 @@ pub fn render_my_vibe( pal.surface_secondary }, ); - ctx.draw_text_ellipsis(APP_VERSION, ver_style, ver_r, TextAlign::Center); + ctx.draw_text_ellipsis(&ver_label, ver_style, ver_r, TextAlign::Center); if ver_resp.hovered { ctx.set_cursor(CursorKind::Pointer); } @@ -1340,6 +1491,479 @@ pub fn render_my_vibe( actions, ); } + + // 12. OFFICIAL 5.129.0 `WordsCardPopoverDesktop` (floating 12px above `WordsCard`, `ZLayer::Popover`) + let words_pop_open = VIBE_LOCAL.with(|s| s.borrow().words_popover_open); + if words_pop_open { + if let Some((anchor_r, ref card)) = words_popover_anchor { + render_words_card_popover(ctx, pal, ru, anchor_r, card, actions); + } else { + VIBE_LOCAL.with(|s| s.borrow_mut().words_popover_open = false); + } + } + + // 13. OFFICIAL 5.129.0 `WordsCardFullscreen` (`ZLayer::Modal` when `app.words_big_card_open`) + if app.words_big_card_open { + render_words_card_fullscreen(ctx, pal, app, ru, active_words_card.as_ref(), actions); + } +} + +fn render_words_card_popover( + ctx: &mut UiContext, + pal: &YmPalette, + ru: bool, + anchor_rect: Rect, + card: &WordsCard, + actions: &mut Vec, +) { + let pop_w = 260.0_f32; + let item_h = 36.0_f32; + let div_h = 13.0_f32; + let src_count = card.actions.len().min(5); + let mut pop_h = 16.0 + 2.0 * item_h; + if src_count > 0 { + pop_h += src_count as f32 * item_h + div_h; + } + let disclaimer_text = if ru { + "AI может ошибаться, проверяйте важное" + } else { + "AI may make mistakes, be sure to double-check important information" + }; + let disclaimer_h = if card.is_fact() { + let mh = ctx + .measure_text( + disclaimer_text, + TextStyle::regular(12.0, pal.text_secondary).with_line_height(16.0), + Some(pop_w - 32.0), + ) + .y + .clamp(18.0, 40.0); + pop_h += div_h + mh + 8.0; + mh + } else { + 0.0 + }; + + let screen = ctx.screen_rect(); + let pop_x = (anchor_rect.center_x() - pop_w * 0.5) + .clamp(screen.left() + 12.0, (screen.right() - pop_w - 12.0).max(screen.left() + 12.0)); + let pop_y = (anchor_rect.top() - pop_h - 12.0).clamp(40.0, (screen.bottom() - pop_h - 12.0).max(40.0)); + let pop_rect = Rect::from_xywh(pop_x, pop_y, pop_w, pop_h); + + let mut close_pop = false; + ctx.with_layer(ZLayer::Popover, |ctx| { + let inner = ym_menu_frame(ctx, pal, pop_rect); + let mut y = inner.top(); + let w = inner.width(); + + if src_count > 0 { + for (idx, src) in card.actions.iter().take(src_count).enumerate() { + let r = Rect::from_xywh(inner.left(), y, w, item_h); + y += item_h; + if ym_menu_item( + ctx, + pal, + WidgetId::from_pair("wcp_src", idx), + r, + Icon::LinkXxs, + &src.title, + false, + false, + ) + .clicked + { + if !src.url.is_empty() { + actions.push(AppAction::OpenUrl(src.url.clone())); + } + close_pop = true; + } + } + ym_menu_divider(ctx, pal, Rect::from_xywh(inner.left(), y, w, div_h)); + y += div_h; + } + + let like_lbl = if ru { + "Больше такого" + } else { + "More similar replies" + }; + let dislike_lbl = if ru { "Мимо" } else { "Not cool" }; + + let r_like = Rect::from_xywh(inner.left(), y, w, item_h); + y += item_h; + if ym_menu_item( + ctx, + pal, + WidgetId::new("wcp_like"), + r_like, + Icon::ThumbUpXxs, + like_lbl, + card.is_liked(), + false, + ) + .clicked + { + actions.push(AppAction::SendWordsFeedback { + track_id: card.track_id.clone(), + card_id: card.id.clone(), + state: if card.is_liked() { + "neutral".into() + } else { + "like".into() + }, + }); + close_pop = true; + } + + let r_dislike = Rect::from_xywh(inner.left(), y, w, item_h); + y += item_h; + if ym_menu_item( + ctx, + pal, + WidgetId::new("wcp_dislike"), + r_dislike, + Icon::ThumbDownXxs, + dislike_lbl, + card.is_disliked(), + false, + ) + .clicked + { + actions.push(AppAction::SendWordsFeedback { + track_id: card.track_id.clone(), + card_id: card.id.clone(), + state: "dislike".into(), + }); + close_pop = true; + } + + if card.is_fact() { + ym_menu_divider(ctx, pal, Rect::from_xywh(inner.left(), y, w, div_h)); + y += div_h + 2.0; + ctx.draw_text_wrapped( + disclaimer_text, + TextStyle::regular(12.0, pal.text_secondary).with_line_height(16.0), + Rect::from_xywh(inner.left() + 8.0, y, w - 16.0, disclaimer_h + 4.0), + Some(3), + TextAlign::Center, + ); + } + + if ctx.input.clicked_outside_any(&[pop_rect, anchor_rect]) + || ctx.input.key_pressed(Key::Escape) + { + close_pop = true; + } + }); + + if close_pop { + VIBE_LOCAL.with(|s| s.borrow_mut().words_popover_open = false); + } +} + +fn render_words_card_fullscreen( + ctx: &mut UiContext, + pal: &YmPalette, + app: &AppState, + ru: bool, + fallback_card: Option<&WordsCard>, + actions: &mut Vec, +) { + let screen = ctx.screen_rect(); + let mut should_close = false; + + ctx.with_layer(ZLayer::Modal, |ctx| { + ctx.register_blocker(screen); + ctx.dl().push_backdrop_blur( + screen, + 0.0, + 4.0, + pal.bg_overlay, + 0.0, + Color::TRANSPARENT, + ); + + // Top-right circular Close `×` button + let close_r = Rect::from_center_size( + Pos2::new(screen.right() - 40.0, screen.top() + 56.0), + Vec2::splat(40.0), + ); + let close_resp = ctx.interact(WidgetId::new("wcf_close"), close_r); + ctx.dl().push_circle( + close_r.center(), + 20.0, + if close_resp.hovered { + pal.surface_hover + } else { + pal.surface_secondary + }, + ); + ctx.draw_icon( + Icon::Close, + Rect::from_center_size(close_r.center(), Vec2::splat(18.0)), + if close_resp.hovered { + pal.text_bright + } else { + pal.text_primary + }, + ); + if close_resp.hovered { + ctx.set_cursor(CursorKind::Pointer); + } + if close_resp.clicked { + should_close = true; + } + + let col_w = (screen.width() - 96.0).clamp(300.0, 540.0); + let modal_h = (screen.height() - 140.0).clamp(320.0, 580.0); + let content_rect = Rect::from_center_size(screen.center(), Vec2::new(col_w + 48.0, modal_h)); + let col_x = content_rect.center_x() - col_w * 0.5; + let mut y = content_rect.top() + 18.0; + + // Top AI sparkle badge with soft meteor glow + let sp_c = Pos2::new(content_rect.center_x(), y + 20.0); + let meteor_tex = ctx.icons.get_official_meteor_glow(&mut ctx.textures); + let badge_tl = Pos2::new(sp_c.x - 24.0, sp_c.y - 24.0); + ctx.dl().push_image( + Rect::from_xywh(badge_tl.x - 180.0 * 0.25, badge_tl.y - 180.0 * 0.43, 180.0, 180.0), + meteor_tex, + 0.0, + Color::WHITE.with_alpha(150), + ); + ctx.draw_icon( + Icon::AiSparkles, + Rect::from_center_size(sp_c, Vec2::splat(28.0)), + pal.text_bright, + ); + y += 64.0; + + if app.words_big_card_loading { + // 3 subtle animated shimmer bars while `POST /words/big-cards` loads + let shimmer = 0.5 + 0.5 * ((ctx.input.time as f32) * 3.2).sin(); + let a = (28.0 + 36.0 * shimmer).round() as u8; + let bar_col = if pal.is_dark { + css_rgba(255, 255, 255, a) + } else { + css_rgba(0, 0, 0, a) + }; + for (i, frac) in [0.88_f32, 1.0_f32, 0.64_f32].iter().enumerate() { + let bw = col_w * frac; + let br = Rect::from_xywh( + content_rect.center_x() - bw * 0.5, + y + i as f32 * 30.0, + bw, + 18.0, + ); + ctx.dl().push_rect(br, 9.0, bar_col); + } + ctx.request_repaint(); + } else { + let full_text = app + .words_big_card + .as_ref() + .map(|b| b.text.as_str()) + .filter(|s| !s.is_empty()) + .or_else(|| fallback_card.map(|c| c.text.as_str())) + .unwrap_or(""); + let sources = app + .words_big_card + .as_ref() + .filter(|b| !b.actions.is_empty()) + .map(|b| b.actions.as_slice()) + .or_else(|| fallback_card.map(|c| c.actions.as_slice())) + .unwrap_or(&[]); + + let bottom_reserved = if sources.is_empty() { 104.0 } else { 154.0 }; + let text_vp_h = (content_rect.bottom() - y - bottom_reserved).max(120.0); + let text_vp = Rect::from_xywh(col_x, y, col_w, text_vp_h); + let text_style = TextStyle::bold(20.0, pal.text_bright).with_line_height(28.0); + let measured = ctx.measure_text(full_text, text_style, Some(col_w)); + + let scroll_id = WidgetId::new("wcf_text_scroll"); + let scroll_y = ctx.begin_scroll_v(scroll_id, text_vp, 0.0); + let ty = if measured.y < text_vp_h { + text_vp.center_y() - measured.y * 0.5 + } else { + text_vp.top() - scroll_y + }; + ctx.draw_text_wrapped( + full_text, + text_style, + Rect::from_xywh(col_x, ty, col_w, measured.y + 12.0), + None, + TextAlign::Center, + ); + ctx.end_scroll_v(scroll_id, pal, measured.y + 16.0, false); + y = text_vp.bottom() + 16.0; + + // Optional source link pills + if !sources.is_empty() { + let mut sx = col_x; + let max_right = col_x + col_w; + for (idx, src) in sources.iter().take(4).enumerate() { + let est_w = (ctx + .measure_text(&src.title, TextStyle::medium(13.5, pal.text_primary), None) + .x + + 50.0) + .clamp(80.0, col_w); + if sx + est_w > max_right && sx > col_x { + break; + } + let (resp, r) = secondary_pill_button( + ctx, + pal, + WidgetId::from_pair("wcf_src", idx), + Pos2::new(sx, y), + Some(Icon::LinkXxs), + &src.title, + 34.0, + false, + ); + if resp.clicked && !src.url.is_empty() { + actions.push(AppAction::OpenUrl(src.url.clone())); + } + sx = r.right() + 8.0; + } + y += 46.0; + } + + // Horizontal feedback bar: 👍 More similar replies | 1px divider | 👎 Not cool + if let Some(card) = fallback_card { + let like_lbl = if ru { + "Больше такого" + } else { + "More similar replies" + }; + let dislike_lbl = if ru { "Мимо" } else { "Not cool" }; + let btn_h = 38.0; + let like_w = (ctx + .measure_text(like_lbl, TextStyle::medium(14.0, pal.text_primary), None) + .x + + 54.0) + .max(120.0); + let dislike_w = (ctx + .measure_text(dislike_lbl, TextStyle::medium(14.0, pal.text_primary), None) + .x + + 54.0) + .max(100.0); + let bar_w = like_w + 25.0 + dislike_w; + let bar_x = content_rect.center_x() - bar_w * 0.5; + + let like_r = Rect::from_xywh(bar_x, y, like_w, btn_h); + let like_resp = ctx.interact(WidgetId::new("wcf_like"), like_r); + ctx.dl().push_rect( + like_r, + 19.0, + if like_resp.hovered || card.is_liked() { + pal.surface_hover + } else { + pal.surface_secondary + }, + ); + let like_fg = if card.is_liked() || like_resp.hovered { + pal.text_bright + } else { + pal.text_primary + }; + ctx.draw_icon( + Icon::ThumbUpXxs, + Rect::from_center_size(Pos2::new(like_r.left() + 22.0, like_r.center_y()), Vec2::splat(18.0)), + like_fg, + ); + ctx.draw_text_ellipsis( + like_lbl, + TextStyle::medium(14.0, like_fg), + Rect::from_xywh(like_r.left() + 38.0, like_r.top(), like_r.width() - 48.0, like_r.height()), + TextAlign::Left, + ); + if like_resp.hovered { + ctx.set_cursor(CursorKind::Pointer); + } + if like_resp.clicked { + actions.push(AppAction::SendWordsFeedback { + track_id: card.track_id.clone(), + card_id: card.id.clone(), + state: if card.is_liked() { + "neutral".into() + } else { + "like".into() + }, + }); + } + + // 1px vertical divider + let div_x = like_r.right() + 12.0; + ctx.dl().push_rect( + Rect::from_xywh(div_x, y + 7.0, 1.0, 24.0), + 0.0, + pal.border_subtle, + ); + + let dislike_r = Rect::from_xywh(div_x + 13.0, y, dislike_w, btn_h); + let dislike_resp = ctx.interact(WidgetId::new("wcf_dislike"), dislike_r); + ctx.dl().push_rect( + dislike_r, + 19.0, + if dislike_resp.hovered || card.is_disliked() { + pal.surface_hover + } else { + pal.surface_secondary + }, + ); + let dislike_fg = if card.is_disliked() || dislike_resp.hovered { + pal.text_bright + } else { + pal.text_primary + }; + ctx.draw_icon( + Icon::ThumbDownXxs, + Rect::from_center_size(Pos2::new(dislike_r.left() + 22.0, dislike_r.center_y()), Vec2::splat(18.0)), + dislike_fg, + ); + ctx.draw_text_ellipsis( + dislike_lbl, + TextStyle::medium(14.0, dislike_fg), + Rect::from_xywh(dislike_r.left() + 38.0, dislike_r.top(), dislike_r.width() - 48.0, dislike_r.height()), + TextAlign::Left, + ); + if dislike_resp.hovered { + ctx.set_cursor(CursorKind::Pointer); + } + if dislike_resp.clicked { + actions.push(AppAction::SendWordsFeedback { + track_id: card.track_id.clone(), + card_id: card.id.clone(), + state: "dislike".into(), + }); + } + y += btn_h + 18.0; + } + + // Bottom AI disclaimer + let disclaimer = if ru { + "AI может ошибаться, проверяйте важное" + } else { + "AI may make mistakes, be sure to double-check important information" + }; + ctx.draw_text_wrapped( + disclaimer, + TextStyle::regular(12.5, pal.text_secondary).with_line_height(17.0), + Rect::from_xywh(col_x, y, col_w, 36.0), + Some(2), + TextAlign::Center, + ); + } + + if ctx.input.key_pressed(Key::Escape) + || ctx.input.clicked_outside_any(&[content_rect, close_r]) + { + should_close = true; + } + }); + + if should_close { + actions.push(AppAction::CloseWordsBigCard); + } } #[allow(clippy::too_many_arguments)] diff --git a/src/views/overlays.rs b/src/views/overlays.rs index 71ce6b1..eea7cde 100644 --- a/src/views/overlays.rs +++ b/src/views/overlays.rs @@ -67,6 +67,7 @@ pub struct ShellUiState { pub entity_share_submenu_open: bool, pub sidebar_profile_open: bool, pub sidebar_appearance_open: bool, + pub sidebar_lang_open: bool, pub sidebar_pin_menu: Option<(usize, Pos2)>, pub vibe_menu_open: bool, pub vibe_vol_open: bool, @@ -172,6 +173,7 @@ impl ShellUiState { self.entity_share_submenu_open = false; self.sidebar_profile_open = false; self.sidebar_appearance_open = false; + self.sidebar_lang_open = false; self.sidebar_pin_menu = None; self.vibe_menu_open = false; self.vibe_vol_open = false; diff --git a/src/views/settings.rs b/src/views/settings.rs index aa2aa7b..26f8ff7 100644 --- a/src/views/settings.rs +++ b/src/views/settings.rs @@ -622,9 +622,9 @@ pub fn render_settings( y += sc_h + 14.0; // ------------------------------------------------------------------------- - // 7. About 5.129.0 & Cache + // 7. About & Updates (`git.tatar/marwy/yandex-music-rs`) & Cache // ------------------------------------------------------------------------- - let about_h = 148.0; + let about_h = 172.0; let about_inner = draw_settings_card( ctx, pal, @@ -634,9 +634,9 @@ pub fn render_settings( { let mut cy = about_inner.top(); let ver_str = if ru { - format!("Яндекс Музыка · Версия {}", APP_VERSION) + format!("yandex-music-rs · Версия {}", APP_VERSION) } else { - format!("Yandex Music · Version {}", APP_VERSION) + format!("yandex-music-rs · Version {}", APP_VERSION) }; ctx.draw_text_ellipsis( &ver_str, @@ -645,10 +645,41 @@ pub fn render_settings( TextAlign::Left, ); cy += 24.0; + let repo_label = "git.tatar/marwy/yandex-music-rs"; + let repo_w = ctx + .measure_text(repo_label, TextStyle::medium(13.0, pal.text_secondary), None) + .x + + 8.0; + let repo_r = Rect::from_xywh(about_inner.left(), cy, repo_w.min(about_inner.width()), 20.0); + let repo_resp = ctx.interact(WidgetId::new("set_repo_link"), repo_r); + ctx.draw_text_ellipsis( + repo_label, + TextStyle::medium( + 13.0, + if repo_resp.hovered { + pal.text_bright + } else if pal.is_dark { + pal.yellow + } else { + pal.outline_selected + }, + ), + repo_r, + TextAlign::Left, + ); + if repo_resp.hovered { + ctx.set_cursor(CursorKind::Pointer); + } + if repo_resp.clicked { + actions.push(AppAction::OpenUrl( + "https://git.tatar/marwy/yandex-music-rs".into(), + )); + } + cy += 22.0; let cache_str = if ru { - format!("© Яндекс · Кэш обложек: {} шт.", covers.len()) + format!("Кэш обложек: {} шт.", covers.len()) } else { - format!("© Yandex · Cover cache: {} items", covers.len()) + format!("Cover cache: {} items", covers.len()) }; ctx.draw_text_ellipsis( &cache_str, @@ -658,19 +689,26 @@ pub fn render_settings( ); cy += 28.0; + let upd_label = if let Some((ref new_ver, _)) = app.available_update { + if ru { + format!("Обновить до {}", new_ver) + } else { + format!("Update to {}", new_ver) + } + } else if ru { + "Проверить обновления".to_string() + } else { + "Check for updates".to_string() + }; let (upd_resp, upd_r) = secondary_pill_button( ctx, pal, WidgetId::new("set_check_updates"), Pos2::new(about_inner.left(), cy), None, - if ru { - "Проверить обновления" - } else { - "Check for updates" - }, + &upd_label, 36.0, - false, + app.available_update.is_some(), ); if upd_resp.clicked { actions.push(AppAction::CheckForUpdates); diff --git a/src/views/sidebar.rs b/src/views/sidebar.rs index 8159571..0e7f8c4 100644 --- a/src/views/sidebar.rs +++ b/src/views/sidebar.rs @@ -1,9 +1,8 @@ use crate::app::{AppAction, AppState, Route}; -use crate::config::{PinnedItem, ThemeMode}; +use crate::config::{Language, PinnedItem, ThemeMode}; use crate::covers::CoverCache; use crate::engine::widgets::{ draw_cover_art, draw_plus_avatar_ring, draw_plus_badge, ym_menu_frame, ym_menu_item, - ym_menu_item_ex, }; use crate::engine::{ css_rgba, Color, CursorKind, Pos2, Rect, TextAlign, TextStyle, UiContext, Vec2, WidgetId, @@ -589,7 +588,17 @@ pub fn render_sidebar( } if shell.sidebar_profile_open { - render_profile_card_popup(ctx, pal, app, shell, sidebar_rect, footer_rect, profile_hit, actions); + render_profile_card_popup( + ctx, + pal, + covers, + app, + shell, + sidebar_rect, + footer_rect, + profile_hit, + actions, + ); } } @@ -616,11 +625,14 @@ fn is_pin_active_route(pin: &PinnedItem, app: &AppState) -> bool { } } -/// 100% Theme-aware Yandex ID Profile Card Popup + 3-way Appearance Submenu (`Как в системе` / `Тёмная` / `Светлая`) +/// 1-to-1 Official Yandex ID `/music` Account Popup (v2.79.0) — Dark & Light themes, +/// exact surface/text/hover tokens, centered 56px Plus-ring avatar, dynamic Appearance icon, +/// Language popover (`ru`/`en`), and 3-way Appearance popover (`Всегда светлый` / `Всегда тёмный` / `Как в системе`). #[allow(clippy::too_many_arguments)] fn render_profile_card_popup( ctx: &mut UiContext, pal: &YmPalette, + covers: &mut CoverCache, app: &AppState, shell: &mut ShellUiState, sidebar_rect: Rect, @@ -630,118 +642,233 @@ fn render_profile_card_popup( ) { let i18n = app.i18n(); let ru = i18n.is_ru(); + let is_dark = pal.is_dark; let has_plus = app.account.as_ref().map_or(false, |a| a.has_plus); let logged_in = app.account.is_some(); + // Exact Yandex ID v2.79.0 Surface & Color Tokens (`307ea1c94a69877eefe9.css`) + let card_bg = if is_dark { + Color::rgb(0x1F, 0x1F, 0x24) + } else { + Color::WHITE + }; + let card_border = if is_dark { + Color::rgb(0x33, 0x33, 0x33) + } else { + Color::rgb(0xE6, 0xE6, 0xE6) + }; + let popover_bg = if is_dark { + Color::rgb(0x2D, 0x2D, 0x34) + } else { + Color::WHITE + }; + let popover_border = if is_dark { + css_rgba(250, 250, 255, 26) + } else { + Color::rgb(0xE6, 0xE6, 0xE6) + }; + let id_text_primary = if is_dark { + Color::rgb(0xFA, 0xFA, 0xFF) + } else { + Color::rgb(0x26, 0x26, 0x33) + }; + let id_text_secondary = if is_dark { + css_rgba(240, 240, 255, 118) + } else { + Color::rgb(0x85, 0x88, 0x9E) + }; + let id_row_hover = if is_dark { + css_rgba(250, 250, 255, 20) + } else { + css_rgba(180, 184, 204, 36) + }; + let id_separator = if is_dark { + css_rgba(250, 250, 255, 22) + } else { + css_rgba(38, 38, 51, 22) + }; + let card_w = 320.0; - let header_h = if logged_in { 88.0 } else { 154.0 }; - let rows_h = 50.0 // Plus row with subtitle - + 40.0 * 4.0 // Account, Settings, Support, Language - + 13.0 // divider - + 40.0 // Appearance - + if logged_in { 40.0 } else { 0.0 }; // Sign out - let card_h = 20.0 + header_h + rows_h + 20.0; + let header_h = if logged_in { 144.0 } else { 198.0 }; + let group1_h = 54.0 + if logged_in { 44.0 * 4.0 } else { 44.0 * 2.0 }; + let sep_h = 13.0; // 6px top + 1px line + 6px bottom + let group2_h = 44.0; + let group3_h = if logged_in { sep_h + 44.0 * 2.0 } else { 0.0 }; + let card_h = header_h + group1_h + sep_h + group2_h + group3_h + 10.0; let screen = ctx.screen_rect(); let card_x = (sidebar_rect.left() + 20.0).min((screen.right() - card_w - 12.0).max(8.0)); - let card_y = (footer_rect.top() - card_h - 10.0).clamp(40.0, (screen.bottom() - card_h - 12.0).max(40.0)); + let card_y = + (footer_rect.top() - card_h - 10.0).clamp(40.0, (screen.bottom() - card_h - 12.0).max(40.0)); let card_rect = Rect::from_xywh(card_x, card_y, card_w, card_h); let mut close_popup = false; + let mut lang_row_rect = Rect::ZERO; let mut appearance_row_rect = Rect::ZERO; ctx.with_layer(ZLayer::Popover, |ctx| { ctx.register_blocker(card_rect); - // Card container: exact `pal.profile_bg` (`#121212` dark / `#FFFFFF` light) + `pal.border_control`! + // Card container: exact `24px` radius, `card_bg`, `1px` `card_border`, elevation shadow ctx.dl() - .push_shadow(card_rect, 24.0, 24.0, 0.0, Vec2::new(0.0, 6.0), pal.shadow_modal); + .push_shadow(card_rect, 24.0, 28.0, 0.0, Vec2::new(0.0, 8.0), pal.shadow_modal); ctx.dl() - .push_rect_bordered(card_rect, 24.0, pal.profile_bg, 1.0, pal.border_control); + .push_rect_bordered(card_rect, 24.0, card_bg, 1.0, card_border); - let inner = card_rect.shrink(20.0); - let mut y = inner.top(); + // 1. Top Overlay Bar (`_overlap_1v1kx_1`): 41×20 Yandex ID vector logo + 32×32 circular Close `×` + let logo_r = Rect::from_xywh(card_rect.left() + 16.0, card_rect.top() + 16.0, 41.0, 20.0); + let logo_icon = match (ru, is_dark) { + (true, true) => Icon::YandexIdLogoRuDark, + (true, false) => Icon::YandexIdLogoRuLight, + (false, true) => Icon::YandexIdLogoEnDark, + (false, false) => Icon::YandexIdLogoEnLight, + }; + let logo_resp = ctx.interact(WidgetId::new("prof_yid_logo"), logo_r); + ctx.draw_icon(logo_icon, logo_r, Color::WHITE); + if logo_resp.hovered { + ctx.set_cursor(CursorKind::Pointer); + } + if logo_resp.clicked { + actions.push(AppAction::OpenUrl("https://id.yandex.ru".into())); + close_popup = true; + } - // Top row: Yandex ID badge + Close `×` - let badge_cy = y + 11.0; - ctx.dl() - .push_circle(Pos2::new(inner.left() + 11.0, badge_cy), 10.0, Color::rgb(0xFC, 0x3F, 0x1D)); - ctx.draw_text_ellipsis( - if ru { "Я" } else { "Y" }, - TextStyle::bold(12.0, Color::WHITE), - Rect::from_center_size(Pos2::new(inner.left() + 11.0, badge_cy), Vec2::splat(20.0)), - TextAlign::Center, - ); - let id_pill = Rect::from_xywh(inner.left() + 24.0, y + 1.0, 24.0, 20.0); - ctx.dl().push_rect(id_pill, 6.0, pal.text_bright); - ctx.draw_text_ellipsis( - "ID", - TextStyle::bold(11.0, pal.profile_bg), - id_pill, - TextAlign::Center, - ); - - let close_r = Rect::from_xywh(inner.right() - 26.0, y - 2.0, 26.0, 26.0); + let close_r = Rect::from_xywh(card_rect.right() - 44.0, card_rect.top() + 10.0, 32.0, 32.0); let close_resp = ctx.interact(WidgetId::new("prof_card_close"), close_r); if close_resp.hovered { - ctx.dl().push_circle(close_r.center(), 13.0, pal.surface_hover); + ctx.dl().push_circle(close_r.center(), 16.0, id_row_hover); ctx.set_cursor(CursorKind::Pointer); } ctx.draw_icon( Icon::Close, - Rect::from_center_size(close_r.center(), Vec2::splat(16.0)), - pal.text_primary, + Rect::from_center_size(close_r.center(), Vec2::splat(18.0)), + if close_resp.hovered { + id_text_primary + } else { + id_text_secondary + }, ); if close_resp.clicked { close_popup = true; } - y += 32.0; - - // Account info OR Guest login prompt + // 2. Header: Logged In (`cv`) vs Logged Out (`Av`) + let mut y = card_rect.top() + header_h; if let Some(ref acc) = app.account { + let avatar_center = Pos2::new(card_rect.center_x(), card_rect.top() + 20.0 + 28.0); + if acc.has_plus { + draw_plus_avatar_ring(ctx, avatar_center, 31.0, 2.0); + ctx.dl().push_circle(avatar_center, 29.0, card_bg); + } + let av_rect = Rect::from_center_size(avatar_center, Vec2::splat(56.0)); + if acc.avatar_uri.is_some() { + draw_cover_art( + ctx, + pal, + covers, + av_rect, + acc.avatar_uri.as_deref(), + "profile_popup_avatar", + 28.0, + true, + false, + ); + } else { + ctx.dl().push_circle( + avatar_center, + 28.0, + if is_dark { + Color::rgb(0x32, 0x32, 0x3B) + } else { + Color::rgb(0xEB, 0xEC, 0xF2) + }, + ); + let initial = acc + .display_name + .chars() + .next() + .or_else(|| acc.login.chars().next()) + .unwrap_or(if ru { 'Я' } else { 'Y' }) + .to_uppercase() + .to_string(); + ctx.draw_text_ellipsis( + &initial, + TextStyle::bold(22.0, id_text_primary), + av_rect, + TextAlign::Center, + ); + } + + let name_y = card_rect.top() + 20.0 + 56.0 + 10.0; ctx.draw_text_ellipsis( &acc.display_name, - TextStyle::bold(20.0, pal.text_bright), - Rect::from_xywh(inner.left(), y, inner.width(), 26.0), - TextAlign::Left, + TextStyle::bold(16.0, id_text_primary), + Rect::from_center_size(Pos2::new(card_rect.center_x(), name_y + 11.0), Vec2::new(260.0, 22.0)), + TextAlign::Center, ); - y += 26.0; + + let sub_y = name_y + 22.0 + 2.0; + let contact_str = acc + .default_email + .as_deref() + .filter(|s| !s.is_empty()) + .unwrap_or(&acc.login); ctx.draw_text_ellipsis( - &format!("@{}", acc.login), - TextStyle::regular(13.0, pal.text_secondary), - Rect::from_xywh(inner.left(), y, inner.width(), 18.0), - TextAlign::Left, + contact_str, + TextStyle::regular(13.0, id_text_secondary), + Rect::from_center_size(Pos2::new(card_rect.center_x(), sub_y + 9.0), Vec2::new(260.0, 18.0)), + TextAlign::Center, ); - y += 30.0; } else { + let hx = card_rect.left() + 16.0; + let hw = card_w - 32.0; + let mut hy = card_rect.top() + 52.0; + + let title = if ru { "Войдите в аккаунт" } else { "Log in" }; ctx.draw_text_ellipsis( - i18n.log_in(), - TextStyle::bold(22.0, pal.text_bright), - Rect::from_xywh(inner.left(), y, inner.width(), 28.0), + title, + TextStyle::bold(20.0, id_text_primary), + Rect::from_xywh(hx, hy, hw, 28.0), TextAlign::Left, ); - y += 30.0; + hy += 34.0; + + let subtitle = if ru { + "Чтобы сохранить свои закладки, пароли и карты" + } else { + "To save your bookmarks, passwords, and cards" + }; ctx.draw_text_wrapped( - i18n.login_subtitle(), - TextStyle::regular(13.0, pal.text_secondary), - Rect::from_xywh(inner.left(), y, inner.width(), 34.0), + subtitle, + TextStyle::regular(13.0, id_text_secondary), + Rect::from_xywh(hx, hy, hw, 36.0), Some(2), TextAlign::Left, ); - y += 40.0; + hy += 52.0; - let btn_r = Rect::from_xywh(inner.left(), y, inner.width(), 42.0); + let btn_r = Rect::from_xywh(hx, hy, hw, 44.0); let btn_resp = ctx.interact(WidgetId::new("prof_login_btn"), btn_r); - let btn_bg = if btn_resp.hovered { - pal.text_primary + let btn_bg = if is_dark { + if btn_resp.hovered { + Color::rgb(0xE8, 0xE8, 0xF2) + } else { + Color::rgb(0xFA, 0xFA, 0xFF) + } + } else if btn_resp.hovered { + Color::rgb(0x3B, 0x3B, 0x47) } else { - pal.text_bright + Color::rgb(0x29, 0x29, 0x33) }; - ctx.dl().push_rect(btn_r, 14.0, btn_bg); + let btn_fg = if is_dark { + Color::rgb(0x1F, 0x1F, 0x24) + } else { + Color::WHITE + }; + ctx.dl().push_rect(btn_r, 12.0, btn_bg); ctx.draw_text_ellipsis( - i18n.log_in(), - TextStyle::bold(15.0, pal.profile_bg), + if ru { "Войти" } else { "Log in" }, + TextStyle::bold(15.0, btn_fg), btn_r, TextAlign::Center, ); @@ -752,242 +879,478 @@ fn render_profile_card_popup( actions.push(AppAction::SetLoginModalOpen(true)); close_popup = true; } - y += 52.0; } - // Helper for 100% theme-aware Yandex ID card rows - let draw_profile_row = |ctx: &mut UiContext, - id: &str, - y_pos: f32, - ic: Icon, - title: &str, - subtitle: Option<&str>, - has_chevron: bool, - active: bool| + // Helper for exact Yandex ID v2.79.0 menu rows (`padding: 0 8px`, `radius: 12px`, `24px` icon @ `+12px`, text @ `+48px`) + let row_x = card_rect.left() + 8.0; + let row_w = card_w - 16.0; + let draw_id_row = |ctx: &mut UiContext, + id: &str, + y_pos: f32, + row_h: f32, + ic: Icon, + ic_tint: Color, + title: &str, + subtitle: Option<&str>, + has_chevron: bool, + active: bool, + right_plus_badge: Option<&str>| -> (bool, bool, Rect) { - let h = if subtitle.is_some() { 50.0 } else { 40.0 }; - let r = Rect::from_xywh(inner.left(), y_pos, inner.width(), h); + let r = Rect::from_xywh(row_x, y_pos, row_w, row_h); let resp = ctx.interact(WidgetId::new(id), r); if resp.hovered || active { - ctx.dl().push_rect(r, 12.0, pal.surface_hover); + ctx.dl().push_rect(r, 12.0, id_row_hover); } if resp.hovered { ctx.set_cursor(CursorKind::Pointer); } ctx.draw_icon( ic, - Rect::from_center_size(Pos2::new(r.left() + 18.0, r.center_y()), Vec2::splat(20.0)), - pal.text_primary, + Rect::from_center_size(Pos2::new(r.left() + 24.0, r.center_y()), Vec2::splat(24.0)), + ic_tint, ); - let tx = r.left() + 42.0; - let tw = (r.right() - tx - if has_chevron { 28.0 } else { 8.0 }).max(40.0); + let tx = r.left() + 48.0; + let right_reserve = if right_plus_badge.is_some() { + 68.0 + } else if has_chevron { + 32.0 + } else { + 12.0 + }; + let tw = (r.right() - tx - right_reserve).max(40.0); if let Some(sub) = subtitle { ctx.draw_text_ellipsis( title, - TextStyle::medium(14.0, pal.text_primary), - Rect::from_xywh(tx, r.top() + 6.0, tw, 19.0), + TextStyle::medium(14.5, id_text_primary), + Rect::from_xywh(tx, r.top() + 8.0, tw, 20.0), TextAlign::Left, ); ctx.draw_text_ellipsis( sub, - TextStyle::regular(12.0, pal.text_secondary), - Rect::from_xywh(tx, r.top() + 26.0, tw, 17.0), + TextStyle::regular(12.5, id_text_secondary), + Rect::from_xywh(tx, r.top() + 29.0, tw, 17.0), TextAlign::Left, ); } else { ctx.draw_text_ellipsis( title, - TextStyle::medium(14.0, pal.text_primary), + TextStyle::medium(14.5, id_text_primary), Rect::from_xywh(tx, r.top(), tw, r.height()), TextAlign::Left, ); } - if has_chevron { + if let Some(badge_txt) = right_plus_badge { + let bw = (ctx.measure_text(badge_txt, TextStyle::bold(11.5, Color::WHITE), None).x + + 18.0) + .max(46.0); + let br = Rect::from_xywh(r.right() - bw - 10.0, r.center_y() - 10.0, bw, 20.0); + ctx.dl().push_plus_gradient_rect(br, 10.0, 1.0); + ctx.draw_text_ellipsis( + badge_txt, + TextStyle::bold(11.5, Color::WHITE), + br, + TextAlign::Center, + ); + } else if has_chevron { ctx.draw_icon( Icon::MenuArrowXxs, - Rect::from_center_size(Pos2::new(r.right() - 14.0, r.center_y()), Vec2::splat(20.0)), - pal.text_secondary, + Rect::from_center_size(Pos2::new(r.right() - 16.0, r.center_y()), Vec2::splat(20.0)), + id_text_secondary, ); } (resp.clicked, resp.hovered, r) }; - // Row 1: Yandex Plus - let plus_title = if has_plus { - if ru { "Яндекс Плюс" } else { "Yandex Plus" } - } else if ru { - "Подключить Яндекс Плюс" - } else { - "Connect Yandex Plus" + let draw_separator = |ctx: &mut UiContext, y_pos: f32| { + ctx.dl().push_rect( + Rect::from_xywh(card_rect.left() + 16.0, y_pos + 6.0, card_w - 32.0, 1.0), + 0.0, + id_separator, + ); }; - let plus_sub = if ru { - "Все преимущества в одной подписке" + + // 3. Menu Group 1 (`r.Menu`) + // Row 1 — Plus (`54px`) + let (plus_title, plus_sub, plus_pill) = if has_plus { + ( + if ru { "Плюс" } else { "Plus" }, + if ru { + "Подписка активна" + } else { + "Subscription is active" + }, + Some(if ru { "Плюс" } else { "Plus" }), + ) } else { - "All the fun and benefits in one subscription" + ( + if ru { + "Подключить Плюс" + } else { + "Connect Yandex Plus" + }, + if ru { + "Все развлечения и выгода в одной подписке" + } else { + "All the fun and benefits in one subscription" + }, + None, + ) }; - if draw_profile_row(ctx, "prof_plus", y, Icon::Plus, plus_title, Some(plus_sub), false, false).0 { + let (c, h, _) = draw_id_row( + ctx, + "prof_plus", + y, + 54.0, + Icon::ProfilePlusXxs, + Color::WHITE, // multi-stop gradient SVG + plus_title, + Some(plus_sub), + false, + false, + plus_pill, + ); + if h { + shell.sidebar_lang_open = false; + shell.sidebar_appearance_open = false; + } + if c { actions.push(AppAction::OpenUrl("https://plus.yandex.ru".into())); close_popup = true; } - y += 50.0; + y += 54.0; - // Row 2: Account management (dedicated `ProfileAccountXxs`) - if draw_profile_row( - ctx, - "prof_account", - y, - Icon::ProfileAccountXxs, - i18n.account_management(), - None, - false, - false, - ) - .0 - { - actions.push(AppAction::OpenUrl("https://id.yandex.ru".into())); - close_popup = true; - } - y += 40.0; - - // Row 3: Settings (`SettingsXxs`) - if draw_profile_row( - ctx, - "prof_settings", - y, - Icon::SettingsXxs, - i18n.settings(), - None, - false, - false, - ) - .0 - { - actions.push(AppAction::Navigate(Route::Settings)); - close_popup = true; - } - y += 40.0; - - // Row 4: Support chat (`ProfileSupportXxs`) - if draw_profile_row( - ctx, - "prof_support", - y, - Icon::ProfileSupportXxs, - i18n.support_chat(), - None, - false, - false, - ) - .0 - { - actions.push(AppAction::OpenUrl("https://yandex.ru/support/music/".into())); - close_popup = true; - } - y += 40.0; - - // Row 5: Language (`ProfileGlobeXxs`) - if draw_profile_row( - ctx, - "prof_lang", - y, - Icon::ProfileGlobeXxs, - i18n.language_name(), - None, - false, - false, - ) - .0 - { - actions.push(AppAction::ToggleLanguage); - close_popup = true; - } - y += 40.0; - - // Divider - ctx.dl() - .push_rect(Rect::from_xywh(inner.left(), y + 6.0, inner.width(), 1.0), 0.0, pal.border_control); - y += 13.0; - - // Row 6: Appearance (`ProfileAppearanceXxs`) -> opens 3-way Appearance submenu! - let (app_clicked, app_hovered, app_rect) = draw_profile_row( - ctx, - "prof_appearance", - y, - Icon::ProfileAppearanceXxs, - i18n.appearance(), - None, - true, - shell.sidebar_appearance_open, - ); - appearance_row_rect = app_rect; - if app_clicked { - shell.sidebar_appearance_open = !shell.sidebar_appearance_open; - } else if app_hovered { - shell.sidebar_appearance_open = true; - } - y += 40.0; - - // Row 7: Sign out (`ProfileLogoutXxs`) when logged in - if logged_in - && draw_profile_row( + // Row 2 — Account management (logged in) + if logged_in { + let (c, h, _) = draw_id_row( ctx, - "prof_logout", + "prof_account", y, - Icon::ProfileLogoutXxs, - i18n.sign_out(), + 44.0, + Icon::ProfileAccountXxs, + id_text_primary, + if ru { + "Управление аккаунтом" + } else { + "Account management" + }, None, false, false, - ) - .0 - { - actions.push(AppAction::Logout); - close_popup = true; + None, + ); + if h { + shell.sidebar_lang_open = false; + shell.sidebar_appearance_open = false; + } + if c { + actions.push(AppAction::OpenUrl("https://id.yandex.ru".into())); + close_popup = true; + } + y += 44.0; + + // Row 3 — Settings (logged in) + let (c, h, _) = draw_id_row( + ctx, + "prof_settings", + y, + 44.0, + Icon::ProfileSettingsXxs, + id_text_primary, + if ru { "Настройки" } else { "Settings" }, + None, + false, + false, + None, + ); + if h { + shell.sidebar_lang_open = false; + shell.sidebar_appearance_open = false; + } + if c { + actions.push(AppAction::Navigate(Route::Settings)); + close_popup = true; + } + y += 44.0; } - // Appearance Submenu (`Как в системе` / `Тёмная` / `Светлая` + active `CheckXxs`!) - let mut submenu_rect = Rect::ZERO; + // Row 4 — Support chat (paper-plane) + let (c, h, _) = draw_id_row( + ctx, + "prof_support", + y, + 44.0, + Icon::ProfileSupportXxs, + id_text_primary, + if ru { + "Чат с поддержкой" + } else { + "Chat with support" + }, + None, + false, + false, + None, + ); + if h { + shell.sidebar_lang_open = false; + shell.sidebar_appearance_open = false; + } + if c { + actions.push(AppAction::OpenUrl( + "https://yandex.ru/support/plus/help/ru/?utm_source=music".into(), + )); + close_popup = true; + } + y += 44.0; + + // Row 5 — Language (opens Yandex ID Language Popover!) + let (lang_clicked, lang_hovered, lang_r) = draw_id_row( + ctx, + "prof_lang", + y, + 44.0, + Icon::ProfileGlobeXxs, + id_text_primary, + if ru { "Русский" } else { "English" }, + None, + true, + shell.sidebar_lang_open, + None, + ); + lang_row_rect = lang_r; + if lang_clicked { + shell.sidebar_lang_open = !shell.sidebar_lang_open; + if shell.sidebar_lang_open { + shell.sidebar_appearance_open = false; + } + } else if lang_hovered { + shell.sidebar_lang_open = true; + shell.sidebar_appearance_open = false; + } + y += 44.0; + + // 4. Hairline Separator 1 + draw_separator(ctx, y); + y += sep_h; + + // 5. Menu Group 2 (`r.Submenu`) — Appearance (dynamic icon matching current theme!) + let theme_row_icon = match app.config.theme { + ThemeMode::Light => Icon::ThemeLightXxs, + ThemeMode::Dark => Icon::ThemeDarkXxs, + ThemeMode::System => Icon::ThemeSystemXxs, + }; + let (app_clicked, app_hovered, app_r) = draw_id_row( + ctx, + "prof_appearance", + y, + 44.0, + theme_row_icon, + id_text_primary, + if ru { "Внешний вид" } else { "Appearance" }, + None, + true, + shell.sidebar_appearance_open, + None, + ); + appearance_row_rect = app_r; + if app_clicked { + shell.sidebar_appearance_open = !shell.sidebar_appearance_open; + if shell.sidebar_appearance_open { + shell.sidebar_lang_open = false; + } + } else if app_hovered { + shell.sidebar_appearance_open = true; + shell.sidebar_lang_open = false; + } + y += 44.0; + + // 6. Hairline Separator 2 + Account Actions (when logged in) + if logged_in { + draw_separator(ctx, y); + y += sep_h; + + // Row 7 — Add account + let (c, h, _) = draw_id_row( + ctx, + "prof_add_account", + y, + 44.0, + Icon::ProfileAddAccountXxs, + id_text_primary, + if ru { + "Добавить аккаунт" + } else { + "Add account" + }, + None, + false, + false, + None, + ); + if h { + shell.sidebar_lang_open = false; + shell.sidebar_appearance_open = false; + } + if c { + actions.push(AppAction::SetLoginModalOpen(true)); + close_popup = true; + } + y += 44.0; + + // Row 8 — Sign out + let (c, h, _) = draw_id_row( + ctx, + "prof_logout", + y, + 44.0, + Icon::ProfileLogoutXxs, + id_text_primary, + if ru { "Выйти" } else { "Sign out" }, + None, + false, + false, + None, + ); + if h { + shell.sidebar_lang_open = false; + shell.sidebar_appearance_open = false; + } + if c { + actions.push(AppAction::Logout); + close_popup = true; + } + } + + // 7A. Yandex ID Language Popover (`210px`, `radius: 16px`, `40px` items: `ru Русский` / `en English`) + let mut lang_sub_rect = Rect::ZERO; + if shell.sidebar_lang_open { + let sub_w = 210.0; + let sub_h = 40.0 * 2.0 + 16.0; + let sub_x = (card_rect.right() + 8.0).min((screen.right() - sub_w - 8.0).max(8.0)); + let sub_y = (lang_row_rect.top() - 8.0) + .clamp(40.0, (screen.bottom() - sub_h - 12.0).max(40.0)); + lang_sub_rect = Rect::from_xywh(sub_x, sub_y, sub_w, sub_h); + ctx.register_blocker(lang_sub_rect); + ctx.dl() + .push_shadow(lang_sub_rect, 16.0, 24.0, 0.0, Vec2::new(0.0, 6.0), pal.shadow_modal); + ctx.dl() + .push_rect_bordered(lang_sub_rect, 16.0, popover_bg, 1.0, popover_border); + + let sub_inner = lang_sub_rect.shrink(8.0); + let lang_opts = [ + (Language::Ru, "ru", "Русский", "lang_opt_ru"), + (Language::En, "en", "English", "lang_opt_en"), + ]; + for (idx, (lang, code, lbl, wid)) in lang_opts.into_iter().enumerate() { + let is_cur = app.config.language == lang; + let ir = Rect::from_xywh(sub_inner.x, sub_inner.y + idx as f32 * 40.0, sub_inner.w, 40.0); + let r = ctx.interact(WidgetId::new(wid), ir); + if r.hovered { + ctx.dl().push_rect(ir, 12.0, id_row_hover); + ctx.set_cursor(CursorKind::Pointer); + } + ctx.draw_text_ellipsis( + code, + TextStyle::bold(13.0, id_text_secondary), + Rect::from_xywh(ir.left() + 12.0, ir.top(), 24.0, ir.height()), + TextAlign::Left, + ); + ctx.draw_text_ellipsis( + lbl, + TextStyle::medium(14.0, id_text_primary), + Rect::from_xywh(ir.left() + 42.0, ir.top(), (ir.width() - 72.0).max(40.0), ir.height()), + TextAlign::Left, + ); + if is_cur { + ctx.draw_icon( + Icon::CheckXxs, + Rect::from_center_size(Pos2::new(ir.right() - 16.0, ir.center_y()), Vec2::splat(20.0)), + id_text_primary, + ); + } + if r.clicked { + actions.push(AppAction::SetLanguage(lang)); + shell.sidebar_lang_open = false; + } + } + } + + // 7B. Yandex ID Appearance Popover (`224px`, `radius: 16px`, `40px` items in exact official order!) + let mut app_sub_rect = Rect::ZERO; if shell.sidebar_appearance_open { - let sub_w = 220.0; - let sub_h = 36.0 * 3.0 + 16.0; + let sub_w = 224.0; + let sub_h = 40.0 * 3.0 + 16.0; let sub_x = (card_rect.right() + 8.0).min((screen.right() - sub_w - 8.0).max(8.0)); let sub_y = (appearance_row_rect.top() - 8.0) .clamp(40.0, (screen.bottom() - sub_h - 12.0).max(40.0)); - submenu_rect = Rect::from_xywh(sub_x, sub_y, sub_w, sub_h); + app_sub_rect = Rect::from_xywh(sub_x, sub_y, sub_w, sub_h); + ctx.register_blocker(app_sub_rect); + ctx.dl() + .push_shadow(app_sub_rect, 16.0, 24.0, 0.0, Vec2::new(0.0, 6.0), pal.shadow_modal); + ctx.dl() + .push_rect_bordered(app_sub_rect, 16.0, popover_bg, 1.0, popover_border); - let sub_inner = ym_menu_frame(ctx, pal, submenu_rect); + let sub_inner = app_sub_rect.shrink(8.0); let theme_opts = [ - (ThemeMode::System, Icon::ThemeSystemXxs, i18n.theme_system(), "theme_opt_sys"), - (ThemeMode::Dark, Icon::ThemeDarkXxs, i18n.theme_dark(), "theme_opt_dark"), - (ThemeMode::Light, Icon::ThemeLightXxs, i18n.theme_light(), "theme_opt_light"), + ( + ThemeMode::Light, + Icon::ThemeLightXxs, + if ru { "Всегда светлый" } else { "Always light" }, + "theme_opt_light", + ), + ( + ThemeMode::Dark, + Icon::ThemeDarkXxs, + if ru { "Всегда тёмный" } else { "Always dark" }, + "theme_opt_dark", + ), + ( + ThemeMode::System, + Icon::ThemeSystemXxs, + if ru { "Как в системе" } else { "System settings" }, + "theme_opt_sys", + ), ]; for (idx, (mode, ic, lbl, wid)) in theme_opts.into_iter().enumerate() { let is_cur = app.config.theme == mode; - let ir = Rect::from_xywh(sub_inner.x, sub_inner.y + idx as f32 * 36.0, sub_inner.w, 36.0); - if ym_menu_item_ex( - ctx, - pal, - WidgetId::new(wid), - ir, + let ir = Rect::from_xywh(sub_inner.x, sub_inner.y + idx as f32 * 40.0, sub_inner.w, 40.0); + let r = ctx.interact(WidgetId::new(wid), ir); + if r.hovered { + ctx.dl().push_rect(ir, 12.0, id_row_hover); + ctx.set_cursor(CursorKind::Pointer); + } + ctx.draw_icon( ic, + Rect::from_center_size(Pos2::new(ir.left() + 20.0, ir.center_y()), Vec2::splat(20.0)), + id_text_primary, + ); + ctx.draw_text_ellipsis( lbl, - is_cur, - is_cur, - false, - false, - ) - .clicked - { + TextStyle::medium(14.0, id_text_primary), + Rect::from_xywh(ir.left() + 42.0, ir.top(), (ir.width() - 72.0).max(40.0), ir.height()), + TextAlign::Left, + ); + if is_cur { + ctx.draw_icon( + Icon::CheckXxs, + Rect::from_center_size(Pos2::new(ir.right() - 16.0, ir.center_y()), Vec2::splat(20.0)), + id_text_primary, + ); + } + if r.clicked { actions.push(AppAction::SetTheme(mode)); shell.sidebar_appearance_open = false; } } } - // Click outside profile card + submenu + profile trigger button closes popup + // Click outside profile card + open sub-popover + profile trigger button closes everything cleanly let mut keep_rects = vec![card_rect, profile_hit]; - if !submenu_rect.is_empty() { - keep_rects.push(submenu_rect); + if !lang_sub_rect.is_empty() { + keep_rects.push(lang_sub_rect); + } + if !app_sub_rect.is_empty() { + keep_rects.push(app_sub_rect); } if ctx.input.clicked_outside_any(&keep_rects) { close_popup = true; @@ -997,5 +1360,6 @@ fn render_profile_card_popup( if close_popup { shell.sidebar_profile_open = false; shell.sidebar_appearance_open = false; + shell.sidebar_lang_open = false; } } diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 2d002bd..064b905 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -398,6 +398,7 @@ fn build_reference_matched_shell( uid: 42, login: "marwy".into(), display_name: "Marwy".into(), + default_email: None, has_plus: true, avatar_uri: Some("test.local/avatar_marwy/%%".into()), }); diff --git a/tests/parity_extended.rs b/tests/parity_extended.rs index 4a464fa..b36f196 100644 --- a/tests/parity_extended.rs +++ b/tests/parity_extended.rs @@ -105,6 +105,7 @@ fn make_base_shell( uid: 1, login: "Marwy".into(), display_name: "Marwy".into(), + default_email: Some("marwy@yandex.ru".into()), has_plus: true, avatar_uri: None, }); @@ -1673,3 +1674,188 @@ fn test_ext_15_opengl33_strict_shaders_and_renderer_backend() { ); } } + +#[test] +fn test_ext_16_yandex_id_popup_and_words_card_visual_parity() { + use yandex_music_rs::api::models::{WordsCard, WordsCardSource}; + use yandex_music_rs::engine::types::Pos2; + + let rt = tokio::runtime::Runtime::new().unwrap(); + let mut vk = HeadlessVulkanRenderer::new(NATIVE_W, NATIVE_H).expect("Vulkan init failed"); + let out_dir = output_dir(); + let _ = std::fs::create_dir_all(&out_dir); + + // 1. Dark Theme Yandex ID v2.79.0 Account Popup + Appearance Popover (`dark_profile_popup.png`) + { + let mut shell = make_base_shell( + rt.handle().clone(), + vk.gpu_name.clone(), + Route::LikedTracks, + ThemeMode::Dark, + Language::Ru, + 0.0, + ); + shell.shell.sidebar_profile_open = true; + shell.shell.sidebar_appearance_open = true; + let mut img = render_single_frame(&mut vk, &mut shell, 0.0); + for f in 1..3 { + img = render_single_frame(&mut vk, &mut shell, f as f64 * 0.016); + } + let _ = img.save(out_dir.join("dark_profile_popup.png")); + + // Verify `#1F1F24` dark Yandex ID card surface inside x=32..320, y=240..660 + let mut card_bg_px = 0usize; + let mut bright_text_px = 0usize; + for y in 240..660 { + for x in 32..320 { + let [r, g, b] = img.get_pixel(x, y).0; + if (r as i32 - 0x1F).abs() <= 6 + && (g as i32 - 0x1F).abs() <= 6 + && (b as i32 - 0x24).abs() <= 6 + { + card_bg_px += 1; + } else if r >= 220 && g >= 220 && b >= 225 { + bright_text_px += 1; + } + } + } + assert!( + card_bg_px > 40_000, + "[dark_profile_popup] Expected Yandex ID #1F1F24 dark surface (got {} px)", + card_bg_px + ); + assert!( + bright_text_px > 1_200, + "[dark_profile_popup] Expected high-contrast #FAFAFF text/icons (got {} px)", + bright_text_px + ); + + // Verify Appearance submenu popover rendered to the right of the card (x=345..555) + let mut sub_bg_px = 0usize; + for y in 420..660 { + for x in 348..555 { + let [r, g, b] = img.get_pixel(x, y).0; + if (r as i32 - 0x2D).abs() <= 8 + && (g as i32 - 0x2D).abs() <= 8 + && (b as i32 - 0x34).abs() <= 8 + { + sub_bg_px += 1; + } + } + } + assert!( + sub_bg_px > 10_000, + "[dark_profile_popup] Expected Yandex ID #2D2D34 Appearance popover (got {} px)", + sub_bg_px + ); + } + + // 2. My Vibe official 5.129.0 `WordsCard` + `WordsCardPopoverDesktop` (`my_vibe_words_popover.png`) + { + // Static guard: fake AI Vibe-settings string MUST be completely gone from `src/views/my_vibe.rs` + let mv_src = std::fs::read_to_string( + Path::new(env!("CARGO_MANIFEST_DIR")).join("src/views/my_vibe.rs"), + ) + .expect("read src/views/my_vibe.rs"); + assert!( + !mv_src.contains("Мою волну по настроению и характеру"), + "Fake AI Vibe-settings phrase must be removed from WordsCard in src/views/my_vibe.rs!" + ); + + let mut shell = make_base_shell( + rt.handle().clone(), + vk.gpu_name.clone(), + Route::MyVibe, + ThemeMode::Dark, + Language::Ru, + 108.0, + ); + shell.app.words_cards.insert( + "t_1".into(), + WordsCard { + id: "wc_test_1".into(), + track_id: "t_1".into(), + text: "Трек вдохновлён бразильским фонком и энергичными рейвами 2000-х".into(), + tags: vec!["FACT".into()], + action: None, + actions: vec![WordsCardSource { + title: "Подробнее об артисте".into(), + url: "https://music.yandex.ru".into(), + favicon_url: None, + }], + big_card_ids: Vec::new(), + feedback_state: None, + }, + ); + + // Warm up WordsCard layout (renders State B around cx~943, ai_y~732) + let before = render_single_frame(&mut vk, &mut shell, 0.0); + let click_pos = Pos2::new(943.0, 732.0); + // Simulate genuine left-click press + release on WordsCard to toggle WordsCardPopoverDesktop + shell.ui.input.pointer_pos = Some(click_pos); + shell.ui.input.left_down = true; + shell.ui.input.left_pressed = true; + let _ = render_single_frame(&mut vk, &mut shell, 0.016); + shell.ui.input.left_down = false; + shell.ui.input.left_released = true; + let _ = render_single_frame(&mut vk, &mut shell, 0.032); + let after = render_single_frame(&mut vk, &mut shell, 0.048); + + let _ = after.save(out_dir.join("my_vibe_words_popover.png")); + + // Verify WordsCardPopoverDesktop actually appeared above WordsCard (y=500..700, x=810..1075) + let popover_delta = region_mean_abs_diff(&before, &after, 810, 500, 1075, 700); + assert!( + popover_delta > 4.0, + "[my_vibe_words_popover] Clicking WordsCard did not open WordsCardPopoverDesktop (delta={:.2} RGB)", + popover_delta + ); + assert!( + !shell.app.vibe_modal_open, + "[my_vibe_words_popover] Clicking WordsCard MUST NOT open fake Vibe settings modal!" + ); + } + + // 3. Official 1-to-1 `VibeResetButton` unified pill + `0.1.0` version badge (`my_vibe_context_pill.png`) + { + use yandex_music_rs::app::APP_VERSION; + assert_eq!(APP_VERSION, "0.1.0", "APP_VERSION must match Cargo.toml 0.1.0"); + + let mut shell = make_base_shell( + rt.handle().clone(), + vk.gpu_name.clone(), + Route::MyVibe, + ThemeMode::Dark, + Language::En, + 12.0, + ); + if let Some(tr) = shell.app.queue.get_mut(0) { + tr.derived_average_hex = Some("#F56E00".into()); + } + shell.app.is_vibe_active = false; + shell.app.context_name = "My Favorites".into(); + shell.app.context_key = "likes".into(); + shell.app.set_vibe_playback_for_test(true, 0.45, 0.35); + + let mut img = render_single_frame(&mut vk, &mut shell, 0.0); + for f in 1..4 { + img = render_single_frame(&mut vk, &mut shell, f as f64 * 0.2); + } + let _ = img.save(out_dir.join("my_vibe_context_pill.png")); + + // Verify bright electric yellow pixels (#FFFF00) inside top-center VibeResetButton pill (y=32..80, x=830..1060) + let mut pill_yellow_px = 0usize; + for y in 32..80 { + for x in 830..1060 { + if is_yandex_yellow(img.get_pixel(x, y).0) { + pill_yellow_px += 1; + } + } + } + assert!( + pill_yellow_px >= 400, + "[my_vibe_context_pill] Expected electric yellow text + filled yellow close circle inside unified VibeResetButton pill, found {} yellow px", + pill_yellow_px + ); + } +}