use std::borrow::Cow; use gpui_kit::{AssetSource, SharedString, assets::AllAssets}; pub const PATH: &str = "yumush/logo.svg"; pub const NEEDLE: &str = "yumush/needle.svg"; const WINDOW_ICON: u32 = 256; mod svg; pub use svg::{NAME, rgba}; use svg::{icon, mark, needle}; pub fn window_icon() -> std::sync::Arc { std::sync::Arc::new( image::RgbaImage::from_raw(WINDOW_ICON, WINDOW_ICON, rgba(WINDOW_ICON)) .expect("icon pixels"), ) } #[cfg(target_os = "linux")] pub fn install() -> std::io::Result<()> { let data = dirs::data_dir().ok_or(std::io::ErrorKind::NotFound)?; let exe = crate::exe().ok_or(std::io::ErrorKind::NotFound)?; put( &data .join("icons/hicolor/scalable/apps") .join(format!("{NAME}.svg")), &icon(), )?; put( &data.join("applications").join(format!("{NAME}.desktop")), &format!( "[Desktop Entry]\nType=Application\nName={}\nExec=\"{}\"\nIcon={NAME}\nStartupWMClass={NAME}\nCategories=Network;Chat;\nTerminal=false\n", crate::NAME, exe.display() ), ) } #[cfg(any(target_os = "linux", target_os = "macos"))] pub(crate) fn put(path: &std::path::Path, content: &str) -> std::io::Result<()> { if std::fs::read_to_string(path).is_ok_and(|old| old == content) { return Ok(()); } if let Some(parent) = path.parent() { std::fs::create_dir_all(parent)?; } std::fs::write(path, content) } pub struct Assets; impl AssetSource for Assets { fn load(&self, path: &str) -> gpui_kit::Result>> { if path == PATH { return Ok(Some(Cow::Owned(mark().into_bytes()))); } if path == NEEDLE { return Ok(Some(Cow::Owned(needle().into_bytes()))); } AllAssets.load(path) } fn list(&self, path: &str) -> gpui_kit::Result> { AllAssets.list(path) } }