diff --git a/Cargo.lock b/Cargo.lock index 6128cc8..55e0a24 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -665,6 +665,7 @@ dependencies = [ "pollster 0.4.0", "rfd", "tempfile", + "winresource", ] [[package]] @@ -2832,6 +2833,15 @@ dependencies = [ "syn 3.0.7", ] +[[package]] +name = "serde_spanned" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e7523beb55eece201a2356bee0bbca0d1ab466c14c07703b2e0ee6d42cb0c2c" +dependencies = [ + "serde_core", +] + [[package]] name = "shlex" version = "2.0.1" @@ -3159,6 +3169,21 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "toml" +version = "1.1.8+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20489e00e4d8741d6be680764cc12e270655e375a20d1011e844a9c3379e678d" +dependencies = [ + "indexmap", + "serde_core", + "serde_spanned", + "toml_datetime", + "toml_parser", + "toml_writer", + "winnow", +] + [[package]] name = "toml_datetime" version = "1.1.2+spec-1.1.0" @@ -3189,6 +3214,12 @@ dependencies = [ "winnow", ] +[[package]] +name = "toml_writer" +version = "1.1.3+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06bdbd8cfc056b8d2e2e85f29b56a3bdbecb527cef81eb39e3e7b98af4652770" + [[package]] name = "tracing" version = "0.1.44" @@ -4119,6 +4150,16 @@ dependencies = [ "memchr", ] +[[package]] +name = "winresource" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0986a8b1d586b7d3e4fe3d9ea39fb451ae22869dcea4aa109d287a374d866087" +dependencies = [ + "toml", + "version_check", +] + [[package]] name = "wit-bindgen" version = "0.57.1" diff --git a/Cargo.toml b/Cargo.toml index f952991..ade2776 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,9 @@ rfd = "0.17" pollster = "0.4" anyhow = "1.0" +[build-dependencies] +winresource = "0.1" + [dev-dependencies] tempfile = "3" diff --git a/README.md b/README.md index af0119d..bbbc9e2 100644 --- a/README.md +++ b/README.md @@ -127,6 +127,8 @@ sudo apt install build-essential pkg-config sudo pacman -S base-devel pkgconf ``` +App icons are generated from `assets/icon/icon.svg` with `./scripts/generate-icons.sh` (needs librsvg and ImageMagick); the results are committed, so regular builds don't need these tools. + The folder picker uses [xdg-desktop-portal](https://flatpak.github.io/xdg-desktop-portal/), which is available on most desktop environments. --- diff --git a/assets/icon/icon-256.png b/assets/icon/icon-256.png new file mode 100644 index 0000000..14bceff Binary files /dev/null and b/assets/icon/icon-256.png differ diff --git a/assets/icon/icon-macos-1024.png b/assets/icon/icon-macos-1024.png new file mode 100644 index 0000000..1aa8c27 Binary files /dev/null and b/assets/icon/icon-macos-1024.png differ diff --git a/assets/icon/icon.ico b/assets/icon/icon.ico new file mode 100644 index 0000000..fa9819f Binary files /dev/null and b/assets/icon/icon.ico differ diff --git a/assets/icon/icon.svg b/assets/icon/icon.svg new file mode 100644 index 0000000..9c7b887 --- /dev/null +++ b/assets/icon/icon.svg @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/assets/linux/commit-rewriter.svg b/assets/linux/commit-rewriter.svg index ec78f73..3799da5 100644 --- a/assets/linux/commit-rewriter.svg +++ b/assets/linux/commit-rewriter.svg @@ -1,8 +1,37 @@ - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..a081ae7 --- /dev/null +++ b/build.rs @@ -0,0 +1,14 @@ +fn main() { + println!("cargo:rerun-if-changed=assets/icon/icon.ico"); + + // Embed the icon and version info into the Windows executable + if std::env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("windows") { + let mut res = winresource::WindowsResource::new(); + res.set_icon("assets/icon/icon.ico") + .set("ProductName", "Git Commit Rewriter") + .set("FileDescription", "Git Commit Rewriter"); + if let Err(e) = res.compile() { + panic!("failed to embed Windows resources: {}", e); + } + } +} diff --git a/scripts/build-macos-app.sh b/scripts/build-macos-app.sh index 8be12e9..66743e5 100755 --- a/scripts/build-macos-app.sh +++ b/scripts/build-macos-app.sh @@ -107,6 +107,18 @@ fi cp "$BINARY_PATH" "$MACOS_DIR/$APP_NAME" chmod +x "$MACOS_DIR/$APP_NAME" +# Create app icon from the pre-rendered 1024px PNG +info "Creating app icon..." +ICONSET_DIR="$(mktemp -d)/AppIcon.iconset" +mkdir -p "$ICONSET_DIR" +ICON_SRC="assets/icon/icon-macos-1024.png" +for size in 16 32 128 256 512; do + sips -z $size $size "$ICON_SRC" --out "$ICONSET_DIR/icon_${size}x${size}.png" > /dev/null + sips -z $((size * 2)) $((size * 2)) "$ICON_SRC" --out "$ICONSET_DIR/icon_${size}x${size}@2x.png" > /dev/null +done +iconutil -c icns "$ICONSET_DIR" -o "$RESOURCES_DIR/AppIcon.icns" +rm -rf "$(dirname "$ICONSET_DIR")" + # Create Info.plist info "Creating Info.plist..." cat > "${CONTENTS_DIR}/Info.plist" << EOF @@ -118,6 +130,8 @@ cat > "${CONTENTS_DIR}/Info.plist" << EOF en CFBundleExecutable ${APP_NAME} + CFBundleIconFile + AppIcon CFBundleIdentifier ${BUNDLE_ID} CFBundleInfoDictionaryVersion diff --git a/scripts/generate-icons.sh b/scripts/generate-icons.sh new file mode 100755 index 0000000..2674a11 --- /dev/null +++ b/scripts/generate-icons.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +# Regenerates all app icons from assets/icon/icon.svg +# Usage: ./scripts/generate-icons.sh +# Requires: rsvg-convert (librsvg) and magick (ImageMagick) + +set -e + +cd "$(dirname "$0")/.." + +SRC="assets/icon/icon.svg" +OUT="assets/icon" +TMP=$(mktemp -d) +trap 'rm -rf "$TMP"' EXIT + +# Full-bleed variant without the macOS safe-area margin, for small sizes +sed 's/viewBox="0 0 1024 1024"/viewBox="100 100 824 824"/' "$SRC" > "$TMP/full.svg" + +# Window icon and Linux desktop icon +rsvg-convert -w 256 -h 256 "$TMP/full.svg" -o "$OUT/icon-256.png" +cp "$TMP/full.svg" assets/linux/commit-rewriter.svg + +# Windows .ico with the usual sizes +for size in 16 24 32 48 64 128 256; do + rsvg-convert -w $size -h $size "$TMP/full.svg" -o "$TMP/ico-$size.png" +done +# ICO with PNG-compressed entries (supported since Windows Vista), much +# smaller than the uncompressed bitmaps ImageMagick writes +python3 - "$OUT/icon.ico" "$TMP"/ico-{16,24,32,48,64,128,256}.png <<'PY' +import struct, sys +out, pngs = sys.argv[1], sys.argv[2:] +images = [open(p, "rb").read() for p in pngs] +header = struct.pack("II", data[16:24]) + entries += struct.pack(" Result<(), eframe::Error> { viewport: egui::ViewportBuilder::default() .with_inner_size([1000.0, 760.0]) .with_min_inner_size([640.0, 520.0]) + // matches commit-rewriter.desktop, so Wayland shows its icon + .with_app_id("commit-rewriter") + .with_icon( + eframe::icon_data::from_png_bytes(include_bytes!("../assets/icon/icon-256.png")) + .expect("bundled icon is a valid PNG"), + ) .with_title("Git Commit Rewriter"), ..Default::default() };