Ship the launcher as Horizon.app in a .dmg, and in Linux's menus
macOS: packaging/macos/package.sh (run by launcher.yml) builds Horizon.app (Info.plist, bundle id dev.horizon.launcher, macOS 11+, the .icns), signs it ad hoc, and makes the two release assets: horizon-launcher-macos-arm64.dmg, the installer (the app and an Applications link over a background, laid out by dmgbuild without a GUI), and the .zip the launcher updates from. A launcher inside the app replaces the whole bundle: copied beside it with ditto, swapped in by renames, restarted; a bare binary, as older launchers are, still finds its binary in the zip. A macOS test zips, unpacks, swaps and re-verifies a signed bundle. Signing for real is a MACOS_SIGN_IDENTITY away (packaging/macos/README.md, with what Gatekeeper asks meanwhile). Linux: release builds keep horizon-launcher.desktop (with the binary's current path), horizon.desktop (hidden, for the game window's icon) and the hicolor icons under $XDG_DATA_HOME, without root; `horizon-launcher desktop-entry --remove` takes them out and stops it, `desktop-entry` puts them back. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -23,9 +23,9 @@ places it in the design system; `candidates/` keeps the two alternatives that we
|
||||
| Output | Used by |
|
||||
|--------|---------|
|
||||
| `packaging/icons/hicolor/<size>/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 |
|
||||
|
||||
@@ -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<PathBuf> {
|
||||
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<bool>,
|
||||
}
|
||||
|
||||
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"),
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<plist version=\"1.0\"><dict>\
|
||||
<key>CFBundleExecutable</key><string>horizon-launcher</string>\
|
||||
<key>CFBundleIdentifier</key><string>dev.horizon.test</string>\
|
||||
<key>CFBundlePackageType</key><string>APPL</string></dict></plist>\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!(
|
||||
|
||||
@@ -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(())
|
||||
|
||||
@@ -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<PathBuf> {
|
||||
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<u8>)> {
|
||||
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<bool> {
|
||||
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<bool, String> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<!-- Horizon.app's Info.plist; package.sh fills in @VERSION@ from launcher/Cargo.toml. -->
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleDisplayName</key>
|
||||
<string>Horizon</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>horizon-launcher</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string>horizon</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>dev.horizon.launcher</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>Horizon</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>@VERSION@</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>@VERSION@</string>
|
||||
<key>LSApplicationCategoryType</key>
|
||||
<string>public.app-category.games</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>11.0</string>
|
||||
<key>NSHighResolutionCapable</key>
|
||||
<true/>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>Horizon is MIT licensed. Not an official Minecraft product; not approved by or associated with Mojang or Microsoft.</string>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -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
|
||||
```
|
||||
@@ -0,0 +1,17 @@
|
||||
<!doctype html>
|
||||
<!-- The .dmg window's background (background.png 660x420, background@2x.png 1320x840).
|
||||
Render: from website/, node -e with Playwright at deviceScaleFactor 1 and 2 (see README). -->
|
||||
<meta charset="utf-8"><style>
|
||||
@font-face{font-family:Geist;src:url(../../website/public/fonts/Geist-Medium.woff2);font-weight:500}
|
||||
@font-face{font-family:"Geist Mono";src:url(../../website/public/fonts/GeistMono-Regular.woff2)}
|
||||
html,body{margin:0;width:660px;height:420px;overflow:hidden;background:#fafafc;font-family:Geist;color:#16181f}
|
||||
.arrow{position:absolute;left:262px;top:199px;width:136px;height:1px;background:#5b3fd6}
|
||||
.arrow::after{content:"";position:absolute;right:-1px;top:-4px;width:8px;height:8px;border-top:1px solid #5b3fd6;border-right:1px solid #5b3fd6;transform:rotate(45deg)}
|
||||
.cap{position:absolute;left:0;right:0;top:346px;text-align:center;font:11px "Geist Mono";letter-spacing:.06em;color:#646875}
|
||||
.word{position:absolute;left:24px;top:22px;display:flex;align-items:center;gap:8px;font-weight:500;font-size:13px}
|
||||
.word img{width:16px}
|
||||
</style><body>
|
||||
<div class="word"><img src="../../docs/media/brand/mark.svg" alt="">Horizon</div>
|
||||
<div class="arrow"></div>
|
||||
<div class="cap">DRAG HORIZON TO APPLICATIONS</div>
|
||||
</body>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 5.0 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
Executable
+57
@@ -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" <<JSON
|
||||
{
|
||||
"title": "Horizon",
|
||||
"icon-size": 128,
|
||||
"background": "$here/background.png",
|
||||
"window": { "position": { "x": 200, "y": 160 }, "size": { "width": 660, "height": 420 } },
|
||||
"format": "UDZO",
|
||||
"contents": [
|
||||
{ "x": 180, "y": 200, "type": "file", "path": "$app" },
|
||||
{ "x": 480, "y": 200, "type": "link", "path": "/Applications" }
|
||||
]
|
||||
}
|
||||
JSON
|
||||
"${DMGBUILD:-dmgbuild}" -s "$out/dmg.json" Horizon "$out/horizon-launcher-macos-arm64.dmg"
|
||||
rm "$out/dmg.json"
|
||||
hdiutil verify "$out/horizon-launcher-macos-arm64.dmg" >/dev/null
|
||||
echo "Packaged $out/horizon-launcher-macos-arm64.zip and .dmg"
|
||||
Reference in New Issue
Block a user