App icon on every platform from the one logo source: embedded .ico in the Windows exe, X11 window icon + app_id + self-written ~/.local desktop entry on Linux, .icns + packaging/macos.sh .app bundle on macOS
Browse files at this commit679ab9544a24403ffa2dceb9e4494d802d66c337Parent: a4b71d1- feat
- app icon on every platform from the one logo source: embedded .ico in the Windows exe, X11 window icon + app_id + self-written ~/.local desktop entry on Linux, .icns + packaging/macos.sh .app bundle on macOS
8 changed files +194 -30
- crates/client/Cargo.toml +4 -0
- crates/client/build.rs +67 -1
- crates/client/src/logo.rs +36 -12
- crates/client/src/logo/svg.rs +39 -0
- crates/client/src/main.rs +6 -0
- crates/client/src/tray.rs +3 -16
- harness/client.sh +1 -1
- packaging/macos.sh +38 -0
crates/client/Cargo.tomlmodified+4 -0
| @@ -56,6 +56,10 @@ tray-icon = { version = "0.27.0", default-features = false } | |||
| 56 | coreaudio-rs = "0.14.2" | 56 | coreaudio-rs = "0.14.2" |
| 57 | 57 | ||
| 58 | [build-dependencies] | 58 | [build-dependencies] |
| 59 | +embed-resource = "3.0.12" | ||
| 60 | +icns = "0.5.0" | ||
| 61 | +ico = "0.6.0" | ||
| 62 | +resvg = "0.50.0" | ||
| 59 | toml = "1.2.3" | 63 | toml = "1.2.3" |
| 60 | 64 | ||
| 61 | [lints] | 65 | [lints] |
crates/client/build.rsmodified+67 -1
| @@ -1,8 +1,21 @@ | |||
| 1 | -use std::{env, fmt::Write, fs, path::Path}; | 1 | +use std::{ |
| 2 | + env, | ||
| 3 | + fmt::Write, | ||
| 4 | + fs, | ||
| 5 | + path::{Path, PathBuf}, | ||
| 6 | +}; | ||
| 2 | 7 | ||
| 3 | use toml::{Table, Value}; | 8 | use toml::{Table, Value}; |
| 4 | 9 | ||
| 10 | +#[allow(dead_code)] | ||
| 11 | +#[path = "src/logo/svg.rs"] | ||
| 12 | +mod svg; | ||
| 13 | + | ||
| 5 | const SOURCE: &str = "design/tokens.toml"; | 14 | const SOURCE: &str = "design/tokens.toml"; |
| 15 | +const ICO_SIZES: [u32; 6] = [16, 24, 32, 48, 64, 256]; | ||
| 16 | +const MAC_CANVAS: u32 = 1024; | ||
| 17 | +const MAC_BODY: u32 = 824; | ||
| 18 | +const ICNS_SIZES: [u32; 7] = [16, 32, 64, 128, 256, 512, 1024]; | ||
| 6 | const COLORS: [&str; 10] = [ | 19 | const COLORS: [&str; 10] = [ |
| 7 | "ground", "raise", "hov", "press", "thread", "off", "faint", "dim", "paper", "bad", | 20 | "ground", "raise", "hov", "press", "thread", "off", "faint", "dim", "paper", "bad", |
| 8 | ]; | 21 | ]; |
| @@ -11,6 +24,7 @@ const MEDIA_FOUNDATION: [&str; 3] = ["mf.dll", "mfplat.dll", "mfreadwrite.dll"]; | |||
| 11 | 24 | ||
| 12 | fn main() { | 25 | fn main() { |
| 13 | println!("cargo::rerun-if-changed={SOURCE}"); | 26 | println!("cargo::rerun-if-changed={SOURCE}"); |
| 27 | + icons(); | ||
| 14 | if env::var("CARGO_CFG_TARGET_ENV").as_deref() == Ok("msvc") { | 28 | if env::var("CARGO_CFG_TARGET_ENV").as_deref() == Ok("msvc") { |
| 15 | for dll in MEDIA_FOUNDATION { | 29 | for dll in MEDIA_FOUNDATION { |
| 16 | println!("cargo::rustc-link-arg-bins=/DELAYLOAD:{dll}"); | 30 | println!("cargo::rustc-link-arg-bins=/DELAYLOAD:{dll}"); |
| @@ -128,3 +142,55 @@ fn hex(color: &str) -> String { | |||
| 128 | assert_eq!(digits.len(), 6, "{color}: #rrggbb"); | 142 | assert_eq!(digits.len(), 6, "{color}: #rrggbb"); |
| 129 | format!("0x{digits}") | 143 | format!("0x{digits}") |
| 130 | } | 144 | } |
| 145 | + | ||
| 146 | +fn icons() { | ||
| 147 | + println!("cargo::rerun-if-changed=src/logo/svg.rs"); | ||
| 148 | + let out = PathBuf::from(env::var("OUT_DIR").expect("OUT_DIR")); | ||
| 149 | + | ||
| 150 | + let mut ico = ico::IconDir::new(ico::ResourceType::Icon); | ||
| 151 | + for size in ICO_SIZES { | ||
| 152 | + let image = ico::IconImage::from_rgba_data(size, size, svg::rgba(size)); | ||
| 153 | + ico.add_entry(ico::IconDirEntry::encode(&image).expect("ico entry")); | ||
| 154 | + } | ||
| 155 | + let ico_path = out.join(format!("{}.ico", svg::NAME)); | ||
| 156 | + ico.write(fs::File::create(&ico_path).expect("ico file")) | ||
| 157 | + .expect("write ico"); | ||
| 158 | + | ||
| 159 | + let mut icns = icns::IconFamily::new(); | ||
| 160 | + for size in ICNS_SIZES { | ||
| 161 | + let image = icns::Image::from_data(icns::PixelFormat::RGBA, size, size, inset(size)) | ||
| 162 | + .expect("icns image"); | ||
| 163 | + icns.add_icon(&image).expect("icns entry"); | ||
| 164 | + } | ||
| 165 | + icns.write(fs::File::create(out.join(format!("{}.icns", svg::NAME))).expect("icns file")) | ||
| 166 | + .expect("write icns"); | ||
| 167 | + | ||
| 168 | + if env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("windows") { | ||
| 169 | + let rc = out.join("icon.rc"); | ||
| 170 | + fs::write( | ||
| 171 | + &rc, | ||
| 172 | + format!( | ||
| 173 | + "1 ICON \"{}\"\n", | ||
| 174 | + ico_path.display().to_string().replace('\\', "/") | ||
| 175 | + ), | ||
| 176 | + ) | ||
| 177 | + .expect("write rc"); | ||
| 178 | + embed_resource::compile(&rc, embed_resource::NONE) | ||
| 179 | + .manifest_optional() | ||
| 180 | + .expect("embed icon"); | ||
| 181 | + } | ||
| 182 | +} | ||
| 183 | + | ||
| 184 | +fn inset(size: u32) -> Vec<u8> { | ||
| 185 | + let inner = size * MAC_BODY / MAC_CANVAS; | ||
| 186 | + let offset = (size - inner) / 2; | ||
| 187 | + let body = svg::rgba(inner); | ||
| 188 | + let mut canvas = vec![0; (size * size * 4) as usize]; | ||
| 189 | + for row in 0..inner { | ||
| 190 | + let from = (row * inner * 4) as usize; | ||
| 191 | + let to = (((row + offset) * size + offset) * 4) as usize; | ||
| 192 | + canvas[to..to + (inner * 4) as usize] | ||
| 193 | + .copy_from_slice(&body[from..from + (inner * 4) as usize]); | ||
| 194 | + } | ||
| 195 | + canvas | ||
| 196 | +} | ||
crates/client/src/logo.rsmodified+36 -12
| @@ -3,24 +3,48 @@ use std::borrow::Cow; | |||
| 3 | use gpui_kit::{AssetSource, SharedString, assets::AllAssets}; | 3 | use gpui_kit::{AssetSource, SharedString, assets::AllAssets}; |
| 4 | 4 | ||
| 5 | pub const PATH: &str = "yumush/logo.svg"; | 5 | pub const PATH: &str = "yumush/logo.svg"; |
| 6 | +const WINDOW_ICON: u32 = 256; | ||
| 6 | 7 | ||
| 7 | -fn svg(view: &str, background: &str, needle: &str, thread: &str) -> String { | 8 | +mod svg; |
| 8 | - format!( | 9 | + |
| 9 | - r##"<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="{view}">{background}<mask id="eye"><rect width="100" height="100" fill="#fff"/><ellipse cx="68" cy="27.5" rx="2.2" ry="5" transform="rotate(39 68 27.5)" fill="#000"/></mask><path d="M26 80 L74 20" stroke="{needle}" stroke-width="7" stroke-linecap="round" mask="url(#eye)"/><path d="M68 28 C80 40 76 56 60 58 C44 60 40 74 52 84" fill="none" stroke="{thread}" stroke-width="5" stroke-linecap="round"/></svg>"## | 10 | +pub use svg::{NAME, icon, mark, rgba}; |
| 11 | + | ||
| 12 | +pub fn window_icon() -> std::sync::Arc<image::RgbaImage> { | ||
| 13 | + std::sync::Arc::new( | ||
| 14 | + image::RgbaImage::from_raw(WINDOW_ICON, WINDOW_ICON, rgba(WINDOW_ICON)) | ||
| 15 | + .expect("icon pixels"), | ||
| 10 | ) | 16 | ) |
| 11 | } | 17 | } |
| 12 | 18 | ||
| 13 | -pub fn mark() -> String { | 19 | +#[cfg(target_os = "linux")] |
| 14 | - svg("14 12 76 76", "", "#000", "#000") | 20 | +pub fn install() -> std::io::Result<()> { |
| 21 | + let data = dirs::data_dir().ok_or(std::io::ErrorKind::NotFound)?; | ||
| 22 | + let exe = std::env::current_exe()?; | ||
| 23 | + put( | ||
| 24 | + &data | ||
| 25 | + .join("icons/hicolor/scalable/apps") | ||
| 26 | + .join(format!("{NAME}.svg")), | ||
| 27 | + &icon(), | ||
| 28 | + )?; | ||
| 29 | + put( | ||
| 30 | + &data.join("applications").join(format!("{NAME}.desktop")), | ||
| 31 | + &format!( | ||
| 32 | + "[Desktop Entry]\nType=Application\nName={}\nExec=\"{}\"\nIcon={NAME}\nStartupWMClass={NAME}\nCategories=Network;Chat;\nTerminal=false\n", | ||
| 33 | + crate::NAME, | ||
| 34 | + exe.display() | ||
| 35 | + ), | ||
| 36 | + ) | ||
| 15 | } | 37 | } |
| 16 | 38 | ||
| 17 | -pub fn icon() -> String { | 39 | +#[cfg(target_os = "linux")] |
| 18 | - svg( | 40 | +fn put(path: &std::path::Path, content: &str) -> std::io::Result<()> { |
| 19 | - "0 0 100 100", | 41 | + if std::fs::read_to_string(path).is_ok_and(|old| old == content) { |
| 20 | - r##"<rect width="100" height="100" rx="23" fill="#121527"/>"##, | 42 | + return Ok(()); |
| 21 | - "#ece5d8", | 43 | + } |
| 22 | - "#ffb36b", | 44 | + if let Some(parent) = path.parent() { |
| 23 | - ) | 45 | + std::fs::create_dir_all(parent)?; |
| 46 | + } | ||
| 47 | + std::fs::write(path, content) | ||
| 24 | } | 48 | } |
| 25 | 49 | ||
| 26 | pub struct Assets; | 50 | pub struct Assets; |
crates/client/src/logo/svg.rsadded+39 -0
| @@ -0,0 +1,39 @@ | |||
| 1 | +pub const NAME: &str = "yumush"; | ||
| 2 | + | ||
| 3 | +fn svg(view: &str, background: &str, needle: &str, thread: &str) -> String { | ||
| 4 | + format!( | ||
| 5 | + r##"<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="{view}">{background}<mask id="eye"><rect width="100" height="100" fill="#fff"/><ellipse cx="68" cy="27.5" rx="2.2" ry="5" transform="rotate(39 68 27.5)" fill="#000"/></mask><path d="M26 80 L74 20" stroke="{needle}" stroke-width="7" stroke-linecap="round" mask="url(#eye)"/><path d="M68 28 C80 40 76 56 60 58 C44 60 40 74 52 84" fill="none" stroke="{thread}" stroke-width="5" stroke-linecap="round"/></svg>"## | ||
| 6 | + ) | ||
| 7 | +} | ||
| 8 | + | ||
| 9 | +pub fn mark() -> String { | ||
| 10 | + svg("14 12 76 76", "", "#000", "#000") | ||
| 11 | +} | ||
| 12 | + | ||
| 13 | +pub fn icon() -> String { | ||
| 14 | + svg( | ||
| 15 | + "0 0 100 100", | ||
| 16 | + r##"<rect width="100" height="100" rx="23" fill="#121527"/>"##, | ||
| 17 | + "#ece5d8", | ||
| 18 | + "#ffb36b", | ||
| 19 | + ) | ||
| 20 | +} | ||
| 21 | + | ||
| 22 | +pub fn rgba(size: u32) -> Vec<u8> { | ||
| 23 | + let tree = resvg::usvg::Tree::from_str(&icon(), &Default::default()).expect("logo svg"); | ||
| 24 | + let mut pixmap = resvg::tiny_skia::Pixmap::new(size, size).expect("icon size"); | ||
| 25 | + let scale = size as f32 / tree.size().width(); | ||
| 26 | + resvg::render( | ||
| 27 | + &tree, | ||
| 28 | + resvg::tiny_skia::Transform::from_scale(scale, scale), | ||
| 29 | + &mut pixmap.as_mut(), | ||
| 30 | + ); | ||
| 31 | + pixmap | ||
| 32 | + .pixels() | ||
| 33 | + .iter() | ||
| 34 | + .flat_map(|pixel| { | ||
| 35 | + let color = pixel.demultiply(); | ||
| 36 | + [color.red(), color.green(), color.blue(), color.alpha()] | ||
| 37 | + }) | ||
| 38 | + .collect() | ||
| 39 | +} | ||
crates/client/src/main.rsmodified+6 -0
| @@ -41,6 +41,10 @@ fn main() { | |||
| 41 | return; | 41 | return; |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | + #[cfg(target_os = "linux")] | ||
| 45 | + if let Err(error) = client::logo::install() { | ||
| 46 | + tracing::warn!("desktop entry: {error}"); | ||
| 47 | + } | ||
| 44 | let settings = settings::load(); | 48 | let settings = settings::load(); |
| 45 | let (network_handle, network_event_receiver) = net::start(Server::load()); | 49 | let (network_handle, network_event_receiver) = net::start(Server::load()); |
| 46 | 50 | ||
| @@ -148,6 +152,8 @@ fn open_window( | |||
| 148 | WindowOptions { | 152 | WindowOptions { |
| 149 | window_bounds: Some(WindowBounds::Windowed(window_bounds)), | 153 | window_bounds: Some(WindowBounds::Windowed(window_bounds)), |
| 150 | titlebar: Some(titlebar), | 154 | titlebar: Some(titlebar), |
| 155 | + app_id: Some(client::logo::NAME.into()), | ||
| 156 | + icon: Some(client::logo::window_icon()), | ||
| 151 | inactive_frame_interval: None, | 157 | inactive_frame_interval: None, |
| 152 | ..Default::default() | 158 | ..Default::default() |
| 153 | }, | 159 | }, |
crates/client/src/tray.rsmodified+3 -16
| @@ -81,22 +81,9 @@ fn coverage(x: f32, y: f32, (cx, cy, radius): (f32, f32, f32)) -> f32 { | |||
| 81 | 81 | ||
| 82 | #[cfg(any(target_os = "linux", target_os = "windows"))] | 82 | #[cfg(any(target_os = "linux", target_os = "windows"))] |
| 83 | fn logo() -> Vec<([u8; 3], u8)> { | 83 | fn logo() -> Vec<([u8; 3], u8)> { |
| 84 | - let tree = | 84 | + crate::logo::rgba(ICON_SIZE as u32) |
| 85 | - resvg::usvg::Tree::from_str(&crate::logo::icon(), &Default::default()).expect("logo svg"); | 85 | + .chunks_exact(4) |
| 86 | - let mut pixmap = | 86 | + .map(|pixel| ([pixel[0], pixel[1], pixel[2]], pixel[3])) |
| 87 | - resvg::tiny_skia::Pixmap::new(ICON_SIZE as u32, ICON_SIZE as u32).expect("icon size"); | ||
| 88 | - resvg::render( | ||
| 89 | - &tree, | ||
| 90 | - resvg::tiny_skia::Transform::default(), | ||
| 91 | - &mut pixmap.as_mut(), | ||
| 92 | - ); | ||
| 93 | - pixmap | ||
| 94 | - .pixels() | ||
| 95 | - .iter() | ||
| 96 | - .map(|pixel| { | ||
| 97 | - let color = pixel.demultiply(); | ||
| 98 | - ([color.red(), color.green(), color.blue()], color.alpha()) | ||
| 99 | - }) | ||
| 100 | .collect() | 87 | .collect() |
| 101 | } | 88 | } |
| 102 | 89 | ||
harness/client.shmodified+1 -1
| @@ -6,6 +6,6 @@ STATE="${HARNESS_STATE:-/tmp/claude-1000/yumush-harness}" | |||
| 6 | NAME="$1" | 6 | NAME="$1" |
| 7 | source "${ENV_FILE:-$STATE/env}" | 7 | source "${ENV_FILE:-$STATE/env}" |
| 8 | mkdir -p "$STATE/clients/$NAME" | 8 | mkdir -p "$STATE/clients/$NAME" |
| 9 | -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 & | 9 | +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 & |
| 10 | echo "$NAME $!" >> "$STATE/pids" | 10 | echo "$NAME $!" >> "$STATE/pids" |
| 11 | echo "$NAME $!" | 11 | echo "$NAME $!" |
packaging/macos.shadded+38 -0
| @@ -0,0 +1,38 @@ | |||
| 1 | +#!/usr/bin/env bash | ||
| 2 | +set -euo pipefail | ||
| 3 | +ROOT="$(cd "$(dirname "$0")/.." && pwd)" | ||
| 4 | +PROFILE="${1:-release}" | ||
| 5 | +cd "$ROOT" | ||
| 6 | +OUT=$(cargo build --profile "$PROFILE" -p client --message-format=json | python3 -c ' | ||
| 7 | +import sys, json | ||
| 8 | +for line in sys.stdin: | ||
| 9 | + m = json.loads(line) | ||
| 10 | + if m.get("reason") == "build-script-executed" and "/crates/client" in m["package_id"]: | ||
| 11 | + print(m["out_dir"])') | ||
| 12 | +DIR="${PROFILE/dev/debug}" | ||
| 13 | +APP="target/$DIR/Yumush.app" | ||
| 14 | +rm -rf "$APP" | ||
| 15 | +mkdir -p "$APP/Contents/MacOS" "$APP/Contents/Resources" | ||
| 16 | +cp "target/$DIR/client" "$APP/Contents/MacOS/yumush" | ||
| 17 | +cp "$OUT/yumush.icns" "$APP/Contents/Resources/yumush.icns" | ||
| 18 | +VERSION=$(cargo pkgid -p client | sed 's/.*[#@]//') | ||
| 19 | +cat > "$APP/Contents/Info.plist" <<PLIST | ||
| 20 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 21 | +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
| 22 | +<plist version="1.0"> | ||
| 23 | +<dict> | ||
| 24 | + <key>CFBundleName</key><string>Yumush</string> | ||
| 25 | + <key>CFBundleDisplayName</key><string>yumuş</string> | ||
| 26 | + <key>CFBundleIdentifier</key><string>com.yumush.client</string> | ||
| 27 | + <key>CFBundleExecutable</key><string>yumush</string> | ||
| 28 | + <key>CFBundleIconFile</key><string>yumush</string> | ||
| 29 | + <key>CFBundlePackageType</key><string>APPL</string> | ||
| 30 | + <key>CFBundleShortVersionString</key><string>$VERSION</string> | ||
| 31 | + <key>CFBundleVersion</key><string>$VERSION</string> | ||
| 32 | + <key>NSHighResolutionCapable</key><true/> | ||
| 33 | + <key>NSMicrophoneUsageDescription</key><string>Voice calls</string> | ||
| 34 | + <key>NSCameraUsageDescription</key><string>Video calls</string> | ||
| 35 | +</dict> | ||
| 36 | +</plist> | ||
| 37 | +PLIST | ||
| 38 | +echo "$APP" | ||