Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ rfd = "0.17"
pollster = "0.4"
anyhow = "1.0"

[build-dependencies]
winresource = "0.1"

[dev-dependencies]
tempfile = "3"

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

---
Expand Down
Binary file added assets/icon/icon-256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icon/icon-macos-1024.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icon/icon.ico
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions assets/icon/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 36 additions & 7 deletions assets/linux/commit-rewriter.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
14 changes: 14 additions & 0 deletions scripts/build-macos-app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -118,6 +130,8 @@ cat > "${CONTENTS_DIR}/Info.plist" << EOF
<string>en</string>
<key>CFBundleExecutable</key>
<string>${APP_NAME}</string>
<key>CFBundleIconFile</key>
<string>AppIcon</string>
<key>CFBundleIdentifier</key>
<string>${BUNDLE_ID}</string>
<key>CFBundleInfoDictionaryVersion</key>
Expand Down
46 changes: 46 additions & 0 deletions scripts/generate-icons.sh
Original file line number Diff line number Diff line change
@@ -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("<HHH", 0, 1, len(images))
entries, offset = b"", 6 + 16 * len(images)
for data in images:
width, height = struct.unpack(">II", data[16:24])
entries += struct.pack("<BBBBHHII", width % 256, height % 256, 0, 0, 1, 32, len(data), offset)
offset += len(data)
with open(out, "wb") as f:
f.write(header + entries + b"".join(images))
PY

# macOS keeps the margin; the .icns is built from this file on macOS
rsvg-convert -w 1024 -h 1024 "$SRC" -o "$OUT/icon-macos-1024.png"

echo "Icons generated in $OUT"
6 changes: 6 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ fn main() -> 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()
};
Expand Down
Loading