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
5 changes: 4 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ jobs:
run: |
mkdir "$PACKAGE"
cp "target/$TARGET/release/drwr" LICENSE.md README.md "$PACKAGE"
cp assets/drwr.desktop assets/app_icon/drwr.png "$PACKAGE"
tar -czf "$PACKAGE.tar.gz" "$PACKAGE"

- name: Package for macOS
Expand All @@ -78,10 +79,11 @@ jobs:
contents=drwr.app/Contents
mkdir -p "$contents/MacOS" "$contents/Resources"
cp "target/$TARGET/release/drwr" "$contents/MacOS"
cp LICENSE.md "$contents/Resources"
cp LICENSE.md assets/app_icon/drwr.icns "$contents/Resources"
version=$(cargo metadata --no-deps --format-version 1 | jq -er '.packages[] | select(.name == "drwr") | .version')
/usr/libexec/PlistBuddy \
-c "Add :CFBundleExecutable string drwr" \
-c "Add :CFBundleIconFile string drwr" \
-c "Add :CFBundleIdentifier string io.github.pvik.drwr" \
-c "Add :CFBundleName string drwr" \
-c "Add :CFBundlePackageType string APPL" \
Expand All @@ -93,6 +95,7 @@ jobs:
codesign --force --sign - drwr.app
ditto -c -k --keepParent drwr.app "$PACKAGE.zip"

# build.rs gives drwr.exe its icon.
- name: Package for Windows
if: runner.os == 'Windows'
run: |
Expand Down
3 changes: 2 additions & 1 deletion Cargo.lock

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

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ default-members = [".", "crates/graphml"]

[package]
name = "drwr"
version = "0.1.1"
version = "0.2.0"
edition = "2024"
homepage = "https://pvik.github.io/drwr/"

Expand All @@ -31,6 +31,11 @@ serde = { version = "1.0.229", features = ["derive"] }
skrifa = { version = "0.44.0", default-features = false, features = ["std", "autohint_shaping"] }
toml = "1.2.1"

[dev-dependencies]
# Compresses the app icon files three times better than tiny-skia does.
# tiny-skia uses it, so it builds nothing new.
png = "0.17.16"

[target.'cfg(target_os = "macos")'.dependencies]
# Has quitting ask about unsaved changes. eframe uses them, so they build
# nothing new.
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ A simple, fast and lightweight GraphML based diagraming tool
- Good keyboard support
- Export to PNG and SVG
- Can read in yEd GraphML files

#### Installing on Mac

Unzip it and move drwr.app to Applications. drwr isn't notarized by Apple yet, so macOS blocks its first launch: allow it under System Settings › Privacy & Security › Open Anyway, or run this in Terminal:
```
xattr -dr com.apple.quarantine /Applications/drwr.app
```

Binary file added assets/app_icon/drwr.icns
Binary file not shown.
Binary file added assets/app_icon/drwr.ico
Binary file not shown.
Binary file added assets/app_icon/drwr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions assets/app_icon/drwr.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions assets/drwr.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Desktop Entry]
Type=Application
Name=drwr
GenericName=Diagram Editor
Comment=Draw diagrams and edit yEd GraphML files
Keywords=diagram;graph;graphml;yed;flowchart;
Exec=drwr
Icon=drwr
Terminal=false
Categories=Graphics;2DGraphics;VectorGraphics;
StartupWMClass=drwr
60 changes: 59 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
//! Embeds the short commit hash (or `unknown`) for `drwr -version` and the
//! About dialog.
//! About dialog, and the app icon in Windows builds.

use std::path::PathBuf;
use std::process::Command;
use std::{env, fs};

/// The icon Explorer and the taskbar show for drwr.exe.
const WINDOWS_ICON: &str = "assets/app_icon/drwr.ico";

fn main() {
let commit = git(&["rev-parse", "--short", "HEAD"]).unwrap_or_else(|| "unknown".to_owned());
Expand All @@ -13,6 +18,59 @@ fn main() {
if let Some(branch_ref) = git(&["symbolic-ref", "--quiet", "HEAD"]) {
rerun_if_git_path_changes(&branch_ref);
}

// -gnu builds go without the icon, as GNU ld needs resources converted
// by windres first.
let target = |key| env::var(key).unwrap_or_default();
if target("CARGO_CFG_TARGET_OS") == "windows" && target("CARGO_CFG_TARGET_ENV") == "msvc" {
println!("cargo::rerun-if-changed={WINDOWS_ICON}");
let ico = fs::read(WINDOWS_ICON).expect("couldn't read the Windows icon");
let res = PathBuf::from(env::var_os("OUT_DIR").unwrap()).join("drwr.res");
fs::write(&res, icon_resources(&ico)).expect("couldn't write drwr.res");
println!("cargo::rustc-link-arg-bins={}", res.display());
}
}

/// The resource file rc.exe compiles `1 ICON "drwr.ico"` to, for the icon
/// file `ico`: each image as a resource, then a directory of them. MSVC's
/// linker takes it as it is, so building needs no resource compiler.
fn icon_resources(ico: &[u8]) -> Vec<u8> {
const RT_ICON: u16 = 3;
const RT_GROUP_ICON: u16 = 14;
const EN_US: u16 = 0x0409;
assert_eq!(ico[..4], [0, 0, 1, 0], "{WINDOWS_ICON} isn't an icon");
// Every resource file starts with an empty resource.
let mut res = resource(0, 0, 0, 0, &[]);
let mut group = ico[..6].to_vec();
for id in 1..=u16::from_le_bytes([ico[4], ico[5]]) {
let entry = &ico[6 + 16 * usize::from(id - 1)..][..16];
let len = u32::from_le_bytes(entry[8..12].try_into().unwrap()) as usize;
let offset = u32::from_le_bytes(entry[12..].try_into().unwrap()) as usize;
res.extend(resource(RT_ICON, id, 0x1010, EN_US, &ico[offset..][..len]));
// The image's entry, with its resource id in place of its offset.
group.extend(&entry[..12]);
group.extend(id.to_le_bytes());
}
res.extend(resource(RT_GROUP_ICON, 1, 0x1030, EN_US, &group));
res
}

/// A resource with a numbered type and name. `flags` are the 16-bit Windows
/// memory flags rc.exe still writes.
fn resource(kind: u16, id: u16, flags: u16, language: u16, data: &[u8]) -> Vec<u8> {
let mut res = Vec::new();
// The data's length, then the header's.
res.extend((data.len() as u32).to_le_bytes());
res.extend(32u32.to_le_bytes());
// 0xffff marks the type and name as numbers. The zeros are the data
// version, the version and the characteristics.
for word in [0xffff, kind, 0xffff, id, 0, 0, flags, language, 0, 0, 0, 0] {
res.extend(word.to_le_bytes());
}
res.extend(data);
// The next resource starts at a multiple of 4 bytes.
res.resize(res.len().next_multiple_of(4), 0);
res
}

/// Uses `--git-path` because `.git` is a file in worktrees and submodules.
Expand Down
21 changes: 21 additions & 0 deletions src/app_icon/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//! drwr's icon, drawn in `assets/app_icon/drwr.svg`. The window and the
//! release packages use the icon files beside it, which the tests draw from
//! the SVG.

use egui::IconData;

/// The icon, 256 pixels across. Decoding it is over ten times faster than
/// drawing the SVG.
const PNG: &[u8] = include_bytes!("../../assets/app_icon/drwr.png");

/// The window's icon. On macOS it's empty, so the Dock shows the app bundle's
/// icon instead of eframe's default one.
pub fn window_icon() -> IconData {
if cfg!(target_os = "macos") {
return IconData::default();
}
eframe::icon_data::from_png_bytes(PNG).expect("drwr.png is a PNG")
}

#[cfg(test)]
mod tests;
Loading
Loading