pub mod collection; pub mod detail; pub mod for_you; pub mod my_vibe; pub mod overlays; pub mod player_bar; pub mod podcasts_kids; pub mod search; pub mod settings; pub mod sidebar; pub mod titlebar; use std::time::Instant; use crate::app::{AppAction, AppState, RightDrawerTab, Route, WindowCommand}; use crate::covers::CoverCache; use crate::engine::{ copy_to_clipboard, Color, FrameOutput, Key, Pos2, Rect, UiContext, Vec2, WidgetId, YmPalette, CONTENT_RADIUS, LAYOUT_GAP, NAVBAR_COLLAPSED_WIDTH, NAVBAR_FULL_WIDTH, PLAYER_BAR_HEIGHT, TITLEBAR_HEIGHT, }; use crate::vulkan::vibe_renderer::VibePushConstants; use overlays::{ render_delete_playlist_confirm_modal, render_entity_context_menu, render_eq_popover, render_equalizer_modal, render_fullscreen_player, render_login_modal, render_playlist_modal, render_release_notes_modal, render_right_drawer, render_shortcuts_modal, render_toast_with_offset, render_track_context_menu, render_track_detail_modal, render_update_notification, render_vibe_settings_modal, ShellUiState, SplashPlayer, }; use player_bar::render_player_bar; use sidebar::render_sidebar; use titlebar::render_titlebar; /// Top-level pure-Rust Application Shell combining `AppState`, `UiContext`, `CoverCache`, /// `YmPalette`, `ShellUiState`, and the theme-aware `SplashPlayer`. pub struct YandexMusicShell { pub app: AppState, pub ui: UiContext, pub covers: CoverCache, pub palette: YmPalette, pub shell: ShellUiState, pub splash: Option, start_instant: Instant, } impl YandexMusicShell { pub fn new(runtime: tokio::runtime::Handle, gpu_name: String) -> Self { let app = AppState::new(runtime.clone(), gpu_name); let palette = YmPalette::from_mode(app.config.theme); let covers = CoverCache::new(app.config.max_cover_cache, runtime); let ui = UiContext::new(); let skip_splash = std::env::args().any(|a| a == "--no-splash" || a.starts_with("--page=")); let splash = if skip_splash { None } else { Some(SplashPlayer::spawn(palette.is_dark)) }; Self { app, ui, covers, palette, shell: ShellUiState::default(), splash, start_instant: Instant::now(), } } /// Deterministic offline shell constructor for headless visual parity tests (zero splash). pub fn new_visual_test(app: AppState, covers: CoverCache) -> Self { let palette = YmPalette::from_mode(app.config.theme); Self { app, ui: UiContext::new(), covers, palette, shell: ShellUiState::default(), splash: None, start_instant: Instant::now(), } } pub fn sync_palette(&mut self) { if self.app.theme_dirty { self.palette = YmPalette::from_mode(self.app.config.theme); self.app.theme_dirty = false; } } pub fn window_title(&self) -> &'static str { self.app.i18n().app_name() } pub fn is_dark(&self) -> bool { self.palette.is_dark } pub fn elapsed_secs(&self) -> f64 { self.start_instant.elapsed().as_secs_f64() } pub fn needs_continuous_repaint(&self) -> bool { self.splash.is_some() || self.app.needs_continuous_repaint() } pub fn continuous_repaint_interval(&self, window_focused: bool) -> Option { if self.splash.is_some() { return Some(std::time::Duration::from_millis(16)); } self.app.continuous_repaint_interval(window_focused) } /// Lightweight CPU-only background poll for idle/minimized/hidden states. /// Returns `true` if new API data, decoded covers, or expired toasts require a GPU redraw. pub fn poll_background_events(&mut self) -> bool { let mut dirty = self.app.poll_async_events(); if self.app.take_clear_cover_cache_requested() { self.covers.clear(&mut self.ui.textures); dirty = true; } if self.app.take_cover_cache_capacity_dirty() { self.covers.set_capacity(self.app.config.max_cover_cache); } if self.covers.poll_uploads(&mut self.ui.textures) { dirty = true; } if self.app.toast.is_some() && self.app.current_toast().is_none() { dirty = true; } dirty } pub fn handle_winit_event(&mut self, event: &winit::event::WindowEvent) -> bool { self.ui.input.handle_winit_event(event) } fn current_cover_fallback_rgb(&mut self) -> Option<[u8; 3]> { let uri = self .app .current_track() .and_then(|t| t.cover_uri.as_deref()) .map(String::from)?; self.covers .get_or_fetch(&uri, 100) .map(|(_, dom, _)| [dom.r, dom.g, dom.b]) } pub fn vibe_push_constants(&mut self) -> Option { let fallback_rgb = self.current_cover_fallback_rgb(); self.app .vibe_push_constants(self.palette.is_dark, fallback_rgb) } /// Render one complete UI frame into a `FrameOutput` (`DisplayList` + `TextureUpload`s + cursor). pub fn render_frame( &mut self, screen_size: Vec2, scale_factor: f32, time: f64, is_maximized: bool, ) -> (FrameOutput, WindowCommand) { self.sync_palette(); self.app.poll_async_events(); if self.app.take_clear_cover_cache_requested() { self.covers.clear(&mut self.ui.textures); } if self.app.take_cover_cache_capacity_dirty() { self.covers.set_capacity(self.app.config.max_cover_cache); } let covers_arrived = self.covers.poll_uploads(&mut self.ui.textures); let dt = self.app.last_vibe_tick.elapsed().as_secs_f32(); self.app.last_vibe_tick = Instant::now(); if self.app.fixed_vibe_time.is_none() && (self.app.has_active_vibe_surface() || self.app.smooth_playing > 0.001 || self.app.is_audio_playing()) { let fallback_rgb = if self.app.has_active_vibe_surface() { self.current_cover_fallback_rgb() } else { None }; self.app.tick_vibe_animation(dt, fallback_rgb); } self.ui.begin_frame(screen_size, scale_factor, time); if covers_arrived { self.ui.request_repaint(); } let mut actions: Vec = Vec::with_capacity(8); // Global keyboard shortcuts (skipped whenever a text input has focus!) self.collect_keyboard_shortcuts(&mut actions); let pal = self.palette; let screen = self.ui.screen_rect(); let is_my_vibe_page = matches!(self.app.route, Route::MyVibe); // 1. Left Sidebar (full-height, smooth 224px <-> 72px collapse animation) let collapse_t = self.ui.animate_bool( WidgetId::new("ym_sidebar_collapse_anim"), self.app.config.sidebar_collapsed, 0.16, ); let nav_w = (NAVBAR_FULL_WIDTH * (1.0 - collapse_t) + NAVBAR_COLLAPSED_WIDTH * collapse_t) .round(); let sidebar_rect = Rect::from_xywh( screen.left(), screen.top() + TITLEBAR_HEIGHT, nav_w, (screen.height() - TITLEBAR_HEIGHT).max(0.0), ); render_sidebar( &mut self.ui, &pal, &mut self.covers, &self.app, &mut self.shell, sidebar_rect, collapse_t, &mut actions, ); // 2. Bottom PlayerBar (80px height, 12px bottom & right margins; hidden on My Vibe) let player_bar_rect = Rect::from_xywh( nav_w, (screen.bottom() - PLAYER_BAR_HEIGHT - 12.0).max(TITLEBAR_HEIGHT), (screen.width() - nav_w - LAYOUT_GAP).max(200.0), PLAYER_BAR_HEIGHT, ); if !is_my_vibe_page { render_player_bar( &mut self.ui, &pal, &mut self.covers, &self.app, &mut self.shell, player_bar_rect, &mut actions, ); } // Route transition (0.20s ease-out upward glide + dissolve; 0 overhead when steady or deterministic test!) if self.app.fixed_vibe_time.is_none() && self.shell.last_route.as_ref() != Some(&self.app.route) { if self.shell.last_route.is_some() { self.shell.route_transition_start = time; } self.shell.last_route = Some(self.app.route.clone()); } let route_t = if self.app.fixed_vibe_time.is_some() || self.shell.route_transition_start <= 0.0 { 1.0f32 } else { ((time - self.shell.route_transition_start) as f32 / 0.20).clamp(0.0, 1.0) }; if route_t < 1.0 { self.ui.request_repaint(); } let route_ease = { let u = 1.0 - route_t; 1.0 - u * u * u }; let page_dy = if route_t < 1.0 { ((1.0 - route_ease) * 14.0).round() } else { 0.0 }; // 3. Optional Right Slide-Over Drawer (smooth 0.22s slide-in/out; instant in deterministic test!) let show_side_drawer = self.app.right_drawer != RightDrawerTab::None && !self.app.fullscreen_open; let drawer_t = if self.app.fixed_vibe_time.is_some() { if show_side_drawer { 1.0 } else { 0.0 } } else { self.ui.animate_bool(WidgetId::new("ym_right_drawer_anim"), show_side_drawer, 0.22) }; let drawer_ease = { let u = 1.0 - drawer_t.clamp(0.0, 1.0); 1.0 - u * u * u }; let content_bottom = if is_my_vibe_page { screen.bottom() } else { (player_bar_rect.top() - LAYOUT_GAP).max(TITLEBAR_HEIGHT + 40.0) }; let drawer_w = 332.0; let content_top = screen.top() + TITLEBAR_HEIGHT + 1.0; let drawer_shift = drawer_ease * (drawer_w + LAYOUT_GAP); let drawer_rect = Rect::from_xywh( screen.right() - drawer_shift, content_top, drawer_w, (content_bottom - content_top).max(40.0), ); if drawer_ease > 0.01 { render_right_drawer( &mut self.ui, &pal, &mut self.covers, &self.app, &mut self.shell, drawer_rect, &mut actions, ); } // 4. Main Content Area (Full-bleed on My Vibe; Rounded 16px `pal.bg_content` card on all other pages!) if is_my_vibe_page { let vibe_rect = Rect::from_xywh( nav_w, screen.top(), (screen.width() - nav_w - if drawer_ease > 0.01 { drawer_shift + LAYOUT_GAP } else { 0.0 }) .max(100.0), screen.height(), ); my_vibe::render_my_vibe( &mut self.ui, &pal, &mut self.covers, &mut self.app, &mut self.shell, vibe_rect, &mut actions, ); if route_t < 1.0 { self.ui.dl().push_rect( vibe_rect, 0.0, pal.bg_basic.with_alpha_f32((1.0 - route_ease) * 0.55), ); } } else { let content_right = if drawer_ease > 0.01 { drawer_rect.left() - LAYOUT_GAP } else { screen.right() - LAYOUT_GAP }; let outer_r = Rect::from_min_max( Pos2::new(nav_w, content_top), Pos2::new(content_right.max(nav_w + 120.0), content_bottom), ); // Base rounded content card self.ui.dl().push_rect(outer_r, CONTENT_RADIUS, pal.bg_content); // Edge-to-edge top atmospheric gradient wash on Detail pages (clipped cleanly by SDF rounded rect!) let is_detail_page = matches!( self.app.route, Route::LikedTracks | Route::Playlist { .. } | Route::Album { .. } | Route::Artist { .. } ); if is_detail_page { let wash_h = 340.0f32.min(outer_r.height()); let wash_r = Rect::from_xywh(outer_r.left(), outer_r.top(), outer_r.width(), wash_h); let wash_top = if pal.is_dark { Color::rgb(61, 61, 61) } else { Color::rgb(235, 235, 235) }; self.ui.push_clip(outer_r, CONTENT_RADIUS); self.ui.dl().push_gradient_rect( wash_r, 0.0, wash_top, pal.bg_content, Vec2::new(0.0, 1.0), ); self.ui.pop_clip(); } // 1px subtle border self.ui.dl().push_rect_bordered( outer_r, CONTENT_RADIUS, Color::TRANSPARENT, 1.0, pal.border_subtle, ); // Exact inner content rect (+25px horizontal, +12px top so inner y stays 45.0 with +1px card_top) let base_inner_r = outer_r.inset(25.0, 12.0, 25.0, 0.0); let inner_r = Rect::from_xywh( base_inner_r.left(), base_inner_r.top() + page_dy, base_inner_r.width(), base_inner_r.height(), ); self.ui.push_clip(outer_r, CONTENT_RADIUS); match self.app.route.clone() { Route::MyVibe => {} Route::ForYou => for_you::render_for_you( &mut self.ui, &pal, &mut self.covers, &mut self.app, &mut self.shell, inner_r, &mut actions, ), Route::Search => search::render_search( &mut self.ui, &pal, &mut self.covers, &mut self.app, &mut self.shell, inner_r, &mut actions, ), Route::Collection => collection::render_collection( &mut self.ui, &pal, &mut self.covers, &mut self.app, &mut self.shell, inner_r, &mut actions, ), Route::LikedTracks | Route::Playlist { .. } | Route::Album { .. } | Route::Artist { .. } => detail::render_detail( &mut self.ui, &pal, &mut self.covers, &mut self.app, &mut self.shell, inner_r, &mut actions, ), Route::Podcasts => podcasts_kids::render_podcasts( &mut self.ui, &pal, &mut self.covers, &mut self.app, &mut self.shell, inner_r, &mut actions, ), Route::Kids => podcasts_kids::render_kids( &mut self.ui, &pal, &mut self.covers, &mut self.app, &mut self.shell, inner_r, &mut actions, ), Route::Concerts => podcasts_kids::render_concerts( &mut self.ui, &pal, &mut self.covers, &mut self.app, &mut self.shell, inner_r, &mut actions, ), Route::Chart => podcasts_kids::render_chart( &mut self.ui, &pal, &mut self.covers, &mut self.app, &mut self.shell, inner_r, &mut actions, ), Route::Metatags => podcasts_kids::render_metatags( &mut self.ui, &pal, &mut self.covers, &mut self.app, &mut self.shell, inner_r, &mut actions, ), Route::Metatag { .. } => podcasts_kids::render_metatag_detail( &mut self.ui, &pal, &mut self.covers, &mut self.app, &mut self.shell, inner_r, &mut actions, ), Route::Settings => settings::render_settings( &mut self.ui, &pal, &mut self.covers, &mut self.app, &mut self.shell, inner_r, &mut actions, ), } if route_t < 1.0 { self.ui.dl().push_rect( outer_r, CONTENT_RADIUS, pal.bg_content.with_alpha_f32((1.0 - route_ease) * 0.65), ); } self.ui.pop_clip(); } // 5. FullscreenPlayerDesktop (ZLayer::Drawer — smooth 0.24s glide-up/down!) let fs_t = if self.app.fixed_vibe_time.is_some() { if self.app.fullscreen_open { 1.0 } else { 0.0 } } else { self.ui.animate_bool(WidgetId::new("ym_fullscreen_anim"), self.app.fullscreen_open, 0.24) }; let fs_ease = { let u = 1.0 - fs_t.clamp(0.0, 1.0); 1.0 - u * u * u }; self.shell.fs_slide_dy = if fs_ease < 0.999 { ((1.0 - fs_ease) * 48.0).round() } else { 0.0 }; if fs_ease > 0.01 { render_fullscreen_player( &mut self.ui, &pal, &mut self.covers, &self.app, &mut self.shell, &mut actions, ); } // 6. Floating Popovers & Context Menus (ZLayer::Popover) let ease_out = |t: f32| -> f32 { let u = 1.0 - t.clamp(0.0, 1.0); 1.0 - u * u * u }; let eq_pop_t = if self.app.fixed_vibe_time.is_some() { if self.app.eq_popover_open { 1.0 } else { 0.0 } } else { ease_out(self.ui.animate_bool( WidgetId::new("ym_quality_popover_anim"), self.app.eq_popover_open, 0.18, )) }; let eq_expand_t = if self.app.fixed_vibe_time.is_some() { if self.app.config.eq_enabled { 1.0 } else { 0.0 } } else { ease_out(self.ui.animate_bool( WidgetId::new("ym_quality_eq_expand"), self.app.config.eq_enabled, 0.20, )) }; if eq_pop_t > 0.01 { render_eq_popover( &mut self.ui, &pal, &self.app, &mut self.shell, eq_pop_t, eq_expand_t, &mut actions, ); } render_track_context_menu(&mut self.ui, &pal, &self.app, &mut self.shell, &mut actions); render_entity_context_menu(&mut self.ui, &pal, &self.app, &mut self.shell, &mut actions); // 7. Modals (ZLayer::Modal) if self.app.vibe_modal_open { render_vibe_settings_modal(&mut self.ui, &pal, &self.app, &mut actions); } render_playlist_modal(&mut self.ui, &pal, &mut self.app, &mut actions); render_delete_playlist_confirm_modal( &mut self.ui, &pal, &self.app, &mut self.shell, &mut actions, ); if self.app.login_modal_open { render_login_modal(&mut self.ui, &pal, &mut self.app, &mut actions); } if self.app.track_detail_modal.is_some() { render_track_detail_modal(&mut self.ui, &pal, &mut self.covers, &self.app, &mut actions); } let rn_mod_t = if self.app.fixed_vibe_time.is_some() { if self.app.release_notes_modal_open { 1.0 } else { 0.0 } } else { ease_out(self.ui.animate_bool( WidgetId::new("ym_release_notes_modal_anim"), self.app.release_notes_modal_open, 0.18, )) }; if rn_mod_t > 0.01 { render_release_notes_modal(&mut self.ui, &pal, &self.app, rn_mod_t, &mut actions); } let eq_mod_t = if self.app.fixed_vibe_time.is_some() { if self.app.equalizer_modal_open { 1.0 } else { 0.0 } } else { ease_out(self.ui.animate_bool( WidgetId::new("ym_eq_modal_anim"), self.app.equalizer_modal_open, 0.18, )) }; if eq_mod_t > 0.01 { render_equalizer_modal( &mut self.ui, &pal, &self.app, &mut self.shell, eq_mod_t, &mut actions, ); } let sc_mod_t = if self.app.fixed_vibe_time.is_some() { if self.app.shortcuts_modal_open { 1.0 } else { 0.0 } } else { ease_out(self.ui.animate_bool( WidgetId::new("ym_shortcuts_modal_anim"), self.app.shortcuts_modal_open, 0.18, )) }; if sc_mod_t > 0.01 { render_shortcuts_modal(&mut self.ui, &pal, &self.app, sc_mod_t, &mut actions); } // 8. Transparent 32px Floating TitleBar (ZLayer::Titlebar) let win_cmd = render_titlebar( &mut self.ui, &pal, &self.app, is_maximized, self.app.fullscreen_open, ); // 9. Official `NotificationUpdate` + Floating Toast (when splash is done) let show_upd_notif = self.splash.is_none() && !self.app.fullscreen_open && !self.app.update_notification_dismissed && self.app.available_update.is_some(); if show_upd_notif { if let Some(ref upd) = self.app.available_update { render_update_notification(&mut self.ui, &pal, &self.app, upd, &mut actions); } } if self.splash.is_none() { if let Some(msg) = self.app.current_toast().map(String::from) { let extra_offset = if show_upd_notif { 64.0 } else { 0.0 }; render_toast_with_offset(&mut self.ui, &pal, &msg, extra_offset); } } // 10. Theme-Aware Streaming Animated Splash Screen (`splash_dark.webp` / `splash_light.webp`) if let Some(ref mut sp) = self.splash { if sp.render(&mut self.ui) { self.splash = None; } } // Dispatch all actions emitted during this frame for act in actions { self.app.dispatch(act); } // Flush any clipboard write requested by Share > Copy link / HTML code if let Some(clip_text) = self.app.take_pending_clipboard_text() { let _ = copy_to_clipboard(&clip_text); } // Refresh palette immediately if theme changed this frame self.sync_palette(); let output = self.ui.end_frame(&self.palette); (output, win_cmd) } /// Exact Yandex Music Desktop 5.129.0 global keyboard shortcuts (disabled while typing in a text input). fn collect_keyboard_shortcuts(&mut self, actions: &mut Vec) { // OS Media keys always work regardless of text focus if self.ui.input.key_pressed(Key::MediaPlayPause) { actions.push(AppAction::TogglePlay); } if self.ui.input.key_pressed(Key::MediaNext) { actions.push(AppAction::Next); } if self.ui.input.key_pressed(Key::MediaPrev) { actions.push(AppAction::Prev); } if self.ui.input.key_pressed(Key::MediaStop) { actions.push(AppAction::Stop); } if self.ui.input.key_pressed(Key::Escape) { self.shell.close_all_menus(); self.shell.confirm_delete_playlist = None; actions.push(AppAction::DismissOverlays); } if self.ui.input.has_text_focus() { return; } let inp = &self.ui.input; let key_any = |chars: &[char]| -> bool { chars.iter().any(|&c| { inp.key_pressed_no_mods(Key::Char(c)) || c.to_uppercase() .next() .map_or(false, |u| inp.key_pressed_no_mods(Key::Char(u))) }) }; let ctrl_any = |chars: &[char]| -> bool { inp.key_events.iter().any(|e| { e.modifiers.command() && !e.modifiers.shift && !e.modifiers.alt && matches!(e.key, Key::Char(c) if chars.iter().any(|&t| { c == t || c.to_lowercase().next() == Some(t) })) }) }; // K / л / Space -> Play / Pause if inp.key_pressed_no_mods(Key::Space) || key_any(&['k', 'л']) { actions.push(AppAction::TogglePlay); } // M / ь -> Mute if key_any(&['m', 'ь']) { actions.push(AppAction::ToggleMute); } // Volume ±5% if inp.key_pressed_no_mods(Key::ArrowUp) { actions.push(AppAction::SetVolume((self.app.config.volume + 0.05).clamp(0.0, 1.0))); } if inp.key_pressed_no_mods(Key::ArrowDown) { actions.push(AppAction::SetVolume((self.app.config.volume - 0.05).clamp(0.0, 1.0))); } // Seek ±2s (ArrowLeft / J / о, ArrowRight / L / д) if inp.key_pressed_no_mods(Key::ArrowRight) || key_any(&['l', 'д']) { let target = (self.app.position_ms() + 2000).min(self.app.duration_ms()); actions.push(AppAction::SeekMs(target)); } if inp.key_pressed_no_mods(Key::ArrowLeft) || key_any(&['j', 'о']) { let target = self.app.position_ms().saturating_sub(2000); actions.push(AppAction::SeekMs(target)); } // Next / Prev (N/т, P/з or Ctrl+ArrowRight/Left) let ctrl_right = inp .key_events .iter() .any(|e| e.key == Key::ArrowRight && e.modifiers.command()); let ctrl_left = inp .key_events .iter() .any(|e| e.key == Key::ArrowLeft && e.modifiers.command()); if ctrl_right || key_any(&['n', 'т']) { actions.push(AppAction::Next); } if ctrl_left || key_any(&['p', 'з']) { actions.push(AppAction::Prev); } // Like (F / а) & Dislike (D / в) if key_any(&['f', 'а']) { if let Some(tr) = self.app.current_track().cloned() { actions.push(AppAction::ToggleLike(tr)); } } if key_any(&['d', 'в']) { if let Some(tr) = self.app.current_track().cloned() { actions.push(AppAction::ToggleDislike(tr)); } } // Repeat (R / к), Shuffle (S / ы), Fullscreen (W / ц) if key_any(&['r', 'к']) { actions.push(AppAction::CycleRepeat); } if key_any(&['s', 'ы']) { actions.push(AppAction::ToggleShuffle); } if key_any(&['w', 'ц']) { actions.push(AppAction::ToggleFullscreen); } // Ctrl+F / Ctrl+а -> Search, Ctrl+L / Ctrl+д -> Lyrics, Alt+Left/Right -> Nav History if ctrl_any(&['f', 'а']) { actions.push(AppAction::Navigate(Route::Search)); } if ctrl_any(&['l', 'д']) { if self.app.fullscreen_open && self.app.fullscreen_lyrics_open { actions.push(AppAction::ToggleFullscreenLyrics); } else { actions.push(AppAction::OpenFullscreenSyncLyrics); } } let alt_left = inp .key_events .iter() .any(|e| e.key == Key::ArrowLeft && e.modifiers.alt); let alt_right = inp .key_events .iter() .any(|e| e.key == Key::ArrowRight && e.modifiers.alt); if alt_left { actions.push(AppAction::GoBack); } if alt_right { actions.push(AppAction::GoForward); } } }