diff --git a/crates/client/Cargo.toml b/crates/client/Cargo.toml index 688dd10..d307f02 100644 --- a/crates/client/Cargo.toml +++ b/crates/client/Cargo.toml @@ -56,6 +56,10 @@ tray-icon = { version = "0.27.0", default-features = false } coreaudio-rs = "0.14.2" [build-dependencies] +embed-resource = "3.0.12" +icns = "0.5.0" +ico = "0.6.0" +resvg = "0.50.0" toml = "1.2.3" [lints] diff --git a/crates/client/build.rs b/crates/client/build.rs index 34caf8c..d348a52 100644 --- a/crates/client/build.rs +++ b/crates/client/build.rs @@ -1,8 +1,21 @@ -use std::{env, fmt::Write, fs, path::Path}; +use std::{ + env, + fmt::Write, + fs, + path::{Path, PathBuf}, +}; use toml::{Table, Value}; +#[allow(dead_code)] +#[path = "src/logo/svg.rs"] +mod svg; + const SOURCE: &str = "design/tokens.toml"; +const ICO_SIZES: [u32; 6] = [16, 24, 32, 48, 64, 256]; +const MAC_CANVAS: u32 = 1024; +const MAC_BODY: u32 = 824; +const ICNS_SIZES: [u32; 7] = [16, 32, 64, 128, 256, 512, 1024]; const COLORS: [&str; 10] = [ "ground", "raise", "hov", "press", "thread", "off", "faint", "dim", "paper", "bad", ]; @@ -11,6 +24,7 @@ const MEDIA_FOUNDATION: [&str; 3] = ["mf.dll", "mfplat.dll", "mfreadwrite.dll"]; fn main() { println!("cargo::rerun-if-changed={SOURCE}"); + icons(); if env::var("CARGO_CFG_TARGET_ENV").as_deref() == Ok("msvc") { for dll in MEDIA_FOUNDATION { println!("cargo::rustc-link-arg-bins=/DELAYLOAD:{dll}"); @@ -128,3 +142,55 @@ fn hex(color: &str) -> String { assert_eq!(digits.len(), 6, "{color}: #rrggbb"); format!("0x{digits}") } + +fn icons() { + println!("cargo::rerun-if-changed=src/logo/svg.rs"); + let out = PathBuf::from(env::var("OUT_DIR").expect("OUT_DIR")); + + let mut ico = ico::IconDir::new(ico::ResourceType::Icon); + for size in ICO_SIZES { + let image = ico::IconImage::from_rgba_data(size, size, svg::rgba(size)); + ico.add_entry(ico::IconDirEntry::encode(&image).expect("ico entry")); + } + let ico_path = out.join(format!("{}.ico", svg::NAME)); + ico.write(fs::File::create(&ico_path).expect("ico file")) + .expect("write ico"); + + let mut icns = icns::IconFamily::new(); + for size in ICNS_SIZES { + let image = icns::Image::from_data(icns::PixelFormat::RGBA, size, size, inset(size)) + .expect("icns image"); + icns.add_icon(&image).expect("icns entry"); + } + icns.write(fs::File::create(out.join(format!("{}.icns", svg::NAME))).expect("icns file")) + .expect("write icns"); + + if env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("windows") { + let rc = out.join("icon.rc"); + fs::write( + &rc, + format!( + "1 ICON \"{}\"\n", + ico_path.display().to_string().replace('\\', "/") + ), + ) + .expect("write rc"); + embed_resource::compile(&rc, embed_resource::NONE) + .manifest_optional() + .expect("embed icon"); + } +} + +fn inset(size: u32) -> Vec { + let inner = size * MAC_BODY / MAC_CANVAS; + let offset = (size - inner) / 2; + let body = svg::rgba(inner); + let mut canvas = vec![0; (size * size * 4) as usize]; + for row in 0..inner { + let from = (row * inner * 4) as usize; + let to = (((row + offset) * size + offset) * 4) as usize; + canvas[to..to + (inner * 4) as usize] + .copy_from_slice(&body[from..from + (inner * 4) as usize]); + } + canvas +} diff --git a/crates/client/src/logo.rs b/crates/client/src/logo.rs index a322a3c..be2e763 100644 --- a/crates/client/src/logo.rs +++ b/crates/client/src/logo.rs @@ -3,24 +3,48 @@ use std::borrow::Cow; use gpui_kit::{AssetSource, SharedString, assets::AllAssets}; pub const PATH: &str = "yumush/logo.svg"; +const WINDOW_ICON: u32 = 256; -fn svg(view: &str, background: &str, needle: &str, thread: &str) -> String { - format!( - r##"{background}"## +mod svg; + +pub use svg::{NAME, icon, mark, rgba}; + +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"), ) } -pub fn mark() -> String { - svg("14 12 76 76", "", "#000", "#000") +#[cfg(target_os = "linux")] +pub fn install() -> std::io::Result<()> { + let data = dirs::data_dir().ok_or(std::io::ErrorKind::NotFound)?; + let exe = std::env::current_exe()?; + 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() + ), + ) } -pub fn icon() -> String { - svg( - "0 0 100 100", - r##""##, - "#ece5d8", - "#ffb36b", - ) +#[cfg(target_os = "linux")] +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; diff --git a/crates/client/src/logo/svg.rs b/crates/client/src/logo/svg.rs new file mode 100644 index 0000000..a33dd68 --- /dev/null +++ b/crates/client/src/logo/svg.rs @@ -0,0 +1,39 @@ +pub const NAME: &str = "yumush"; + +fn svg(view: &str, background: &str, needle: &str, thread: &str) -> String { + format!( + r##"{background}"## + ) +} + +pub fn mark() -> String { + svg("14 12 76 76", "", "#000", "#000") +} + +pub fn icon() -> String { + svg( + "0 0 100 100", + r##""##, + "#ece5d8", + "#ffb36b", + ) +} + +pub fn rgba(size: u32) -> Vec { + let tree = resvg::usvg::Tree::from_str(&icon(), &Default::default()).expect("logo svg"); + let mut pixmap = resvg::tiny_skia::Pixmap::new(size, size).expect("icon size"); + let scale = size as f32 / tree.size().width(); + resvg::render( + &tree, + resvg::tiny_skia::Transform::from_scale(scale, scale), + &mut pixmap.as_mut(), + ); + pixmap + .pixels() + .iter() + .flat_map(|pixel| { + let color = pixel.demultiply(); + [color.red(), color.green(), color.blue(), color.alpha()] + }) + .collect() +} diff --git a/crates/client/src/main.rs b/crates/client/src/main.rs index 9f8eab8..13de372 100644 --- a/crates/client/src/main.rs +++ b/crates/client/src/main.rs @@ -41,6 +41,10 @@ fn main() { return; } + #[cfg(target_os = "linux")] + if let Err(error) = client::logo::install() { + tracing::warn!("desktop entry: {error}"); + } let settings = settings::load(); let (network_handle, network_event_receiver) = net::start(Server::load()); @@ -148,6 +152,8 @@ fn open_window( WindowOptions { window_bounds: Some(WindowBounds::Windowed(window_bounds)), titlebar: Some(titlebar), + app_id: Some(client::logo::NAME.into()), + icon: Some(client::logo::window_icon()), inactive_frame_interval: None, ..Default::default() }, diff --git a/crates/client/src/tray.rs b/crates/client/src/tray.rs index 4118944..7b86a73 100644 --- a/crates/client/src/tray.rs +++ b/crates/client/src/tray.rs @@ -81,22 +81,9 @@ fn coverage(x: f32, y: f32, (cx, cy, radius): (f32, f32, f32)) -> f32 { #[cfg(any(target_os = "linux", target_os = "windows"))] fn logo() -> Vec<([u8; 3], u8)> { - let tree = - resvg::usvg::Tree::from_str(&crate::logo::icon(), &Default::default()).expect("logo svg"); - let mut pixmap = - resvg::tiny_skia::Pixmap::new(ICON_SIZE as u32, ICON_SIZE as u32).expect("icon size"); - resvg::render( - &tree, - resvg::tiny_skia::Transform::default(), - &mut pixmap.as_mut(), - ); - pixmap - .pixels() - .iter() - .map(|pixel| { - let color = pixel.demultiply(); - ([color.red(), color.green(), color.blue()], color.alpha()) - }) + crate::logo::rgba(ICON_SIZE as u32) + .chunks_exact(4) + .map(|pixel| ([pixel[0], pixel[1], pixel[2]], pixel[3])) .collect() } diff --git a/harness/client.sh b/harness/client.sh index 2c5f37f..1077b16 100755 --- a/harness/client.sh +++ b/harness/client.sh @@ -6,6 +6,6 @@ STATE="${HARNESS_STATE:-/tmp/claude-1000/yumush-harness}" NAME="$1" source "${ENV_FILE:-$STATE/env}" mkdir -p "$STATE/clients/$NAME" -YUMUSH_ANY_CERT=1 YUMUSH_SERVER_ADDRESS="127.0.0.1:${HARNESS_PORT:-2027}" XDG_CONFIG_HOME="$STATE/clients/$NAME" RUST_LOG="${RUST_LOG:-info}" "$ROOT/target/${PROFILE:-harness}/client" >"$STATE/$NAME.log" 2>&1 & +YUMUSH_ANY_CERT=1 YUMUSH_SERVER_ADDRESS="127.0.0.1:${HARNESS_PORT:-2027}" XDG_CONFIG_HOME="$STATE/clients/$NAME" XDG_DATA_HOME="$STATE/clients/$NAME/data" RUST_LOG="${RUST_LOG:-info}" "$ROOT/target/${PROFILE:-harness}/client" >"$STATE/$NAME.log" 2>&1 & echo "$NAME $!" >> "$STATE/pids" echo "$NAME $!" diff --git a/packaging/macos.sh b/packaging/macos.sh new file mode 100755 index 0000000..91c440e --- /dev/null +++ b/packaging/macos.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +set -euo pipefail +ROOT="$(cd "$(dirname "$0")/.." && pwd)" +PROFILE="${1:-release}" +cd "$ROOT" +OUT=$(cargo build --profile "$PROFILE" -p client --message-format=json | python3 -c ' +import sys, json +for line in sys.stdin: + m = json.loads(line) + if m.get("reason") == "build-script-executed" and "/crates/client" in m["package_id"]: + print(m["out_dir"])') +DIR="${PROFILE/dev/debug}" +APP="target/$DIR/Yumush.app" +rm -rf "$APP" +mkdir -p "$APP/Contents/MacOS" "$APP/Contents/Resources" +cp "target/$DIR/client" "$APP/Contents/MacOS/yumush" +cp "$OUT/yumush.icns" "$APP/Contents/Resources/yumush.icns" +VERSION=$(cargo pkgid -p client | sed 's/.*[#@]//') +cat > "$APP/Contents/Info.plist" < + + + + CFBundleNameYumush + CFBundleDisplayNameyumuß + CFBundleIdentifiercom.yumush.client + CFBundleExecutableyumush + CFBundleIconFileyumush + CFBundlePackageTypeAPPL + CFBundleShortVersionString$VERSION + CFBundleVersion$VERSION + NSHighResolutionCapable + NSMicrophoneUsageDescriptionVoice calls + NSCameraUsageDescriptionVideo calls + + +PLIST +echo "$APP"