//! Hex's app icon on Linux: `anomaly.hex` in the hicolor theme, the name its //! desktop entries and window app id use. Packages install it under //! `/usr/share/icons`; a direct or source install and a downloaded executable //! have no package, so Hex writes the same PNGs into the user's icon theme at //! startup (#652). Each PNG carries an `X-Hex-Managed=true` text chunk, so //! Hex replaces, and the installer removes, only icons Hex wrote: a user's own //! `anomaly.hex.png` or a symlink stays. //! //! [`install_tray_symbolic`] writes the tray's own `anomaly.hex-symbolic.svg` //! beside them, always: it is a runtime tray asset, not a packaged app icon. //! Its KDE `current-color-scheme` stylesheet lets Plasma 6 draw the mark in the //! panel's text color; GNOME's AppIndicator extension and Waybar recolor the //! `-symbolic` name with the bar's foreground. use std::io::{ErrorKind, Write}; use std::path::Path; use color_eyre::eyre::{Result, WrapErr}; use crate::linux::portal::APP_ID; macro_rules! icon { ($size:literal) => { ( $size, include_bytes!(concat!( "../../packaging/linux/icons/hicolor/", $size, "x", $size, "/apps/anomaly.hex.png" )) .as_slice(), ) }; } /// Every size the packages install, in pixels. const ICONS: [(&str, &[u8]); 8] = [ icon!("16"), icon!("24"), icon!("32"), icon!("48"), icon!("64"), icon!("128"), icon!("256"), icon!("512"), ]; /// Writes Hex's icon into the user's hicolor theme, unless a package /// already installs it; rewrites only icons that differ. pub(crate) fn install() -> Result<()> { let Some(home) = dirs::data_dir() else { return Ok(()); }; let canonical = |dir: &Path| std::fs::canonicalize(dir).unwrap_or_else(|_| dir.into()); let own = canonical(&home); // Some profiles list the user's own data directory in XDG_DATA_DIRS too. let packaged = crate::linux::portal::system_data_dirs() .iter() .filter(|dir| canonical(dir) != own) .any(|dir| icon_path(dir, "48").exists()); if packaged { return Ok(()); } install_in(&home) } const MANAGED_MARK: &[u8] = b"X-Hex-Managed=true"; /// The tray's symbolic icon in the user's hicolor theme. pub(crate) const TRAY_ICON: &str = "anomaly.hex-symbolic"; /// The symbolic mark, its default color in the `