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