Add generated app icons and cross-platform desktop launchers

This commit is contained in:
Dandaedre 2026-11-14 14:14:59 +01:00
parent 2aa4c72a00
commit e6809eb021
63 changed files with 458 additions and 23 deletions

2
Cargo.lock generated
View File

@ -213,6 +213,7 @@ dependencies = [
"tempfile",
"unicode-normalization",
"windows-sys 0.61.2",
"winresource",
]
[[package]]
@ -2557,6 +2558,7 @@ dependencies = [
"svgtypes",
"tempfile",
"tungstenite",
"winresource",
]
[[package]]

View File

@ -51,7 +51,7 @@ opening reports, and reading video timings.
- [Rundown converter](docs/rundown-converter.md) · [Sample findings](docs/rundown-corpus.md)
- [Midra layout helper](docs/midra-layout.md) · [Plan and visual proposals](docs/midra-layout-plan.md) · [File formats](docs/interfaces/midra-layout.md)
- [Development](docs/development.md) · [CI and coverage](docs/ci.md)
- [Cross builds and portable releases](docs/releases.md)
- [Cross builds and portable releases](docs/releases.md) · [App icons and desktop launchers](docs/releases.md#application-artwork)
- [MPC-HC Companion module development](companion-modules/media-player-classic/README.md)
- [Future ideas](Ideas.md)
- [Future program task list](docs/program-task-list.md)

View File

@ -1,5 +1,7 @@
# MPC-HC Companion module — local development
<img src="companion/assets/app-icon.png" width="96" alt="Media Player Classic module icon">
A local development port of the original Media Player Classic module for
**Companion 5.1.0**, using Companion module API 2 and Node.js 22. It preserves
all 138 original numeric command IDs, adds live player feedback, and provides

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 364 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

View File

@ -28,3 +28,6 @@ windows-sys = { version = "0.61", features = ["Win32_Storage_FileSystem"] }
[target.'cfg(target_os = "freebsd")'.dependencies]
libc = "0.2.191"
[build-dependencies]
winresource = "0.1.17"

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 364 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

View File

@ -0,0 +1,9 @@
fn main() {
println!("cargo:rerun-if-changed=assets/app-icon.ico");
if std::env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("windows") {
winresource::WindowsResource::new()
.set_icon("assets/app-icon.ico")
.compile()
.expect("Could not embed the Windows application icon");
}
}

View File

@ -138,6 +138,11 @@ pub fn launch() -> eframe::Result {
"ASCII names",
eframe::NativeOptions {
viewport: egui::ViewportBuilder::default()
.with_app_id("ascii-names")
.with_icon(
eframe::icon_data::from_png_bytes(include_bytes!("../assets/app-icon.png"))
.expect("embedded application icon must be a valid PNG"),
)
.with_inner_size([760.0, 480.0])
.with_drag_and_drop(true),
..Default::default()

View File

@ -19,3 +19,6 @@ tempfile = "3"
directories = "6"
reqwest = { version = "0.12.28", default-features = false, features = ["blocking"] }
tungstenite = { version = "0.28", default-features = false, features = ["handshake"] }
[build-dependencies]
winresource = "0.1.17"

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 364 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

View File

@ -0,0 +1,9 @@
fn main() {
println!("cargo:rerun-if-changed=assets/app-icon.ico");
if std::env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("windows") {
winresource::WindowsResource::new()
.set_icon("assets/app-icon.ico")
.compile()
.expect("Could not embed the Windows application icon");
}
}

View File

@ -16,6 +16,11 @@ fn main() -> eframe::Result {
"Midra Layout",
eframe::NativeOptions {
viewport: egui::ViewportBuilder::default()
.with_app_id("midra-layout")
.with_icon(
eframe::icon_data::from_png_bytes(include_bytes!("../assets/app-icon.png"))
.expect("embedded application icon must be a valid PNG"),
)
.with_inner_size([1440.0, 940.0])
.with_min_inner_size([1000.0, 720.0]),
..Default::default()

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 364 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

View File

@ -1,10 +1,8 @@
fn main() {
println!("cargo:rerun-if-changed=assets/rust-report.ico");
if std::env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("windows")
&& std::env::var_os("CARGO_FEATURE_DESKTOP").is_some()
{
println!("cargo:rerun-if-changed=assets/app-icon.ico");
if std::env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("windows") {
winresource::WindowsResource::new()
.set_icon("assets/rust-report.ico")
.set_icon("assets/app-icon.ico")
.compile()
.expect("Could not embed the Windows application icon");
}

View File

@ -639,9 +639,10 @@ fn configure_style(ctx: &egui::Context) {
}
pub fn launch() -> anyhow::Result<()> {
let icon = eframe::icon_data::from_png_bytes(include_bytes!("../assets/rust-report-icon.png"))?;
let icon = eframe::icon_data::from_png_bytes(include_bytes!("../assets/app-icon.png"))?;
let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default()
.with_app_id("pptx-reporter")
.with_icon(icon)
.with_inner_size([760.0, 560.0])
.with_min_inner_size([560.0, 420.0])

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 364 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

View File

@ -1,10 +1,8 @@
fn main() {
println!("cargo:rerun-if-changed=assets/rundown-converter.ico");
if std::env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("windows")
&& std::env::var_os("CARGO_FEATURE_DESKTOP").is_some()
{
println!("cargo:rerun-if-changed=assets/app-icon.ico");
if std::env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("windows") {
winresource::WindowsResource::new()
.set_icon("assets/rundown-converter.ico")
.set_icon("assets/app-icon.ico")
.compile()
.expect("Could not embed the Windows application icon");
}

View File

@ -1510,13 +1510,13 @@ fn configure_style(ctx: &egui::Context) {
ctx.set_style(style);
}
pub fn launch() -> eframe::Result {
let icon =
eframe::icon_data::from_png_bytes(include_bytes!("../assets/rundown-converter-icon.png"))
.expect("embedded rundown converter icon must be a valid PNG");
let icon = eframe::icon_data::from_png_bytes(include_bytes!("../assets/app-icon.png"))
.expect("embedded rundown converter icon must be a valid PNG");
eframe::run_native(
"Rundown converter",
eframe::NativeOptions {
viewport: egui::ViewportBuilder::default()
.with_app_id("rundown-converter")
.with_icon(icon)
.with_inner_size([860.0, 620.0])
.with_min_inner_size([560.0, 400.0]),

View File

@ -1,5 +1,7 @@
# ASCII names
<img src="../crates/ascii-names/assets/app-icon.png" width="96" alt="Application icon">
A small Rust application for cleaning filenames before using a folder on an
ASCII-only computer. Run it on your modern computer while the USB drive is plugged in.
It changes names in place; file contents are never opened or rewritten.

View File

@ -2,6 +2,10 @@
[All changelogs](../changelogs.md)
## Unreleased
- Add ImageGen application artwork in PNG, Windows ICO and macOS ICNS formats. Embed native icons and support Linux/BSD desktop entries and macOS app launchers; native Windows/macOS visual checks remain required.
## 2026-11-13
- `00a43e8`: Handle FreeBSD no-overwrite rename capabilities and safe-refusal CI expectations.

View File

@ -1,5 +1,7 @@
# Export presentations and PDF pages
<img src="../tools/assets/exporter/app-icon.png" width="96" alt="Application icon">
```sh
python3 tools/exporter.py presentation.pptx --output pdf,images
python3 tools/exporter.py document.pdf --output images

View File

@ -2,6 +2,10 @@
[All changelogs](../changelogs.md)
## Unreleased
- Add ImageGen application artwork in PNG, Windows ICO and macOS ICNS formats. Artwork is available for shortcuts and documentation; the tool remains hosted by its terminal or Companion.
## 2026-10-20
- `095e7c7`: Report selected export DPI and allow reusing it.

12
docs/icon-prompts.json Normal file
View File

@ -0,0 +1,12 @@
{
"generator": "Built-in image_gen",
"prompts": {
"ascii-names": "Use case: logo-brand. Asset type: professional desktop application icon for ascii-names in a coordinated suite of document and audiovisual tools. Subject: a refined folder containing a single clean capital A with a small check mark, representing filename cleanup. A single centered icon, square 1024x1024 canvas, rounded-square deep graphite tile with restrained luminous teal and cool silver pictogram. Premium contemporary desktop software visual identity, simple bold geometry, subtle depth and soft bevel, crisp silhouette legible at 32 pixels, front-facing orthographic view, balanced margins. Transparent background outside the tile, tile occupies 88% of canvas. No words, no labels, no watermark, no extra decorative objects.",
"midra-layout": "Use case: logo-brand. Asset type: professional desktop application icon for midra-layout in a coordinated suite of document and audiovisual tools. Subject: three precisely aligned overlapping display rectangles, representing professional video screen layer layout. A single centered icon, square 1024x1024 canvas, rounded-square deep graphite tile with restrained luminous teal and cool silver pictogram. Premium contemporary desktop software visual identity, simple bold geometry, subtle depth and soft bevel, crisp silhouette legible at 32 pixels, front-facing orthographic view, balanced margins. Transparent background outside the tile, tile occupies 88% of canvas. No words, no labels, no watermark, no extra decorative objects.",
"pptx-reporter": "Use case: logo-brand. Asset type: professional desktop application icon for pptx-reporter in a coordinated suite of document and audiovisual tools. Subject: a presentation slide with a play triangle and a small clock, representing video timing reports. A single centered icon, square 1024x1024 canvas, rounded-square deep graphite tile with restrained luminous teal and cool silver pictogram. Premium contemporary desktop software visual identity, simple bold geometry, subtle depth and soft bevel, crisp silhouette legible at 32 pixels, front-facing orthographic view, balanced margins. Transparent background outside the tile, tile occupies 88% of canvas. No words, no labels, no watermark, no extra decorative objects.",
"rundown-converter": "Use case: logo-brand. Asset type: professional desktop application icon for rundown-converter in a coordinated suite of document and audiovisual tools. Subject: a clean schedule sheet with three horizontal rows and a clock, representing show rundown conversion. A single centered icon, square 1024x1024 canvas, rounded-square deep graphite tile with restrained luminous teal and cool silver pictogram. Premium contemporary desktop software visual identity, simple bold geometry, subtle depth and soft bevel, crisp silhouette legible at 32 pixels, front-facing orthographic view, balanced margins. Transparent background outside the tile, tile occupies 88% of canvas. No words, no labels, no watermark, no extra decorative objects.",
"exporter": "Use case: logo-brand. Asset type: professional desktop application icon for exporter in a coordinated suite of document and audiovisual tools. Subject: two layered documents and a bold outward arrow, representing document export. A single centered icon, square 1024x1024 canvas, rounded-square deep graphite tile with restrained luminous teal and cool silver pictogram. Premium contemporary desktop software visual identity, simple bold geometry, subtle depth and soft bevel, crisp silhouette legible at 32 pixels, front-facing orthographic view, balanced margins. Transparent background outside the tile, tile occupies 88% of canvas. No words, no labels, no watermark, no extra decorative objects.",
"midra-probe": "Use case: logo-brand. Asset type: professional desktop application icon for midra-probe in a coordinated suite of document and audiovisual tools. Subject: a display rectangle with a magnifying glass and a small connection node, representing video processor diagnostics. A single centered icon, square 1024x1024 canvas, rounded-square deep graphite tile with restrained luminous teal and cool silver pictogram. Premium contemporary desktop software visual identity, simple bold geometry, subtle depth and soft bevel, crisp silhouette legible at 32 pixels, front-facing orthographic view, balanced margins. Transparent background outside the tile, tile occupies 88% of canvas. No words, no labels, no watermark, no extra decorative objects.",
"media-player-classic": "Use case: logo-brand. Asset type: professional desktop application icon for media-player-classic in a coordinated suite of document and audiovisual tools. Subject: a play triangle within a professional media transport panel, representing remote media player control. A single centered icon, square 1024x1024 canvas, rounded-square deep graphite tile with restrained luminous teal and cool silver pictogram. Premium contemporary desktop software visual identity, simple bold geometry, subtle depth and soft bevel, crisp silhouette legible at 32 pixels, front-facing orthographic view, balanced margins. Transparent background outside the tile, tile occupies 88% of canvas. No words, no labels, no watermark, no extra decorative objects."
}
}

View File

@ -0,0 +1,37 @@
# Desktop launcher output
`scripts/create-desktop-launcher.py` emits standard operating-system launcher
files for the four Rust desktop apps. It does not save application data or
import user projects. There is no custom schema version or round-trip importer;
compatibility follows Desktop Entry and macOS bundle conventions.
Linux/BSD output under `--output`:
- `applications/<tool>.desktop`: UTF-8 `[Desktop Entry]`, `Type=Application`,
human-readable `Name`, quoted absolute `Exec` with desktop field-code escaping,
absolute `Icon`, `Terminal=false`, `Categories=AudioVideo;Utility;`, and
`StartupWMClass=<tool>`. The filename matches the egui Wayland app ID.
- `icons/hicolor/256x256/apps/<tool>.png`: 256 × 256 RGBA application artwork.
macOS output is `<display name>.app/Contents/`:
- `Info.plist`: XML plist, `CFBundleName` and `CFBundleDisplayName` contain the
display name; `CFBundleIdentifier=com.beffroi.<tool>`;
`CFBundlePackageType=APPL`; `CFBundleExecutable=<tool>`;
`CFBundleIconFile=app-icon.icns`; `CFBundleVersion=1` identifies the launcher;
`NSHighResolutionCapable=true`.
- `MacOS/<tool>`: copied executable with mode 0755.
- `MacOS/ffprobe`: copied adjacent FFprobe when present for the reporter, requiring
a sibling `LICENSES` directory. Without it, the reporter uses PATH discovery.
- `Resources/LICENSES`: copied adjacent notices, when present. Symlinks in the
notices tree are refused.
- `Resources/app-icon.icns`: PNG-backed `ic07`, `ic08`, `ic09`, `ic10` entries,
at 128, 256, 512 and 1024 pixels respectively.
The binary must resolve to an existing executable regular file. Existing
launcher/icon destinations are refused, including symlinks. Linux/BSD paths are absolute and require the original installation to stay in
place. macOS copies are independent of their source location; recreate the bundle
to update its executables. Fonts stay embedded in the Rust binaries. The helper does not bypass macOS
Gatekeeper, sign bundles, register file associations, or make a binary for
another CPU/OS runnable. No timing values, numeric precision or user-data
migration applies to this format.

View File

@ -2,6 +2,10 @@
[All changelogs](../changelogs.md)
## Unreleased
- Add ImageGen application artwork in PNG, Windows ICO and macOS ICNS formats. Artwork is available for shortcuts and documentation; the tool remains hosted by its terminal or Companion.
## 2026-11-12
- `bb045ec`: Raise Load navigation symbols and enlarge labels.

View File

@ -1,5 +1,7 @@
# Midra Layout
<img src="../crates/midra-layout/assets/app-icon.png" width="96" alt="Application icon">
A native Rust/egui workspace for positioning rectangular layers, with offline editing
and an explicit Eikos 4K device link.
Select layers, paste draw.io or import SVG geometry, move them visually or enter exact corner

View File

@ -4,6 +4,8 @@
## Unreleased
- Add ImageGen application artwork in PNG, Windows ICO and macOS ICNS formats. Embed native icons and support Linux/BSD desktop entries and macOS app launchers; native Windows/macOS visual checks remain required. Include artwork for the Python device probe.
- Fix the crop-alignment regression test’s Clippy range-loop warning so CI passes with warnings denied; retain both offset assertions.
- Rename the positioning toggle to “Use a different measure point”.

View File

@ -2,6 +2,10 @@
[All changelogs](../changelogs.md)
## Unreleased
- Add ImageGen application artwork in PNG, Windows ICO and macOS ICNS formats. Embed native icons and support Linux/BSD desktop entries and macOS app launchers; native Windows/macOS visual checks remain required.
## 2026-11-03
- `b1ddf39`: Compact GUI with tabs and a fixed action bar.

View File

@ -173,16 +173,59 @@ all platforms.
## Application artwork
Artwork and fonts live in `crates/pptx-reporter/assets/`. Builds embed the PNG
window icon and the ICO Windows resource without image conversion tools.
To regenerate derivatives with ImageMagick from that directory:
All four Rust apps embed their own PNG window icon and Windows ICO resource,
including CLI-only Windows builds. Linux/FreeBSD X11 uses the window icon;
Wayland desktops match each app ID to its desktop entry. macOS uses the ICNS
resource in an app bundle. A bare Unix executable has no Finder/application-menu icon.
Seven coordinated icons were generated with the built-in ImageGen tool. The
[exact prompts](icon-prompts.json) are retained. Each Rust crate keeps its
`app-icon-source.png`, `app-icon.png`, `app-icon.ico` and `app-icon.icns` in
`assets/`. Python artwork lives in `tools/assets/exporter/` and
`tools/assets/midra-probe/`; Companion artwork lives in
`companion-modules/media-player-classic/companion/assets/`. Earlier reporter and
converter artwork remains available under its original filenames.
Builds consume committed derivatives and need no image tools. To regenerate the
256px PNG, seven-size ICO (16–256px), and ICNS (128–1024px), install ImageMagick 7
and run `python3 scripts/build-icons.py` from the repository root.
### Desktop launchers
After building or extracting a release, create a launcher pointing to the binary
at its permanent location. The helper refuses existing launchers/icons. Linux/BSD launchers reference the
original executable and stop working if it moves. macOS bundles copy the binary
and adjacent LICENSES directory. Reporter bundles also copy an adjacent FFprobe
(requiring its LICENSES directory); otherwise FFprobe must be on PATH. Recreate
macOS bundles after updating binaries.
```sh
magick rust-report.png -resize 256x256 -background none -gravity center \
-extent 256x256 rust-report-icon.png
magick rust-report-icon.png -define icon:auto-resize=256,128,64,48,32,24,16 rust-report.ico
# Linux / FreeBSD: install into your desktop's user application directory.
python3 scripts/create-desktop-launcher.py ascii-names \
--binary "$PWD/target/release/ascii-names" --output "$HOME/.local/share"
# macOS: create a Finder/Dock launcher (run on the Mac).
python3 scripts/create-desktop-launcher.py midra-layout --platform macos \
--binary "$PWD/target/release/midra-layout" --output "$HOME/Applications"
```
The same helper supports `pptx-reporter` and `rundown-converter`; pass their
`-gui` executable. Reporter and rundown portable archives include the helper,
its supporting module, and the icon formats, so these commands also work from
an extracted archive. Respect `XDG_DATA_HOME` instead of `~/.local/share` when
customized. Desktop menus may need a refresh. Windows executables have embedded
icons; shortcuts inherit those icons.
Python scripts and the Companion module run inside a host application and cannot
replace its OS icon. Their PNG/ICO/ICNS files are available for custom shortcuts;
the Companion README displays its module icon. Shared libraries, CI scripts,
packaging helpers and `progress.py` are not standalone applications.
Launcher output is described in [the desktop launcher contract](interfaces/desktop-launchers.md).
Automated checks validate icon containers and launcher output on Linux. Finder,
Dock, Windows Explorer/taskbar and individual Wayland desktop behavior still
need native visual checks. The macOS launchers are not signed or notarized.
## Releases containing both tools
The workspace version applies to both tools. Build the reporter with the root

View File

@ -1,5 +1,7 @@
# Rundown converter
<img src="../crates/rundown-converter/assets/app-icon.png" width="96" alt="Application icon">
Status: first implementation, available from source. A Rust core powers both the
CLI and egui desktop app, styled like the [PPTX reporter](rust-reporter.md).
It reads XLSX and UTF-8 CSV/TSV, infers columns, preserves untimed gaps and exports

View File

@ -2,6 +2,10 @@
[All changelogs](../changelogs.md)
## Unreleased
- Add ImageGen application artwork in PNG, Windows ICO and macOS ICNS formats. Embed native icons and support Linux/BSD desktop entries and macOS app launchers; native Windows/macOS visual checks remain required.
## 2026-11-09
- `7e47054`: Track normalized supplied XLSX fixtures and exercise them in corpus regression tests.

View File

@ -1,5 +1,7 @@
# PPTX reporter
<img src="../crates/pptx-reporter/assets/app-icon.png" width="96" alt="Application icon">
Create video timing reports from a PowerPoint presentation using the desktop
app or CLI. Python and PowerPoint are not required for the Rust application.
For a walkthrough with screenshots, see the [user guide](user-guide.md).

View File

@ -7,6 +7,11 @@ archive-name = "{name}-{bundle}-{target}-v{version}"
root = "{name}-{bundle}-{target}-v{version}"
cargo-binaries = "all"
files = [
{ source = "assets/app-icon.png", destination = "icons/rundown-converter/app-icon.png" },
{ source = "assets/app-icon.ico", destination = "icons/rundown-converter/app-icon.ico" },
{ source = "assets/app-icon.icns", destination = "icons/rundown-converter/app-icon.icns" },
{ source = "scripts/create-desktop-launcher.py", destination = "scripts/create-desktop-launcher.py", workspace-relative = true },
{ source = "scripts/desktop_icons.py", destination = "scripts/desktop_icons.py", workspace-relative = true },
{ source = "LICENSE", destination = "LICENSES/MIT.txt", workspace-relative = true },
{ source = "assets/fonts/LICENSE", destination = "LICENSES/DejaVu.txt" },
{ source = "docs/rundown-portable-quickstart.txt", destination = "README.txt", workspace-relative = true },

View File

@ -27,6 +27,11 @@ archive-name = "{name}-{bundle}-{target}-v{version}"
root = "{name}-{bundle}-{target}-v{version}"
cargo-binaries = "all"
files = [
{ source = "assets/app-icon.png", destination = "icons/pptx-reporter/app-icon.png" },
{ source = "assets/app-icon.ico", destination = "icons/pptx-reporter/app-icon.ico" },
{ source = "assets/app-icon.icns", destination = "icons/pptx-reporter/app-icon.icns" },
{ source = "scripts/create-desktop-launcher.py", destination = "scripts/create-desktop-launcher.py", workspace-relative = true },
{ source = "scripts/desktop_icons.py", destination = "scripts/desktop_icons.py", workspace-relative = true },
{ source = "LICENSE", destination = "LICENSES/reporter-MIT.txt", workspace-relative = true },
{ source = "assets/fonts/LICENSE", destination = "LICENSES/DejaVu.txt" },
{ source = "docs/portable-quickstart.txt", destination = "README.txt", workspace-relative = true },

29
scripts/build-icons.py Normal file
View File

@ -0,0 +1,29 @@
#!/usr/bin/env python3
"""Regenerate committed PNG, ICO and ICNS icons using ImageMagick 7."""
import struct
import subprocess
import tempfile
from pathlib import Path
from desktop_icons import ARTWORK, ROOT
def build(folder):
source = folder / "app-icon-source.png"
subprocess.run(["magick", str(source), "-resize", "256x256", str(folder / "app-icon.png")], check=True)
subprocess.run(["magick", str(source), "-define", "icon:auto-resize=256,128,64,48,32,24,16",
str(folder / "app-icon.ico")], check=True)
chunks = []
with tempfile.TemporaryDirectory() as temporary:
for size, tag in [(128, b"ic07"), (256, b"ic08"), (512, b"ic09"), (1024, b"ic10")]:
png = Path(temporary) / f"{size}.png"
subprocess.run(["magick", str(source), "-resize", f"{size}x{size}", str(png)], check=True)
data = png.read_bytes()
chunks.append(tag + struct.pack(">I", len(data) + 8) + data)
data = b"".join(chunks)
(folder / "app-icon.icns").write_bytes(b"icns" + struct.pack(">I", len(data) + 8) + data)
if __name__ == "__main__":
for relative in ARTWORK.values():
build(ROOT / relative)

View File

@ -0,0 +1,103 @@
#!/usr/bin/env python3
"""Create an icon-bearing Linux/BSD desktop entry or macOS app launcher."""
import argparse
import os
from pathlib import Path
import plistlib
import shutil
import sys
import tempfile
from desktop_icons import APPS, ROOT
def desktop_value(value):
return str(value).replace("\\", "\\\\").replace("\n", "\\n").replace("\r", "\\r").replace("\t", "\\t")
def desktop_exec(path):
# Exec has a second escaping layer inside double quotes, plus field codes.
value = str(path).replace("%", "%%")
for character in ('\\', '"', '`', '$'):
value = value.replace(character, "\\" + character)
return desktop_value('"' + value + '"')
def create(tool, binary, output, platform):
title, assets, _ = APPS[tool]
binary = binary.resolve(strict=True)
if not binary.is_file() or not os.access(binary, os.X_OK):
raise ValueError(f"Not an executable file: {binary}")
output = output.resolve()
output.mkdir(parents=True, exist_ok=True)
assets = ROOT / assets
if not assets.is_dir():
assets = ROOT / "icons" / tool
if platform == "macos":
destination = output / f"{title}.app"
if destination.exists() or destination.is_symlink():
raise FileExistsError(destination)
with tempfile.TemporaryDirectory(dir=output) as temporary:
app = Path(temporary) / destination.name
contents = app / "Contents"
(contents / "MacOS").mkdir(parents=True)
(contents / "Resources").mkdir()
shutil.copyfile(assets / "app-icon.icns", contents / "Resources/app-icon.icns")
with (contents / "Info.plist").open("wb") as stream:
plistlib.dump({
"CFBundleName": title, "CFBundleDisplayName": title,
"CFBundleIdentifier": f"com.beffroi.{tool}",
"CFBundlePackageType": "APPL", "CFBundleExecutable": tool,
"CFBundleIconFile": "app-icon.icns", "CFBundleVersion": "1",
"NSHighResolutionCapable": True,
}, stream)
executable = contents / "MacOS" / tool
shutil.copy2(binary, executable)
executable.chmod(0o755)
# Keep FFprobe discovery beside the actual bundled executable.
probe = binary.parent / "ffprobe"
notices = binary.parent / "LICENSES"
if tool == "pptx-reporter" and probe.exists():
if not probe.is_file() or probe.is_symlink() or not os.access(probe, os.X_OK):
raise ValueError(f"Not a regular executable FFprobe: {probe}")
if not notices.is_dir():
raise ValueError("Bundling adjacent FFprobe requires its LICENSES directory")
shutil.copy2(probe, contents / "MacOS/ffprobe")
if notices.is_dir():
if notices.is_symlink() or any(path.is_symlink() for path in notices.rglob("*")):
raise ValueError("Refusing symlinked bundle notices")
shutil.copytree(notices, contents / "Resources/LICENSES")
app.rename(destination)
return destination
destination = output / "applications" / f"{tool}.desktop"
icon = output / "icons/hicolor/256x256/apps" / f"{tool}.png"
if any(path.exists() or path.is_symlink() for path in (destination, icon)):
raise FileExistsError(f"Launcher or icon already exists for {tool}")
destination.parent.mkdir(parents=True, exist_ok=True)
icon.parent.mkdir(parents=True, exist_ok=True)
with icon.open("xb") as stream:
stream.write((assets / "app-icon.png").read_bytes())
with destination.open("x") as stream:
stream.write(f"[Desktop Entry]\nType=Application\nName={title}\n"
f"Exec={desktop_exec(binary)}\nIcon={desktop_value(icon)}\n"
f"Terminal=false\nCategories=AudioVideo;Utility;\nStartupWMClass={tool}\n")
return destination
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("tool", choices=APPS)
parser.add_argument("--binary", required=True, type=Path)
parser.add_argument("--platform", choices=("linux", "macos"),
default="macos" if sys.platform == "darwin" else "linux")
parser.add_argument("--output", type=Path, required=True,
help="Applications folder on macOS; data prefix (e.g. ~/.local/share) on Linux/BSD")
args = parser.parse_args()
try:
print(create(args.tool, args.binary, args.output, args.platform))
except (OSError, ValueError) as error:
parser.exit(1, f"Cannot create launcher: {error}\n")
if __name__ == "__main__":
main()

15
scripts/desktop_icons.py Normal file
View File

@ -0,0 +1,15 @@
"""Shared application artwork locations (no third-party Python dependencies)."""
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
APPS = {
"ascii-names": ("ASCII Names", "crates/ascii-names/assets", "ascii-names"),
"midra-layout": ("Midra Layout", "crates/midra-layout/assets", "midra-layout"),
"pptx-reporter": ("PPTX Reporter", "crates/pptx-reporter/assets", "pptx-reporter-gui"),
"rundown-converter": ("Rundown Converter", "crates/rundown-converter/assets", "rundown-converter-gui"),
}
ARTWORK = {name: folder for name, (_, folder, _) in APPS.items()} | {
"exporter": "tools/assets/exporter",
"midra-probe": "tools/assets/midra-probe",
"media-player-classic": "companion-modules/media-player-classic/companion/assets",
}

View File

@ -75,6 +75,13 @@ def main():
shutil.copy2(ROOT / "crates/pptx-reporter/assets/fonts/LICENSE", licenses / "DejaVu.txt")
shutil.copytree(args.ffprobe_licenses, licenses / "ffmpeg")
shutil.copy2(ROOT / "docs/windows-quickstart.txt", folder / "README.txt")
icons = folder / "icons/pptx-reporter"
icons.mkdir(parents=True)
for extension in ("png", "ico", "icns"):
shutil.copy2(ROOT / f"crates/pptx-reporter/assets/app-icon.{extension}", icons)
(folder / "scripts").mkdir()
for script in ("create-desktop-launcher.py", "desktop_icons.py"):
shutil.copy2(ROOT / "scripts" / script, folder / "scripts" / script)
if windows:
with zipfile.ZipFile(destination, "x", zipfile.ZIP_DEFLATED) as archive:
for path in sorted(folder.rglob("*")):

107
tests/test_desktop_icons.py Normal file
View File

@ -0,0 +1,107 @@
import importlib.util
import os
from pathlib import Path
import plistlib
import shutil
import struct
import subprocess
import sys
import tempfile
import unittest
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "scripts"))
from desktop_icons import ARTWORK
spec = importlib.util.spec_from_file_location("desktop_launcher", ROOT / "scripts/create-desktop-launcher.py")
launcher = importlib.util.module_from_spec(spec)
spec.loader.exec_module(launcher)
class DesktopIconTests(unittest.TestCase):
def test_all_platform_artwork(self):
for tool, relative in ARTWORK.items():
with self.subTest(tool=tool):
folder = ROOT / relative
png = (folder / "app-icon.png").read_bytes()
self.assertEqual(png[:8], b"\x89PNG\r\n\x1a\n")
self.assertEqual(struct.unpack(">II", png[16:24]), (256, 256))
ico = (folder / "app-icon.ico").read_bytes()
self.assertEqual(struct.unpack("<HHH", ico[:6]), (0, 1, 7))
sizes = set()
for index in range(7):
width, height, _, _, _, _, length, offset = struct.unpack(
"<BBBBHHII", ico[6 + index * 16:22 + index * 16])
self.assertEqual(width, height)
self.assertLessEqual(offset + length, len(ico))
sizes.add(width or 256)
self.assertEqual(sizes, {16, 24, 32, 48, 64, 128, 256})
icns = (folder / "app-icon.icns").read_bytes()
self.assertEqual(icns[:4], b"icns")
self.assertEqual(struct.unpack(">I", icns[4:8])[0], len(icns))
tags = []
offset = 8
while offset < len(icns):
tag, length = struct.unpack(">4sI", icns[offset:offset + 8])
self.assertGreater(length, 8)
self.assertEqual(icns[offset + 8:offset + 16], png[:8])
tags.append(tag)
offset += length
self.assertEqual(offset, len(icns))
self.assertEqual(tags, [b"ic07", b"ic08", b"ic09", b"ic10"])
def test_launchers_and_no_overwrite(self):
with tempfile.TemporaryDirectory(prefix="icons é ") as temporary:
root = Path(temporary)
binary = root / 'player " $ ` % \\ test'
binary.write_text('#!/bin/sh\nprintf "%s" "$1"\n')
binary.chmod(0o755)
for tool in launcher.APPS:
with self.subTest(tool=tool):
app = launcher.create(tool, binary, root / "mac", "macos")
with (app / "Contents/Info.plist").open("rb") as stream:
metadata = plistlib.load(stream)
self.assertTrue((app / "Contents/Resources" / metadata["CFBundleIconFile"]).is_file())
command = app / "Contents/MacOS" / metadata["CFBundleExecutable"]
self.assertFalse(command.samefile(binary))
self.assertEqual(command.read_bytes(), binary.read_bytes())
result = subprocess.check_output([str(command), "argument with spaces"])
self.assertEqual(result, b"argument with spaces")
desktop = launcher.create(tool, binary, root / "linux", "linux")
self.assertIn("%%", desktop.read_text())
if shutil.which("desktop-file-validate"):
subprocess.run(["desktop-file-validate", str(desktop)], check=True)
for platform in ("macos", "linux"):
with self.assertRaises(FileExistsError):
launcher.create(tool, binary, root / ("mac" if platform == "macos" else "linux"), platform)
self.assertTrue(os.access(command, os.X_OK))
def test_macos_reporter_copies_probe_and_notices(self):
with tempfile.TemporaryDirectory() as temporary:
root = Path(temporary)
binary = root / "pptx-reporter-gui"
binary.write_text("#!/bin/sh\nexit 0\n")
binary.chmod(0o755)
probe = root / "ffprobe"
probe.write_bytes(binary.read_bytes())
probe.chmod(0o755)
output = root / "apps"
with self.assertRaisesRegex(ValueError, "LICENSES"):
launcher.create("pptx-reporter", binary, output, "macos")
self.assertEqual(list(output.iterdir()), [])
notices = root / "LICENSES"
notices.mkdir()
(notices / "ffmpeg.txt").write_text("upstream notices")
app = launcher.create("pptx-reporter", binary, output, "macos")
self.assertEqual((app / "Contents/MacOS/ffprobe").read_bytes(), probe.read_bytes())
self.assertEqual((app / "Contents/Resources/LICENSES/ffmpeg.txt").read_text(), "upstream notices")
(notices / "unsafe").symlink_to(binary)
with self.assertRaisesRegex(ValueError, "symlinked"):
launcher.create("pptx-reporter", binary, root / "unsafe-output", "macos")
def test_missing_binary_does_not_create_output(self):
with tempfile.TemporaryDirectory() as temporary:
root = Path(temporary)
with self.assertRaises(FileNotFoundError):
launcher.create("ascii-names", root / "missing", root / "out", "linux")
self.assertFalse((root / "out").exists())

View File

@ -27,7 +27,11 @@ class PortableTests(unittest.TestCase):
licenses = root / "ffmpeg-licenses"
licenses.mkdir()
(licenses / "LICENSE").write_text("fixture notice")
for file in ("LICENSE", "crates/pptx-reporter/assets/fonts/LICENSE", "docs/windows-quickstart.txt"):
for file in ("LICENSE", "crates/pptx-reporter/assets/fonts/LICENSE", "docs/windows-quickstart.txt",
"crates/pptx-reporter/assets/app-icon.png",
"crates/pptx-reporter/assets/app-icon.ico",
"crates/pptx-reporter/assets/app-icon.icns",
"scripts/create-desktop-launcher.py", "scripts/desktop_icons.py"):
path = root / file
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text("fixture")
@ -44,7 +48,8 @@ class PortableTests(unittest.TestCase):
names = {Path(n).name for n in bundle.namelist()}
self.assertTrue({"pptx-reporter.exe", "pptx-reporter-gui.exe",
"ffprobe.exe", "README.txt", "LICENSE",
"reporter-MIT.txt", "DejaVu.txt"} <= names)
"reporter-MIT.txt", "DejaVu.txt", "app-icon.png", "app-icon.ico",
"app-icon.icns", "create-desktop-launcher.py", "desktop_icons.py"} <= names)
self.assertTrue(archive.with_suffix(".zip.sha256").is_file())
with self.assertRaises(SystemExit):
portable.main()

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 364 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 364 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB