chore(release): v0.1.5 - Linux ksni tray, 1:1 sidebar collapse button, zero-overhead Linux RAM tuning
This commit is contained in:
parent
f063382410
commit
ee65d23b2a
9 changed files with 684 additions and 48 deletions
|
|
@ -7,9 +7,16 @@ use std::sync::Arc;
|
|||
use crate::engine::textures::TextureRegistry;
|
||||
use crate::engine::types::{Color, TextureId};
|
||||
|
||||
/// Hard minimum LRU cover cache capacity so even dense pages (Artist/Collection + sidebar + player)
|
||||
/// can never thrash or flicker visible avatars/covers.
|
||||
/// Hard minimum LRU cover cache capacity.
|
||||
/// Leaner on Linux integrated-GPU (UMA) builds where GL textures live directly in system RAM!
|
||||
#[cfg(all(target_os = "linux", not(test)))]
|
||||
pub const MIN_COVER_CACHE_CAPACITY: usize = 64;
|
||||
#[cfg(not(all(target_os = "linux", not(test))))]
|
||||
pub const MIN_COVER_CACHE_CAPACITY: usize = 128;
|
||||
|
||||
#[cfg(all(target_os = "linux", not(test)))]
|
||||
const MAX_AUTO_GROW_CAPACITY: usize = 128;
|
||||
#[cfg(not(all(target_os = "linux", not(test))))]
|
||||
const MAX_AUTO_GROW_CAPACITY: usize = 1024;
|
||||
|
||||
pub struct CoverEntry {
|
||||
|
|
|
|||
|
|
@ -332,8 +332,25 @@ impl TextEngine {
|
|||
|
||||
db.set_sans_serif_family(&ys_text_family);
|
||||
|
||||
// Load system fallback fonts for rare symbols / emoji / CJK
|
||||
db.load_system_fonts();
|
||||
// On Linux, avoid indexing all 400+ system fonts (saves 20-40 MB RSS from Noto CJK/Emoji);
|
||||
// load only 1-2 lean symbol/fallback faces alongside our 4 embedded official Yandex fonts.
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
for path in [
|
||||
"/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
|
||||
"/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf",
|
||||
"/usr/share/fonts/truetype/noto/NotoSansSymbols2-Regular.ttf",
|
||||
] {
|
||||
if std::path::Path::new(path).is_file() {
|
||||
let _ = db.load_font_file(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
{
|
||||
// Load system fallback fonts for rare symbols / emoji / CJK
|
||||
db.load_system_fonts();
|
||||
}
|
||||
|
||||
let font_system = FontSystem::new_with_locale_and_db("ru-RU".to_string(), db);
|
||||
|
||||
|
|
|
|||
18
src/main.rs
18
src/main.rs
|
|
@ -1058,7 +1058,25 @@ fn acquire_single_instance_lock() -> bool {
|
|||
true
|
||||
}
|
||||
|
||||
#[cfg(all(target_os = "linux", target_env = "gnu"))]
|
||||
fn tune_linux_glibc_allocator() {
|
||||
extern "C" {
|
||||
fn mallopt(param: std::ffi::c_int, value: std::ffi::c_int) -> std::ffi::c_int;
|
||||
}
|
||||
const M_TRIM_THRESHOLD: std::ffi::c_int = -1;
|
||||
const M_MMAP_THRESHOLD: std::ffi::c_int = -3;
|
||||
const M_ARENA_MAX: std::ffi::c_int = -8;
|
||||
unsafe {
|
||||
let _ = mallopt(M_ARENA_MAX, 2);
|
||||
let _ = mallopt(M_TRIM_THRESHOLD, 128 * 1024);
|
||||
let _ = mallopt(M_MMAP_THRESHOLD, 128 * 1024);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
#[cfg(all(target_os = "linux", target_env = "gnu"))]
|
||||
tune_linux_glibc_allocator();
|
||||
|
||||
// Isolated Vulkan HW probe subprocess (keeps libvulkan_lvp / libLLVM out of main Linux RSS)
|
||||
if std::env::args().any(|a| a == "--probe-vulkan") {
|
||||
std::process::exit(if VulkanContext::has_hardware_vulkan() { 0 } else { 1 });
|
||||
|
|
|
|||
|
|
@ -451,22 +451,267 @@ mod imp {
|
|||
mod imp {
|
||||
use super::NativeEvent;
|
||||
use crate::api::models::Track;
|
||||
use crossbeam_channel::{unbounded, Receiver, Sender};
|
||||
use ksni::blocking::{Handle, TrayMethods};
|
||||
use std::io::{BufRead, BufReader};
|
||||
use std::process::{Command, Stdio};
|
||||
use std::sync::Arc;
|
||||
use winit::window::Window;
|
||||
|
||||
const OAUTH_TOKEN_PREFIX: &str = "YM_OAUTH_TOKEN:";
|
||||
|
||||
pub struct NativeDesktop;
|
||||
struct LinuxTray {
|
||||
tx: Sender<NativeEvent>,
|
||||
icons: Arc<Vec<ksni::Icon>>,
|
||||
is_ru: bool,
|
||||
window_visible: bool,
|
||||
is_playing: bool,
|
||||
track_summary: String,
|
||||
}
|
||||
|
||||
impl ksni::Tray for LinuxTray {
|
||||
fn id(&self) -> String {
|
||||
"yandex-music-rs".into()
|
||||
}
|
||||
|
||||
fn category(&self) -> ksni::Category {
|
||||
ksni::Category::ApplicationStatus
|
||||
}
|
||||
|
||||
fn title(&self) -> String {
|
||||
if self.is_ru {
|
||||
"Яндекс Музыка".into()
|
||||
} else {
|
||||
"Yandex Music".into()
|
||||
}
|
||||
}
|
||||
|
||||
fn icon_name(&self) -> String {
|
||||
"yandex-music-rs".into()
|
||||
}
|
||||
|
||||
fn icon_pixmap(&self) -> Vec<ksni::Icon> {
|
||||
(*self.icons).clone()
|
||||
}
|
||||
|
||||
fn tool_tip(&self) -> ksni::ToolTip {
|
||||
ksni::ToolTip {
|
||||
icon_name: "yandex-music-rs".into(),
|
||||
icon_pixmap: Vec::new(),
|
||||
title: self.title(),
|
||||
description: self.track_summary.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
fn activate(&mut self, _x: i32, _y: i32) {
|
||||
let _ = self.tx.send(NativeEvent::ToggleWindow);
|
||||
}
|
||||
|
||||
fn menu(&self) -> Vec<ksni::MenuItem<Self>> {
|
||||
use ksni::menu::*;
|
||||
let toggle_label = if self.window_visible {
|
||||
if self.is_ru { "Скрыть" } else { "Hide" }
|
||||
} else if self.is_ru {
|
||||
"Показать"
|
||||
} else {
|
||||
"Show"
|
||||
};
|
||||
let play_label = if self.is_playing {
|
||||
if self.is_ru { "Пауза" } else { "Pause" }
|
||||
} else if self.is_ru {
|
||||
"Играть"
|
||||
} else {
|
||||
"Play"
|
||||
};
|
||||
let ver_label = if self.is_ru {
|
||||
format!("Яндекс Музыка {}", env!("CARGO_PKG_VERSION"))
|
||||
} else {
|
||||
format!("Yandex Music {}", env!("CARGO_PKG_VERSION"))
|
||||
};
|
||||
|
||||
vec![
|
||||
StandardItem {
|
||||
label: toggle_label.into(),
|
||||
activate: Box::new(|this: &mut Self| {
|
||||
let _ = this.tx.send(NativeEvent::ToggleWindow);
|
||||
}),
|
||||
..Default::default()
|
||||
}
|
||||
.into(),
|
||||
StandardItem {
|
||||
label: if self.is_ru {
|
||||
"Проверить обновления".into()
|
||||
} else {
|
||||
"Check updates".into()
|
||||
},
|
||||
activate: Box::new(|this: &mut Self| {
|
||||
let _ = this.tx.send(NativeEvent::CheckUpdates);
|
||||
}),
|
||||
..Default::default()
|
||||
}
|
||||
.into(),
|
||||
MenuItem::Separator,
|
||||
StandardItem {
|
||||
label: play_label.into(),
|
||||
activate: Box::new(|this: &mut Self| {
|
||||
let _ = this.tx.send(NativeEvent::TogglePlay);
|
||||
}),
|
||||
..Default::default()
|
||||
}
|
||||
.into(),
|
||||
StandardItem {
|
||||
label: if self.is_ru {
|
||||
"Предыдущий трек".into()
|
||||
} else {
|
||||
"Previous song".into()
|
||||
},
|
||||
activate: Box::new(|this: &mut Self| {
|
||||
let _ = this.tx.send(NativeEvent::Prev);
|
||||
}),
|
||||
..Default::default()
|
||||
}
|
||||
.into(),
|
||||
StandardItem {
|
||||
label: if self.is_ru {
|
||||
"Следующий трек".into()
|
||||
} else {
|
||||
"Next song".into()
|
||||
},
|
||||
activate: Box::new(|this: &mut Self| {
|
||||
let _ = this.tx.send(NativeEvent::Next);
|
||||
}),
|
||||
..Default::default()
|
||||
}
|
||||
.into(),
|
||||
MenuItem::Separator,
|
||||
SubMenu {
|
||||
label: if self.is_ru {
|
||||
"О приложении".into()
|
||||
} else {
|
||||
"About the app".into()
|
||||
},
|
||||
submenu: vec![StandardItem {
|
||||
label: ver_label,
|
||||
enabled: false,
|
||||
..Default::default()
|
||||
}
|
||||
.into()],
|
||||
..Default::default()
|
||||
}
|
||||
.into(),
|
||||
MenuItem::Separator,
|
||||
StandardItem {
|
||||
label: if self.is_ru {
|
||||
"Закрыть приложение".into()
|
||||
} else {
|
||||
"Close app".into()
|
||||
},
|
||||
activate: Box::new(|this: &mut Self| {
|
||||
let _ = this.tx.send(NativeEvent::QuitApp);
|
||||
}),
|
||||
..Default::default()
|
||||
}
|
||||
.into(),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
fn decode_ksni_icon(png_bytes: &[u8]) -> Option<ksni::Icon> {
|
||||
let img = image::load_from_memory(png_bytes).ok()?.to_rgba8();
|
||||
let (w, h) = img.dimensions();
|
||||
let mut data = img.into_raw();
|
||||
for px in data.chunks_exact_mut(4) {
|
||||
px.rotate_right(1); // RGBA -> ARGB32 network byte order (SNI spec)
|
||||
}
|
||||
Some(ksni::Icon {
|
||||
width: w as i32,
|
||||
height: h as i32,
|
||||
data,
|
||||
})
|
||||
}
|
||||
|
||||
pub struct NativeDesktop {
|
||||
handle: Option<Handle<LinuxTray>>,
|
||||
rx: Receiver<NativeEvent>,
|
||||
last_playing: Option<bool>,
|
||||
last_track_id: Option<String>,
|
||||
}
|
||||
|
||||
impl Drop for NativeDesktop {
|
||||
fn drop(&mut self) {
|
||||
if let Some(ref handle) = self.handle {
|
||||
handle.shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl NativeDesktop {
|
||||
pub fn new(_window: &Window, _is_ru: bool) -> Self {
|
||||
Self
|
||||
pub fn new(_window: &Window, is_ru: bool) -> Self {
|
||||
let (tx, rx) = unbounded();
|
||||
let mut pixmaps = Vec::with_capacity(2);
|
||||
if let Some(ic32) = decode_ksni_icon(include_bytes!("../../assets/icons/tray_32.png")) {
|
||||
pixmaps.push(ic32);
|
||||
}
|
||||
if let Some(ic48) = decode_ksni_icon(include_bytes!("../../assets/icons/app_48.png")) {
|
||||
pixmaps.push(ic48);
|
||||
}
|
||||
let tray = LinuxTray {
|
||||
tx,
|
||||
icons: Arc::new(pixmaps),
|
||||
is_ru,
|
||||
window_visible: true,
|
||||
is_playing: false,
|
||||
track_summary: String::new(),
|
||||
};
|
||||
let handle = tray.assume_sni_available(true).spawn().ok();
|
||||
Self {
|
||||
handle,
|
||||
rx,
|
||||
last_playing: None,
|
||||
last_track_id: None,
|
||||
}
|
||||
}
|
||||
pub fn set_window_visible_label(&self, _visible: bool) {}
|
||||
|
||||
pub fn set_window_visible_label(&self, visible: bool) {
|
||||
if let Some(ref handle) = self.handle {
|
||||
handle.update(move |t| {
|
||||
t.window_visible = visible;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
pub fn poll_events(&self) -> Vec<NativeEvent> {
|
||||
Vec::new()
|
||||
let mut out = Vec::new();
|
||||
while let Ok(ev) = self.rx.try_recv() {
|
||||
out.push(ev);
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
pub fn sync_playback(&mut self, track: Option<&Track>, is_playing: bool, _pos_ms: u64) {
|
||||
let track_id = track.map(|t| t.id.as_str());
|
||||
if self.last_playing == Some(is_playing) && self.last_track_id.as_deref() == track_id {
|
||||
return;
|
||||
}
|
||||
self.last_playing = Some(is_playing);
|
||||
self.last_track_id = track_id.map(String::from);
|
||||
let summary = track
|
||||
.map(|tr| {
|
||||
let artists = tr.artists_string();
|
||||
if artists.is_empty() {
|
||||
tr.title.clone()
|
||||
} else {
|
||||
format!("{} — {}", artists, tr.title)
|
||||
}
|
||||
})
|
||||
.unwrap_or_default();
|
||||
if let Some(ref handle) = self.handle {
|
||||
handle.update(move |t| {
|
||||
t.is_playing = is_playing;
|
||||
t.track_summary = summary;
|
||||
});
|
||||
}
|
||||
}
|
||||
pub fn sync_playback(&mut self, _track: Option<&Track>, _is_playing: bool, _pos_ms: u64) {}
|
||||
}
|
||||
|
||||
pub fn load_window_icon() -> Option<winit::window::Icon> {
|
||||
|
|
|
|||
|
|
@ -3812,7 +3812,7 @@ impl SplashPlayer {
|
|||
/// Spawns a bounded 4-frame background WebP decoder selecting `splash_dark.webp` on `#000`
|
||||
/// or `splash_light.webp` on `#FFF` to match official Yandex Music 5.129.0 SplashScreen 1-to-1!
|
||||
pub fn spawn(is_dark: bool) -> Self {
|
||||
let (tx, rx) = crossbeam_channel::bounded::<SplashFrame>(4);
|
||||
let (tx, rx) = crossbeam_channel::bounded::<SplashFrame>(1);
|
||||
std::thread::Builder::new()
|
||||
.name("ym-splash-decode".into())
|
||||
.spawn(move || {
|
||||
|
|
|
|||
|
|
@ -80,42 +80,58 @@ pub fn render_sidebar(
|
|||
}
|
||||
}
|
||||
|
||||
// Collapse button on hover (`.NavbarDesktop_collapseButton`: 16×28px pill, 6px radius)
|
||||
let sidebar_hovered = ctx.is_hovered(sidebar_rect);
|
||||
if sidebar_hovered {
|
||||
let col_btn_rect = Rect::from_center_size(
|
||||
Pos2::new(sidebar_rect.right() - 8.0, sidebar_rect.top() + 22.0),
|
||||
Vec2::new(16.0, 28.0),
|
||||
);
|
||||
let col_resp = ctx.interact(WidgetId::new("sb_collapse"), col_btn_rect);
|
||||
ctx.dl().push_rect(
|
||||
col_btn_rect,
|
||||
6.0,
|
||||
if col_resp.hovered {
|
||||
// Exact 5.129.0 `.NavbarDesktop_collapseButton__XQh9d` (`f43a2cc01fed8ead.css:157-198`):
|
||||
// - 16×28px pill (`width: 1rem`, `border-radius: 6px`), `margin-inline-end: -8px` overhanging
|
||||
// right onto the sidebar/content seam on `ZLayer::Drawer` (`z-index: header`) so the content
|
||||
// card never clips its right half!
|
||||
// - Smooth 0.20s opacity fade on sidebar OR button hover; 16×16 `xxs` chevron inside;
|
||||
// tooltip ("Развернуть"/"Expand") shown ONLY when collapsed (`enabled: s`).
|
||||
let col_btn_rect = Rect::from_center_size(
|
||||
Pos2::new(sidebar_rect.right(), sidebar_rect.top() + 20.0),
|
||||
Vec2::new(16.0, 28.0),
|
||||
);
|
||||
let show_col_target =
|
||||
!app.fullscreen_open && (ctx.is_hovered(sidebar_rect) || ctx.is_hovered(col_btn_rect));
|
||||
let col_vis = ctx.animate_bool(WidgetId::new("sb_col_vis"), show_col_target, 0.20);
|
||||
if col_vis > 0.01 {
|
||||
ctx.with_layer(ZLayer::Drawer, |ctx| {
|
||||
let col_resp = ctx.interact(WidgetId::new("sb_collapse"), col_btn_rect);
|
||||
let bg_col = if col_resp.hovered {
|
||||
pal.surface_hover
|
||||
} else {
|
||||
pal.surface_secondary
|
||||
},
|
||||
);
|
||||
ctx.draw_icon(
|
||||
if collapsed {
|
||||
Icon::ArrowRightXxs
|
||||
} else {
|
||||
Icon::ArrowLeftXxs
|
||||
},
|
||||
Rect::from_center_size(col_btn_rect.center(), Vec2::splat(20.0)),
|
||||
if col_resp.hovered {
|
||||
}
|
||||
.scale_alpha(col_vis);
|
||||
let icon_col = if col_resp.hovered {
|
||||
pal.text_primary
|
||||
} else {
|
||||
pal.text_secondary
|
||||
},
|
||||
);
|
||||
if col_resp.hovered {
|
||||
ctx.set_cursor(CursorKind::Pointer);
|
||||
}
|
||||
if col_resp.clicked {
|
||||
actions.push(AppAction::ToggleSidebarCollapse);
|
||||
}
|
||||
Color::rgb(0x80, 0x80, 0x80)
|
||||
}
|
||||
.scale_alpha(col_vis);
|
||||
|
||||
ctx.dl().push_rect(col_btn_rect, 6.0, bg_col);
|
||||
ctx.draw_icon(
|
||||
if collapsed {
|
||||
Icon::ArrowRightXxs
|
||||
} else {
|
||||
Icon::ArrowLeftXxs
|
||||
},
|
||||
Rect::from_center_size(col_btn_rect.center(), Vec2::splat(16.0)),
|
||||
icon_col,
|
||||
);
|
||||
if col_resp.hovered {
|
||||
ctx.set_cursor(CursorKind::Pointer);
|
||||
if collapsed {
|
||||
ctx.show_tooltip(
|
||||
col_btn_rect,
|
||||
if ru { "Развернуть" } else { "Expand" },
|
||||
);
|
||||
}
|
||||
}
|
||||
if col_resp.clicked {
|
||||
actions.push(AppAction::ToggleSidebarCollapse);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 2. Navigation Items (exact 5.129.0 order + optional Kids section)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue