diff --git a/.github/workflows/launcher.yml b/.github/workflows/launcher.yml index 3f25e7f0b..d41b38092 100644 --- a/.github/workflows/launcher.yml +++ b/.github/workflows/launcher.yml @@ -187,20 +187,27 @@ jobs: rm -rf "$HORIZON_LAUNCHER_HOME" - name: Package run: | - rm -rf dist ${{ matrix.asset }} && mkdir -p dist - cp target/release/${{ matrix.binary }} dist/ - cd dist - if [[ "${{ matrix.asset }}" == *.tar.gz ]]; then - tar czf ../${{ matrix.asset }} ${{ matrix.binary }} - elif [[ "$RUNNER_OS" == "Windows" ]]; then - 7z a ../${{ matrix.asset }} ${{ matrix.binary }} + rm -rf dist out && mkdir -p out + if [[ "$RUNNER_OS" == "macOS" ]]; then + # Horizon.app, zipped (self-update) and in a .dmg (installer): packaging/macos. + python3 -m venv "$RUNNER_TEMP/dmg" && "$RUNNER_TEMP/dmg/bin/pip" install --quiet dmgbuild==1.6.5 + version=${HORIZON_LAUNCHER_VERSION:-$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1)} + DMGBUILD="$RUNNER_TEMP/dmg/bin/dmgbuild" ../packaging/macos/package.sh target/release/${{ matrix.binary }} "$version" out + rm -rf out/Horizon.app else - zip ../${{ matrix.asset }} ${{ matrix.binary }} + mkdir -p dist + cp target/release/${{ matrix.binary }} dist/ + if [[ "${{ matrix.asset }}" == *.tar.gz ]]; then + (cd dist && tar czf ../out/${{ matrix.asset }} ${{ matrix.binary }}) + else + (cd dist && 7z a ../out/${{ matrix.asset }} ${{ matrix.binary }}) + fi fi + ls -l out - uses: actions/upload-artifact@v4 with: name: ${{ matrix.asset }} - path: launcher/${{ matrix.asset }} + path: launcher/out/* retention-days: 7 release: diff --git a/docs/media/brand/README.md b/docs/media/brand/README.md index a453f4470..c038126cb 100644 --- a/docs/media/brand/README.md +++ b/docs/media/brand/README.md @@ -23,9 +23,9 @@ places it in the design system; `candidates/` keeps the two alternatives that we | Output | Used by | |--------|---------| | `packaging/icons/hicolor//apps/horizon.png` (16–512) and `scalable/apps/horizon.svg` | Linux: copy the tree into `~/.local/share/icons/hicolor` (or `/usr/share/icons/hicolor`) | -| `packaging/linux/horizon-launcher.desktop`, `horizon.desktop` (hand-written) | Linux: `~/.local/share/applications`; Wayland matches the windows' app ids `horizon-launcher` and `horizon` | +| `packaging/linux/horizon-launcher.desktop`, `horizon.desktop` (hand-written) | Linux: the launcher installs both and the hicolor icons itself, under `$XDG_DATA_HOME` (`~/.local/share`), with its own path in `Exec` (`launcher/src/desktop.rs`; `horizon-launcher desktop-entry --remove` takes them out). Wayland matches the windows' app ids `horizon-launcher` and `horizon` | | `packaging/icons/horizon.ico` | Windows: embedded in `horizon-client.exe`, its tools and `horizon-launcher.exe` as icon resource 1 (`build.rs` of each, Windows builds only) | -| `packaging/icons/horizon.icns` | macOS: an app bundle's `Contents/Resources/horizon.icns` (`CFBundleIconFile`) | +| `packaging/icons/horizon.icns` | macOS: `Horizon.app/Contents/Resources/horizon.icns`, packaged with the .dmg by `packaging/macos/package.sh` | | `crates/horizon-theme/icons/horizon-64.png` | the game window's icon at run time (X11 and Windows title bars, `window::icon`) | | `website/public/favicon.svg`, `favicon-32.png`, `apple-touch-icon.png` | the website | | `icon-1024.png`, `icon-macos-1024.png` | previews, store listings | diff --git a/launcher/src/backend.rs b/launcher/src/backend.rs index d1ddc2b8c..e2918dda8 100644 --- a/launcher/src/backend.rs +++ b/launcher/src/backend.rs @@ -1280,6 +1280,77 @@ fn replace_binary(new: &Path, _exe: &Path) -> std::io::Result<()> { self_replace::self_replace(new) } +/// The app bundle the launcher runs from (`…/Horizon.app` for `…/Horizon.app/Contents/MacOS/ +/// horizon-launcher`), or None for a bare binary, as launchers before the .app shipped. +pub fn app_bundle(exe: &Path) -> Option<&Path> { + let macos = exe.parent()?; + let contents = macos.parent()?; + let app = contents.parent()?; + (macos.file_name()? == "MacOS" + && contents.file_name()? == "Contents" + && app.extension()? == "app") + .then_some(app) +} + +/// Finds the first `*.app` folder under `dir`. +fn find_app(dir: &Path) -> Option { + for entry in fs::read_dir(dir).ok()?.flatten() { + let path = entry.path(); + if path.is_dir() { + if path.extension().is_some_and(|e| e == "app") { + return Some(path); + } + if let Some(found) = find_app(&path) { + return Some(found); + } + } + } + None +} + +/// Puts the bundle `new` in place of `app`: copied beside it first (`ditto` keeps its links, +/// modes and signature), then the old one is moved aside and the new one renamed in, so `app` is +/// never half written. The running launcher keeps its open files and works on. +#[cfg(target_os = "macos")] +fn replace_bundle(new: &Path, app: &Path) -> Result<(), String> { + let dir = app.parent().ok_or("The app has no folder.")?; + let name = app.file_name().unwrap_or_default().to_string_lossy(); + let staged = dir.join(format!(".{name}.update-{}", std::process::id())); + let old = dir.join(format!(".{name}.old-{}", std::process::id())); + let _ = fs::remove_dir_all(&staged); + let copied = Command::new("ditto") + .arg(new) + .arg(&staged) + .status() + .map_err(|e| format!("ditto: {e}"))?; + if !copied.success() { + let _ = fs::remove_dir_all(&staged); + return Err(format!( + "Could not copy the new app next to {}.", + app.display() + )); + } + fs::rename(app, &old).map_err(|e| { + let _ = fs::remove_dir_all(&staged); + format!("Could not move {} aside: {e}", app.display()) + })?; + if let Err(e) = fs::rename(&staged, app) { + let _ = fs::rename(&old, app); + let _ = fs::remove_dir_all(&staged); + return Err(format!( + "Could not put the new app at {}: {e}", + app.display() + )); + } + let _ = fs::remove_dir_all(&old); + Ok(()) +} + +#[cfg(not(target_os = "macos"))] +fn replace_bundle(_new: &Path, _app: &Path) -> Result<(), String> { + Err("App bundles are a macOS thing.".into()) +} + /// Downloads a launcher release and puts its binary in place of this one. The running process /// keeps working; `restart` starts the new one. When the file there already is that release or /// a newer one (updated from the command line or another window), there is nothing to do. @@ -1302,6 +1373,17 @@ pub fn self_update(release: &Release, progress: impl Fn(f32)) -> Result<(), Stri download(&url, size, &archive, &progress)?; let unpacked = work.join("unpacked"); unpack(&archive, &url, &unpacked)?; + // A launcher inside Horizon.app replaces the whole bundle (its Info.plist, icon and + // signature belong with the binary); a bare binary, as older launchers are, only the binary, + // which the macOS archive also holds (Horizon.app/Contents/MacOS/horizon-launcher). + if let Some(app) = app_bundle(exe_path()) { + if let Some(new) = find_app(&unpacked) { + replace_bundle(&new, app)?; + let _ = fs::remove_dir_all(&work); + progress(1.0); + return Ok(()); + } + } let binary = find_file(&unpacked, LAUNCHER_BINARY).ok_or("The download has no launcher binary.")?; replace_binary(&binary, exe_path()).map_err(|e| { @@ -1521,6 +1603,10 @@ pub struct Settings { /// Off by default, so the opening animation shows unless the player turns it off. #[serde(default)] pub skip_opening: bool, + /// Linux: whether the launcher keeps its entry in the applications menu (`desktop`). Unset + /// means yes; removing the entry stores `false`, so it doesn't come back on the next start. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub desktop_entry: Option, } impl Settings { @@ -1530,6 +1616,10 @@ impl Settings { pub fn parse(text: &str) -> Self { serde_json::from_str(text).unwrap_or_default() } + /// Whether the launcher keeps its entry in the applications menu (Linux). + pub fn desktop_entry(&self) -> bool { + self.desktop_entry.unwrap_or(true) + } /// Whether new Horizon versions are installed automatically. pub fn auto_install(&self) -> bool { self.install_new_versions.unwrap_or(true) @@ -1878,6 +1968,96 @@ mod tests { let _ = fs::remove_dir_all(&versions); } + #[test] + fn finds_the_app_bundle_around_the_binary() { + let exe = Path::new("/Applications/Horizon.app/Contents/MacOS/horizon-launcher"); + assert_eq!( + app_bundle(exe), + Some(Path::new("/Applications/Horizon.app")) + ); + assert_eq!(app_bundle(Path::new("/Users/me/horizon-launcher")), None); + assert_eq!( + app_bundle(Path::new("/x/Contents/MacOS/horizon-launcher")), + None + ); + let work = std::env::temp_dir().join(format!("horizon-find-app-{}", std::process::id())); + let _ = fs::remove_dir_all(&work); + fs::create_dir_all(work.join("dist/Horizon.app/Contents/MacOS")).unwrap(); + assert_eq!(find_app(&work), Some(work.join("dist/Horizon.app"))); + let _ = fs::remove_dir_all(&work); + } + + /// The whole update of an app bundle, as the release ships it: signed, zipped with `ditto`, + /// unpacked by the launcher, swapped in place of the installed one, still valid. + #[cfg(target_os = "macos")] + #[test] + fn an_app_bundle_updates_in_place() { + use std::os::unix::fs::PermissionsExt; + let work = std::env::temp_dir().join(format!("horizon-bundle-{}", std::process::id())); + let _ = fs::remove_dir_all(&work); + let make = |dir: &Path, version: &str| { + let app = dir.join("Horizon.app"); + fs::create_dir_all(app.join("Contents/MacOS")).unwrap(); + fs::create_dir_all(app.join("Contents/Resources")).unwrap(); + let bin = app.join("Contents/MacOS/horizon-launcher"); + fs::copy("/usr/bin/true", &bin).unwrap(); + fs::set_permissions(&bin, fs::Permissions::from_mode(0o755)).unwrap(); + fs::write(app.join("Contents/Resources/version"), version).unwrap(); + fs::write( + app.join("Contents/Info.plist"), + "\n\ + CFBundleExecutablehorizon-launcher\ + CFBundleIdentifierdev.horizon.test\ + CFBundlePackageTypeAPPL\n", + ) + .unwrap(); + let signed = Command::new("codesign") + .args(["--force", "--sign", "-"]) + .arg(&app) + .status() + .unwrap(); + assert!(signed.success()); + app + }; + let installed = make(&work.join("Applications"), "1.0.0"); + let release = make(&work.join("release"), "2.0.0"); + let zip = work.join("release.zip"); + let zipped = Command::new("ditto") + .args(["-c", "-k", "--norsrc", "--noextattr", "--keepParent"]) + .arg(&release) + .arg(&zip) + .status() + .unwrap(); + assert!(zipped.success()); + unpack(&zip, "release.zip", &work.join("unpacked")).unwrap(); + let new = find_app(&work.join("unpacked")).unwrap(); + replace_bundle(&new, &installed).unwrap(); + let version = fs::read_to_string(installed.join("Contents/Resources/version")).unwrap(); + assert_eq!(version, "2.0.0"); + let bin = installed.join("Contents/MacOS/horizon-launcher"); + assert!( + Command::new(&bin).status().unwrap().success(), + "still executable" + ); + let valid = Command::new("codesign") + .args(["--verify", "--strict"]) + .arg(&installed) + .status() + .unwrap(); + assert!(valid.success(), "the updated bundle's signature holds"); + let left: Vec<_> = fs::read_dir(work.join("Applications")) + .unwrap() + .flatten() + .map(|e| e.file_name()) + .collect(); + assert_eq!( + left, + ["Horizon.app"], + "nothing staged or moved aside is left" + ); + let _ = fs::remove_dir_all(&work); + } + #[test] fn launcher_versions_read_from_the_binary() { assert_eq!( diff --git a/launcher/src/cli.rs b/launcher/src/cli.rs index 43cb39482..095d25c4a 100644 --- a/launcher/src/cli.rs +++ b/launcher/src/cli.rs @@ -106,6 +106,13 @@ enum Cmd { #[arg(long)] check: bool, }, + /// Linux: put Horizon in the applications menu (an entry and the icon, under + /// $XDG_DATA_HOME), or take it out with --remove + DesktopEntry { + /// Remove the entry and the icon, and stop adding them back + #[arg(long)] + remove: bool, + }, /// Serve the Model Context Protocol on stdin and stdout, for AI agents Mcp, } @@ -312,6 +319,18 @@ fn execute(command: Cmd, as_json: bool) -> Result<(), String> { } } Cmd::Update { check } => update(check, as_json)?, + Cmd::DesktopEntry { remove } => { + let mut settings = backend::Settings::load(); + settings.desktop_entry = Some(!remove); + settings.save(); + if remove { + horizon_launcher::desktop::remove()?; + println!("Removed Horizon from the applications menu."); + } else { + horizon_launcher::desktop::install(backend::exe_path())?; + println!("Horizon is in the applications menu."); + } + } Cmd::Mcp => unreachable!(), } Ok(()) diff --git a/launcher/src/desktop.rs b/launcher/src/desktop.rs new file mode 100644 index 000000000..f97433139 --- /dev/null +++ b/launcher/src/desktop.rs @@ -0,0 +1,202 @@ +//! Linux: the launcher puts itself in the applications menu. It writes +//! `applications/horizon-launcher.desktop` (pointing at wherever the binary is now) and Horizon's +//! icon into the `hicolor` theme, under `$XDG_DATA_HOME` (`~/.local/share` by default), so no root +//! is needed; `horizon.desktop` (hidden from menus) gives the game's window its icon on Wayland. +//! A release build does this when it starts, and again whenever the binary has moved; the +//! Settings switch and `horizon-launcher desktop-entry --remove` take it all away again. +use std::fs; +use std::io; +use std::path::{Path, PathBuf}; + +/// The icon theme sizes, as `packaging/icons/hicolor` holds them (`cargo run -p xtask -- icons`). +const ICONS: [(&str, &[u8]); 9] = [ + ( + "16x16", + include_bytes!("../../packaging/icons/hicolor/16x16/apps/horizon.png"), + ), + ( + "24x24", + include_bytes!("../../packaging/icons/hicolor/24x24/apps/horizon.png"), + ), + ( + "32x32", + include_bytes!("../../packaging/icons/hicolor/32x32/apps/horizon.png"), + ), + ( + "48x48", + include_bytes!("../../packaging/icons/hicolor/48x48/apps/horizon.png"), + ), + ( + "64x64", + include_bytes!("../../packaging/icons/hicolor/64x64/apps/horizon.png"), + ), + ( + "128x128", + include_bytes!("../../packaging/icons/hicolor/128x128/apps/horizon.png"), + ), + ( + "256x256", + include_bytes!("../../packaging/icons/hicolor/256x256/apps/horizon.png"), + ), + ( + "512x512", + include_bytes!("../../packaging/icons/hicolor/512x512/apps/horizon.png"), + ), + ( + "scalable", + include_bytes!("../../packaging/icons/hicolor/scalable/apps/horizon.svg"), + ), +]; + +const LAUNCHER_ENTRY: &str = "horizon-launcher.desktop"; +const GAME_ENTRY: &str = "horizon.desktop"; +const GAME_ENTRY_TEXT: &str = include_str!("../../packaging/linux/horizon.desktop"); + +/// `$XDG_DATA_HOME`, or `~/.local/share` when it is unset or not absolute (as the spec says). +pub fn data_home() -> Option { + std::env::var_os("XDG_DATA_HOME") + .map(PathBuf::from) + .filter(|p| p.is_absolute()) + .or_else(|| dirs::home_dir().map(|h| h.join(".local/share"))) +} + +/// Quotes a path for an `Exec` key: inside double quotes, `"`, `` ` ``, `$` and `\` are escaped. +fn quote(path: &Path) -> String { + let mut out = String::from("\""); + for c in path.to_string_lossy().chars() { + if matches!(c, '"' | '`' | '$' | '\\') { + out.push('\\'); + } + out.push(c); + } + out.push('"'); + out +} + +/// The launcher's entry, starting the binary at `exe`. +pub fn launcher_entry(exe: &Path) -> String { + format!( + "[Desktop Entry]\n\ + Type=Application\n\ + Name=Horizon\n\ + GenericName=Game launcher\n\ + Comment=Install, prepare and play Horizon, Minecraft: Java Edition 26.3 rewritten in Rust\n\ + Exec={}\n\ + TryExec={}\n\ + Icon=horizon\n\ + Terminal=false\n\ + Categories=Game;\n\ + StartupWMClass=horizon-launcher\n", + quote(exe), + exe.display() + ) +} + +/// Every file this module writes, with its contents, under `data`. +fn files(data: &Path, exe: &Path) -> Vec<(PathBuf, Vec)> { + let mut out = vec![ + ( + data.join("applications").join(LAUNCHER_ENTRY), + launcher_entry(exe).into_bytes(), + ), + ( + data.join("applications").join(GAME_ENTRY), + GAME_ENTRY_TEXT.as_bytes().to_vec(), + ), + ]; + for (size, bytes) in ICONS { + let name = if size == "scalable" { + "horizon.svg" + } else { + "horizon.png" + }; + out.push(( + data.join("icons/hicolor") + .join(size) + .join("apps") + .join(name), + bytes.to_vec(), + )); + } + out +} + +/// Writes whatever is missing or out of date (a moved binary changes the entry). Returns +/// whether anything was written. +pub fn install_in(data: &Path, exe: &Path) -> io::Result { + let mut wrote = false; + for (path, bytes) in files(data, exe) { + if fs::read(&path).ok().as_deref() == Some(&bytes[..]) { + continue; + } + if let Some(dir) = path.parent() { + fs::create_dir_all(dir)?; + } + // Written beside and renamed, so a menu never reads half an entry. + let temp = path.with_extension("horizon-tmp"); + fs::write(&temp, &bytes)?; + fs::rename(&temp, &path)?; + wrote = true; + } + Ok(wrote) +} + +/// Removes every file `install_in` writes (the folders stay: other apps share them). +pub fn remove_in(data: &Path) -> io::Result<()> { + for (path, _) in files(data, Path::new("")) { + match fs::remove_file(&path) { + Err(e) if e.kind() != io::ErrorKind::NotFound => return Err(e), + _ => {} + } + } + Ok(()) +} + +pub fn install(exe: &Path) -> Result { + let data = data_home().ok_or("No home folder to put the menu entry in.")?; + install_in(&data, exe).map_err(|e| format!("{}: {e}", data.display())) +} + +pub fn remove() -> Result<(), String> { + let data = data_home().ok_or("No home folder.")?; + remove_in(&data).map_err(|e| format!("{}: {e}", data.display())) +} + +/// Whether the launcher's entry is there. +pub fn installed() -> bool { + data_home().is_some_and(|d| d.join("applications").join(LAUNCHER_ENTRY).exists()) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn exec_paths_are_quoted() { + let entry = launcher_entry(Path::new("/home/a b/Horizon \"x\"/horizon-launcher")); + assert!(entry.contains("Exec=\"/home/a b/Horizon \\\"x\\\"/horizon-launcher\"\n")); + assert!(entry.contains("TryExec=/home/a b/Horizon \"x\"/horizon-launcher\n")); + assert!(entry.contains("Icon=horizon\n")); + } + + #[test] + fn installs_follows_a_moved_binary_and_removes() { + let data = std::env::temp_dir().join(format!("horizon-desktop-{}", std::process::id())); + let _ = fs::remove_dir_all(&data); + assert!(install_in(&data, Path::new("/opt/a/horizon-launcher")).unwrap()); + assert!(!install_in(&data, Path::new("/opt/a/horizon-launcher")).unwrap()); + let png = data.join("icons/hicolor/48x48/apps/horizon.png"); + assert!(fs::read(&png).unwrap().starts_with(b"\x89PNG")); + assert!(data + .join("icons/hicolor/scalable/apps/horizon.svg") + .exists()); + assert!(install_in(&data, Path::new("/opt/b/horizon-launcher")).unwrap()); + let entry = fs::read_to_string(data.join("applications").join(LAUNCHER_ENTRY)).unwrap(); + assert!(entry.contains("Exec=\"/opt/b/horizon-launcher\"")); + remove_in(&data).unwrap(); + assert!(!data.join("applications").join(LAUNCHER_ENTRY).exists()); + assert!(!png.exists()); + remove_in(&data).unwrap(); + let _ = fs::remove_dir_all(&data); + } +} diff --git a/launcher/src/lib.rs b/launcher/src/lib.rs index cac481c4a..f19e310d6 100644 --- a/launcher/src/lib.rs +++ b/launcher/src/lib.rs @@ -1,3 +1,4 @@ //! The launcher's core, shared by the GUI, the CLI and the MCP server. pub mod account; pub mod backend; +pub mod desktop; diff --git a/launcher/src/main.rs b/launcher/src/main.rs index bbbbc5b53..276b31193 100644 --- a/launcher/src/main.rs +++ b/launcher/src/main.rs @@ -189,6 +189,17 @@ impl Launcher { if settings.server_dir.is_none() { settings.server_dir = Some(backend::data_dir().join("server")); } + // Release builds on Linux keep their entry in the applications menu up to date (a moved + // binary changes it); `HORIZON_LAUNCHER_DESKTOP_ENTRY=1` does it in a development build. + if cfg!(target_os = "linux") + && settings.desktop_entry() + && (!cfg!(debug_assertions) + || std::env::var_os("HORIZON_LAUNCHER_DESKTOP_ENTRY").is_some()) + { + std::thread::spawn(|| { + let _ = horizon_launcher::desktop::install(backend::exe_path()); + }); + } let installed = backend::installed(); if settings .selected diff --git a/packaging/macos/Info.plist b/packaging/macos/Info.plist new file mode 100644 index 000000000..b50e509c7 --- /dev/null +++ b/packaging/macos/Info.plist @@ -0,0 +1,35 @@ + + + + + + CFBundleDevelopmentRegion + en + CFBundleDisplayName + Horizon + CFBundleExecutable + horizon-launcher + CFBundleIconFile + horizon + CFBundleIdentifier + dev.horizon.launcher + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + Horizon + CFBundlePackageType + APPL + CFBundleShortVersionString + @VERSION@ + CFBundleVersion + @VERSION@ + LSApplicationCategoryType + public.app-category.games + LSMinimumSystemVersion + 11.0 + NSHighResolutionCapable + + NSHumanReadableCopyright + Horizon is MIT licensed. Not an official Minecraft product; not approved by or associated with Mojang or Microsoft. + + diff --git a/packaging/macos/README.md b/packaging/macos/README.md new file mode 100644 index 000000000..7441ccf77 --- /dev/null +++ b/packaging/macos/README.md @@ -0,0 +1,39 @@ +# The macOS launcher: Horizon.app in a .dmg + +`package.sh BINARY VERSION OUTDIR` (run by `.github/workflows/launcher.yml` on macOS) makes: + +- `Horizon.app`: `Contents/MacOS/horizon-launcher`, `Contents/Info.plist` (this folder's, bundle + id `dev.horizon.launcher`, macOS 11 or later), `Contents/Resources/horizon.icns` + (`packaging/icons`, from `cargo run -p xtask -- icons`). +- `horizon-launcher-macos-arm64.dmg`: the installer. Opening it shows the app and a link to + Applications over `background.png` / `background@2x.png` (drawn from `background.html`); the + player drags one onto the other. Built by [dmgbuild](https://github.com/dmgbuild/dmgbuild), + which writes the Finder layout without a GUI session. +- `horizon-launcher-macos-arm64.zip`: the same app, zipped with `ditto`. The launcher updates + itself from this: inside Horizon.app it replaces the whole bundle (copied beside it, then + swapped in by renaming, then restarted); a bare `horizon-launcher` binary, as launchers before + the app shipped, finds the binary inside the zip and replaces only itself. + +## Signing and Gatekeeper + +The app is signed **ad hoc** (`codesign --sign -`): no Apple account is needed, the bundle is +consistent and runs on Apple Silicon, but Gatekeeper doesn't know the developer. The first time +a player opens it after downloading: + +- macOS 14 and earlier: right-click (or Control-click) Horizon in Applications, choose **Open**, + then **Open** in the dialog. +- macOS 15 and later: open it once (it is refused), then **System Settings › Privacy & Security**, + **Open Anyway** next to "Horizon was blocked", and confirm. + +After that it opens normally, and its own updates don't ask again (they aren't downloaded by a +browser, so they carry no quarantine flag). + +To sign and notarize for real (Ludovic's Apple Developer account): import the "Developer ID +Application" certificate into the runner's keychain, set `MACOS_SIGN_IDENTITY` to its name for +`package.sh` (it then signs with the hardened runtime and a timestamp), and after it, notarize and +staple the disk image: + +```sh +xcrun notarytool submit dist/horizon-launcher-macos-arm64.dmg --keychain-profile horizon --wait +xcrun stapler staple dist/horizon-launcher-macos-arm64.dmg +``` diff --git a/packaging/macos/background.html b/packaging/macos/background.html new file mode 100644 index 000000000..6f08e90cd --- /dev/null +++ b/packaging/macos/background.html @@ -0,0 +1,17 @@ + + + +
Horizon
+
+
DRAG HORIZON TO APPLICATIONS
+ diff --git a/packaging/macos/background.png b/packaging/macos/background.png new file mode 100644 index 000000000..727e9df13 Binary files /dev/null and b/packaging/macos/background.png differ diff --git a/packaging/macos/background@2x.png b/packaging/macos/background@2x.png new file mode 100644 index 000000000..31f204668 Binary files /dev/null and b/packaging/macos/background@2x.png differ diff --git a/packaging/macos/package.sh b/packaging/macos/package.sh new file mode 100755 index 000000000..5743343f5 --- /dev/null +++ b/packaging/macos/package.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash +# Packages the macOS launcher: Horizon.app (the binary, Info.plist, the icon), signed, then the +# two release assets, horizon-launcher-macos-arm64.zip (what the launcher updates itself from; +# older launchers find the binary inside it) and horizon-launcher-macos-arm64.dmg (the installer: +# the app and an Applications link over a background, to drag one onto the other). +# +# packaging/macos/package.sh BINARY VERSION OUTDIR +# +# Needs macOS (ditto, codesign, hdiutil) and dmgbuild (pip install dmgbuild==1.6.5; $DMGBUILD +# names it if it isn't on PATH). Signing: ad hoc by default, which needs no Apple account; +# set MACOS_SIGN_IDENTITY to a "Developer ID Application: …" identity in the keychain to sign +# for real (then notarize the .dmg: see packaging/macos/README.md). +set -euo pipefail +here=$(cd "$(dirname "$0")" && pwd) +binary=$1 +version=$2 +out=$(mkdir -p "$3" && cd "$3" && pwd) +app=$out/Horizon.app + +rm -rf "$app" +mkdir -p "$app/Contents/MacOS" "$app/Contents/Resources" +cp "$binary" "$app/Contents/MacOS/horizon-launcher" +chmod 755 "$app/Contents/MacOS/horizon-launcher" +cp "$here/../icons/horizon.icns" "$app/Contents/Resources/horizon.icns" +sed "s/@VERSION@/$version/g" "$here/Info.plist" > "$app/Contents/Info.plist" +printf 'APPL????' > "$app/Contents/PkgInfo" +plutil -lint "$app/Contents/Info.plist" + +identity=${MACOS_SIGN_IDENTITY:--} +if [[ "$identity" == "-" ]]; then + codesign --force --sign - "$app" +else + codesign --force --options runtime --timestamp --sign "$identity" "$app" +fi +codesign --verify --strict --verbose=2 "$app" + +rm -f "$out/horizon-launcher-macos-arm64.zip" "$out/horizon-launcher-macos-arm64.dmg" +# No resource forks or extended attributes: they would land as ._ files inside the bundle. +(cd "$out" && ditto -c -k --norsrc --noextattr --noqtn --keepParent Horizon.app horizon-launcher-macos-arm64.zip) + +cat > "$out/dmg.json" </dev/null +echo "Packaged $out/horizon-launcher-macos-arm64.zip and .dmg"