From 4b3493465d8c73ea49fd456a5480a5062888e997 Mon Sep 17 00:00:00 2001 From: Youwes09 Date: Wed, 25 Mar 2026 00:01:48 -0500 Subject: [PATCH] Fix: MacOS Directory Build Change --- src-tauri/binaries/suwayomi-launcher.sh | 44 +++++++++++++++++-------- src-tauri/src/lib.rs | 40 +++++++++++++++------- 2 files changed, 60 insertions(+), 24 deletions(-) diff --git a/src-tauri/binaries/suwayomi-launcher.sh b/src-tauri/binaries/suwayomi-launcher.sh index 5e166a6..2245c09 100644 --- a/src-tauri/binaries/suwayomi-launcher.sh +++ b/src-tauri/binaries/suwayomi-launcher.sh @@ -1,24 +1,31 @@ #!/bin/sh # Moku — Suwayomi launcher sidecar for macOS. -# Tauri calls this script directly; the rootDir JVM flag is prepended by -# spawn_server in lib.rs as the first element of invocation.args. +# Tauri calls this script directly as a sidecar (Contents/MacOS/suwayomi-server-{arch}). +# The Suwayomi bundle is placed by Tauri into Contents/Resources/suwayomi-bundle/. set -e -DIR="$(cd "$(dirname "$0")" && pwd)" +# Resolve the real directory of this script, following symlinks. +SELF="$0" +while [ -L "$SELF" ]; do + SELF="$(readlink "$SELF")" +done +DIR="$(cd "$(dirname "$SELF")" && pwd)" -# When running from inside the .app bundle the sidecar lives in -# Contents/MacOS/; the bundle is in Contents/Resources/. -# Walk up to find the bundle directory. +# ── Locate the bundle ───────────────────────────────────────────────────────── +# Inside .app: sidecar = Contents/MacOS/suwayomi-server-{arch} +# bundle = Contents/Resources/suwayomi-bundle/ +# Dev / flat layout: bundle sits next to the sidecar, or one level up. find_bundle() { local base="$1" for candidate in \ - "${base}/suwayomi-bundle" \ "${base}/../Resources/suwayomi-bundle" \ - "${base}/../Resources/binaries/suwayomi-bundle" \ - "${base}/../Resources" + "${base}/suwayomi-bundle" \ + "${base}/../suwayomi-bundle" do - if [ -f "${candidate}/Suwayomi-Server.jar" ]; then - echo "$candidate" + # The jar lives at /bin/Suwayomi-Server.jar + if [ -f "${candidate}/bin/Suwayomi-Server.jar" ]; then + # Canonicalise (no readlink -f on older macOS sh, use cd trick) + echo "$(cd "$candidate" && pwd)" return 0 fi done @@ -27,14 +34,22 @@ find_bundle() { BUNDLE=$(find_bundle "$DIR") || { echo "[sidecar] ERROR: cannot locate suwayomi-bundle relative to $DIR" >&2 + echo "[sidecar] Tried:" >&2 + echo " $DIR/../Resources/suwayomi-bundle" >&2 + echo " $DIR/suwayomi-bundle" >&2 + echo " $DIR/../suwayomi-bundle" >&2 exit 1 } JAVA="${BUNDLE}/jre/bin/java" -JAR="${BUNDLE}/Suwayomi-Server.jar" +JAR="${BUNDLE}/bin/Suwayomi-Server.jar" + +echo "[sidecar] BUNDLE=$BUNDLE" >&2 +echo "[sidecar] JAVA=$JAVA" >&2 +echo "[sidecar] JAR=$JAR" >&2 if [ ! -x "$JAVA" ]; then - echo "[sidecar] ERROR: java not found at $JAVA" >&2 + echo "[sidecar] ERROR: java not executable at $JAVA" >&2 exit 1 fi if [ ! -f "$JAR" ]; then @@ -42,6 +57,9 @@ if [ ! -f "$JAR" ]; then exit 1 fi +# "$@" will contain the -Dsuwayomi.tachidesk.config.server.rootDir=... flag +# prepended by spawn_server in lib.rs, followed by -jar . +# We call java directly so all JVM flags reach it properly. exec "$JAVA" \ -Djava.awt.headless=true \ "$@" \ diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 886fb2d..14bd0a6 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -309,21 +309,39 @@ fn resolve_server_binary( #[cfg(target_os = "macos")] { + // Tauri places externalBin sidecars next to the main binary in + // Contents/MacOS/, not in Contents/Resources/. Derive that path + // from resource_dir (Contents/Resources → Contents/MacOS). + let macos_dir = resource_dir.join("../MacOS") + .canonicalize() + .unwrap_or_else(|_| resource_dir.join("../MacOS")); + + do_log(log, &format!("[resolve] macOS macos_dir = {:?}", macos_dir)); + + // Tauri strips the target triple when installing externalBin sidecars + // into Contents/MacOS/, so the binary is always just "suwayomi-server" + // at runtime. The triple-suffixed names are only needed on disk at + // build time for Tauri to pick the right arch during bundling. let candidates = [ + "suwayomi-server", "suwayomi-server-aarch64-apple-darwin", "suwayomi-server-x86_64-apple-darwin", - "suwayomi-server", ]; - for name in &candidates { - let p = resource_dir.join(name); - do_log(log, &format!("[resolve] macOS candidate: {:?} exists={}", p, p.exists())); - if p.exists() { - do_log(log, &format!("[resolve] using macOS candidate: {:?}", p)); - return Ok(ServerInvocation { - bin: p.to_string_lossy().into_owned(), - args: vec![], - working_dir: None, - }); + + // Search MacOS/ first (correct location), then Resources/ as fallback + // for flat dev layouts where the script sits next to resources. + for search_dir in &[&macos_dir, &resource_dir] { + for name in &candidates { + let p = search_dir.join(name); + do_log(log, &format!("[resolve] macOS candidate: {:?} exists={}", p, p.exists())); + if p.exists() { + do_log(log, &format!("[resolve] using macOS sidecar: {:?}", p)); + return Ok(ServerInvocation { + bin: p.to_string_lossy().into_owned(), + args: vec![], + working_dir: None, + }); + } } } }