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
28 changes: 28 additions & 0 deletions .github/actions/package/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,34 @@ runs:
check AppImage "$(ls "$RUNNER_TEMP/squashfs-root/usr/bin")" devnotes
fi

# The icon the menus, the dock and the file managers show, read from the package and not from
# the window. Windows reads it from devnotes.exe, which a test of `crates/app` holds.
- name: Each package carries the icon
if: runner.os != 'Windows'
shell: bash
run: |
packages="$GITHUB_WORKSPACE/target/release/packages"
need() {
if ! echo "$2" | grep -qxF -- "$3"; then
echo "::error::$1 has no $3"
exit 1
fi
echo "$1: $3"
}
if [ "$RUNNER_OS" = macOS ]; then
app="$packages/DevNotes.app/Contents"
icns=$(plutil -extract CFBundleIconFile raw "$app/Info.plist")
need app "$(ls "$app/Resources")" "$icns"
need archive "$(tar -tzf "$(ls "$packages"/*.app.tar.gz)" | xargs -n1 basename)" "$icns"
else
icon=usr/share/icons/hicolor/512x512/apps/devnotes.png
deb=$(ls "$packages"/*.deb)
need deb "$(dpkg-deb -c "$deb" | awk '{ print $6 }' | sed 's|^\./||')" "$icon"
need deb "$(dpkg-deb --fsys-tarfile "$deb" | tar -xO --wildcards '*usr/share/applications/devnotes.desktop')" Icon=devnotes
need rpm "$(rpm -qlp "$(ls "$packages"/*.rpm)")" "/$icon"
need AppImage "$(ls -A "$RUNNER_TEMP/squashfs-root")" .DirIcon
fi

# The packages, their signatures, and the standalone executable, renamed so that the two
# operating systems do not overlap in a release.
- name: Gather
Expand Down
11 changes: 11 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ unicode-segmentation = "1.13.3"
url = "2.5.8"
uuid = { version = "1.27.0", features = ["v4"] }
winit = { version = "0.30.13", default-features = false, features = ["x11"] }
winresource = { version = "0.1.34", default-features = false }
winreg = "0.56.0"
yaml-rust2 = "0.13.0"
zbus = "5.19.0"
Expand Down
6 changes: 6 additions & 0 deletions crates/app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ summary = "A developer's notes and snippets manager for the desktop"
assets = [
{ source = "target/release/devnotes", dest = "/usr/bin/devnotes", mode = "755" },
{ source = "packaging/devnotes.desktop", dest = "/usr/share/applications/devnotes.desktop", mode = "644" },
{ source = "icons/32x32.png", dest = "/usr/share/icons/hicolor/32x32/apps/devnotes.png", mode = "644" },
{ source = "icons/128x128.png", dest = "/usr/share/icons/hicolor/128x128/apps/devnotes.png", mode = "644" },
{ source = "icons/icon.png", dest = "/usr/share/icons/hicolor/512x512/apps/devnotes.png", mode = "644" },
]

[package.metadata.generate-rpm.requires]
Expand Down Expand Up @@ -82,6 +84,10 @@ puffin_http = { workspace = true, optional = true }
# The one eframe uses, for its X11 switch (D15) and for macOS's menu bar.
winit.workspace = true

[build-dependencies]
toml.workspace = true
winresource.workspace = true

[dev-dependencies]
# `examples/tours.rs`, which assembles the README's tours, and their test.
image.workspace = true
Expand Down
39 changes: 39 additions & 0 deletions crates/app/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//! The Windows executable carries its icon and its version: the shell, the installer's shortcuts
//! and the taskbar read them from the file, whatever the window sets.

use std::{env, fs, path::Path};

fn main() {
println!("cargo:rerun-if-changed=Cargo.toml");
println!("cargo:rerun-if-changed=icons/icon.ico");
// The script runs on the host: the target says what is being built.
if env::var("CARGO_CFG_TARGET_OS").as_deref() != Ok("windows") {
return;
}

let manifest_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR is set by cargo");
let manifest_dir = Path::new(&manifest_dir);
let name = product_name(manifest_dir);
let icon = manifest_dir.join("icons/icon.ico");
winresource::WindowsResource::new()
.set_icon(icon.to_str().expect("the repository is at a path of text"))
.set("ProductName", &name)
.set("FileDescription", &name)
.compile()
.expect("the Windows SDK's resource compiler embeds the icon");
}

/// The name the packages give the application, `[package.metadata.packager] product-name`; the
/// version is the workspace's, which `winresource` reads from Cargo itself.
fn product_name(manifest_dir: &Path) -> String {
let text = fs::read_to_string(manifest_dir.join("Cargo.toml")).expect("Cargo.toml is readable");
let manifest: toml::Table = toml::from_str(&text).expect("Cargo.toml is valid TOML");
manifest
.get("package")
.and_then(|package| package.get("metadata"))
.and_then(|metadata| metadata.get("packager"))
.and_then(|packager| packager.get("product-name"))
.and_then(toml::Value::as_str)
.expect("[package.metadata.packager] product-name is a string")
.to_owned()
}
48 changes: 48 additions & 0 deletions crates/app/tests/windows_resources.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//! What Windows reads from the executable itself: the shell, the installer's shortcuts and the
//! taskbar take the icon from the file, not from the window.
#![cfg(windows)]

const RT_GROUP_ICON: u32 = 14;
const RT_VERSION: u32 = 16;

#[test]
fn the_executable_carries_its_icon_and_its_version() {
let file = std::fs::read(env!("CARGO_BIN_EXE_devnotes")).unwrap();
let types = resource_types(&file);

assert!(types.contains(&RT_GROUP_ICON), "no icon: {types:?}");
assert!(types.contains(&RT_VERSION), "no version: {types:?}");
}

/// The types listed by the file's root resource directory, read from its PE headers; none when it
/// has no resource table.
fn resource_types(file: &[u8]) -> Vec<u32> {
let u16_at = |at: usize| usize::from(u16::from_le_bytes([file[at], file[at + 1]]));
let u32_at = |at: usize| u32::from_le_bytes(file[at..at + 4].try_into().unwrap());

let pe = u32_at(0x3C) as usize;
let optional = pe + 24;
let directories = optional + if u16_at(optional) == 0x20B { 112 } else { 96 };
let table = u32_at(directories + 2 * 8);
if table == 0 {
return Vec::new();
}

let headers = optional + u16_at(pe + 20);
let root = (0..u16_at(pe + 6))
.map(|index| headers + 40 * index)
.find_map(|section| {
let start = u32_at(section + 12);
let length = u32_at(section + 8).max(u32_at(section + 16));
(start..start + length)
.contains(&table)
.then(|| (table - start + u32_at(section + 20)) as usize)
})
.expect("the resource table lies in a section");

let named = u16_at(root + 12);
let numbered = u16_at(root + 14);
(named..named + numbered)
.map(|entry| u32_at(root + 16 + 8 * entry))
.collect()
}
6 changes: 4 additions & 2 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -6255,8 +6255,10 @@ three invariants `changelog::tests::the_shipped_file_parses_into_something_to_sh
**The packages** are built by `cargo build -p app --release`, then `.github/actions/package`:
`cargo packager` (NSIS per user on Windows; AppImage and deb on Linux; a `.dmg` and the updater's
archive on macOS) and `cargo generate-rpm`,
each signed with the minisign key, each checked to hold the application alone (→
`docs/releasing.md`, "What gets published").
each signed with the minisign key, each checked to hold the application alone and to carry the
icon (→ `docs/releasing.md`, "What gets published"). On Windows the icon and the version are
resources of `devnotes.exe`, embedded by `crates/app/build.rs` (`winresource`): the shell, the
installer's shortcuts and the taskbar read the file, whatever the window sets.
`packages.yml` runs the same action on a pull request that touches packaging, with a key made
for the run, then installs 1.0.0 on a clean runner, refuses a 1.0.1 altered by one byte and
installs the whole one through the application's own updater client
Expand Down
5 changes: 4 additions & 1 deletion docs/releasing.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,10 @@ more; the Linux ones depend on GTK (the tray alone), xkbcommon, Vulkan and the i
library.

Each package is checked to hold the application alone (one binary; the identity tool's lists are
compiled into it) before anything is uploaded.
compiled into it) before anything is uploaded, and to carry the icon: the hicolor icons and the
`.desktop` entry on Linux, the `.icns` of the bundle and of the updater's archive on macOS. On
Windows the icon is a resource of `devnotes.exe` itself, held by
`crates/app/tests/windows_resources.rs`.

**Signatures.** `cargo-packager` signs every package it writes with the minisign key, and the
`.rpm` is signed by `cargo packager signer sign`. The key and its password are the release
Expand Down
Loading