Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

fix(spaces-macos): run cua-spacesd from Contents/Helpers so opening the app shows a window (#5871)

ddupont92c4cbe22411
diff --git a/apps/cua-spaces-macos/README.md b/apps/cua-spaces-macos/README.md
index 9eeec2d2d9..b6d5eac482 100644
--- a/apps/cua-spaces-macos/README.md
+++ b/apps/cua-spaces-macos/README.md
@@ -440,8 +440,13 @@ and a Developer ID signature with the hardened runtime from the inside out
(Sparkle.framework in Sparkle's documented order: `Installer.xpc`,
`Downloader.xpc`, `Autoupdate`, `Updater.app`, the framework; then
`libcua_sdk.dylib`, then `Contents/MacOS/cua` as `com.trycua.cua` with
-`Support/cua.entitlements`, then the app as `com.trycua.spaces.macos` with
-`Support/CuaSpacesMac.entitlements`). It ends with `scripts/check-launch.sh`:
+`Support/cua.entitlements`, the host service `Contents/Helpers/cua-spacesd` as
+`com.trycua.cua-env-driver`, then the app as `com.trycua.spaces.macos` with
+`Support/CuaSpacesMac.entitlements`). `scripts/check-bundle-layout.sh` keeps
+everything but the app and the command-line tools out of `Contents/MacOS`: a
+process there that starts AppKit (cua-spacesd does, for its cursor overlay)
+registers with LaunchServices as the app itself, and opening Cua Spaces then
+activates that windowless process instead of showing a window. It ends with `scripts/check-launch.sh`:
every library resolves inside the bundle and passes library validation, and
`CuaSpacesMac --check-launch-only` starts and exits. The workflow notarizes
and staples the app, packs it with `scripts/package-dmg.sh` into
diff --git a/apps/cua-spaces-macos/Sources/CuaSpacesMac/ServiceLauncher.swift b/apps/cua-spaces-macos/Sources/CuaSpacesMac/ServiceLauncher.swift
index 33ff8d2f27..2ffca8f1ba 100644
--- a/apps/cua-spaces-macos/Sources/CuaSpacesMac/ServiceLauncher.swift
+++ b/apps/cua-spaces-macos/Sources/CuaSpacesMac/ServiceLauncher.swift
@@ -13,8 +13,8 @@
// (by default ~/.cua/helper/
// service.json; written by cua-host:
// args, env, log, working directory)
-// and runs Contents/MacOS/cua-spacesd
-// with it
+// and runs Contents/Helpers/
+// cua-spacesd with it
// CuaSpacesMac check-permissions `cua-spacesd check-permissions` with
// this terminal's stdio: the app's own
// permission state (cua-host's
@@ -49,12 +49,13 @@ private func specPath() -> String? {
return HelperService.specPath(info: Bundle.main.infoDictionary, home: home)
}
-/// `cua-spacesd` next to this executable (never a path from the spec: only
-/// the code sealed in this app runs with the app's permissions).
+/// This app's `Contents/Helpers/cua-spacesd` (never a path from the spec:
+/// only the code sealed in this app runs with the app's permissions). Not
+/// `Contents/MacOS`: from there it would register with LaunchServices as
+/// the app itself (see `HelperService.daemonInContents`).
private func daemonPath() -> String {
let me = Bundle.main.executablePath ?? CommandLine.arguments[0]
- return URL(fileURLWithPath: me).resolvingSymlinksInPath()
- .deletingLastPathComponent().appendingPathComponent("cua-spacesd").path
+ return HelperService.daemonPath(executable: URL(fileURLWithPath: me)).path
}
private func log(_ message: String) {
diff --git a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/LoginItem.swift b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/LoginItem.swift
index 7e06bff19a..8faf3462c9 100644
--- a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/LoginItem.swift
+++ b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/LoginItem.swift
@@ -144,6 +144,26 @@ public enum HelperService {
return (base as NSString).appendingPathComponent("helper/service.json")
}
+ /// Where the host service's executable lives, relative to the app's
+ /// `Contents`: `Helpers/cua-spacesd`, never `MacOS/`. AppKit takes the
+ /// main bundle from the executable's path, so a cua-spacesd in
+ /// `Contents/MacOS` checks in with LaunchServices *as the app* (same
+ /// bundle id and name) when its cursor overlay starts AppKit. Opening
+ /// the app then activates that windowless helper instead of launching
+ /// the UI. From `Contents/Helpers` it has no bundle of its own and runs
+ /// as a nameless background UI element (`cua_host::service::
+ /// APP_HELPER_DAEMON`; `scripts/build-app.sh` puts it there).
+ public static let daemonInContents = "Helpers/cua-spacesd"
+
+ /// The cua-spacesd of the app whose executable is `executable`
+ /// (`<App>.app/Contents/MacOS/<exe>`): `Contents/Helpers/cua-spacesd`.
+ public static func daemonPath(executable: URL) -> URL {
+ executable.resolvingSymlinksInPath()
+ .deletingLastPathComponent() // Contents/MacOS
+ .deletingLastPathComponent() // Contents
+ .appendingPathComponent(daemonInContents)
+ }
+
private static func stamped(_ info: [String: Any]?, _ key: String) -> String? {
guard let value = (info?[key] as? String)?.trimmingCharacters(in: .whitespaces),
!value.isEmpty else { return nil }
diff --git a/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/HelperServiceTests.swift b/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/HelperServiceTests.swift
index ffb21e675a..f79463ded4 100644
--- a/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/HelperServiceTests.swift
+++ b/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/HelperServiceTests.swift
@@ -48,4 +48,16 @@ struct HelperServiceTests {
#expect(HelperService.specPath(info: ["CuaChannel": "local", "CuaHome": "cua-local"], home: home) == nil)
#expect(HelperService.specPath(info: ["CuaHome": "cua-local"], home: home) == nil)
}
+
+ /// The host service runs from Contents/Helpers, outside Contents/MacOS:
+ /// from Contents/MacOS, AppKit (its cursor overlay) registered it with
+ /// LaunchServices as the app itself, and opening Cua Spaces activated
+ /// the windowless helper instead of showing a window.
+ @Test func theHostServiceRunsFromContentsHelpers() {
+ let exe = URL(fileURLWithPath: "/Applications/Cua Spaces.app/Contents/MacOS/CuaSpacesMac")
+ let daemon = HelperService.daemonPath(executable: exe)
+ #expect(daemon.path == "/Applications/Cua Spaces.app/Contents/Helpers/cua-spacesd")
+ #expect(!daemon.path.contains("/Contents/MacOS/"))
+ #expect(HelperService.daemonInContents == "Helpers/cua-spacesd")
+ }
}
diff --git a/apps/cua-spaces-macos/scripts/build-app.sh b/apps/cua-spaces-macos/scripts/build-app.sh
index b60797722d..d7c6a832d1 100755
--- a/apps/cua-spaces-macos/scripts/build-app.sh
+++ b/apps/cua-spaces-macos/scripts/build-app.sh
@@ -14,7 +14,7 @@
# artifact, with its XPC services) in Contents/Frameworks and the
# third-party notices (Settings, About, Acknowledgements), the host
# service (the pinned cua-spacesd from scripts/fetch-spacesd.sh, or
-# $CUA_SPACESD_BIN, in Contents/MacOS; the app's own executable runs it as
+# $CUA_SPACESD_BIN, in Contents/Helpers; the app's own executable runs it as
# its login item, whose SMAppService plist is in
# Contents/Library/LaunchAgents), then signs it ad hoc as
# com.trycua.spaces.macos.
@@ -191,15 +191,20 @@ for rp in $(otool -l "$app/Contents/MacOS/CuaSpacesMac" | awk '/LC_RPATH/ {getli
done
install_name_tool -add_rpath "@executable_path/../Frameworks" "$app/Contents/MacOS/CuaSpacesMac" 2>/dev/null || true
-# The host service: cua-spacesd next to the app's executable, which runs it
-# as the app's login item (SMAppService.agent; `CuaSpacesMac
-# --service-helper run`), so macOS asks for and keeps its permissions under
-# the app's own name, "Cua Spaces".
-mkdir -p "$app/Contents/Library/LaunchAgents"
+# The host service: cua-spacesd in Contents/Helpers. The app's own
+# executable runs it as the app's login item (SMAppService.agent;
+# `CuaSpacesMac --service-helper run`), so macOS asks for and keeps its
+# permissions under the app's own name, "Cua Spaces". Not in Contents/MacOS:
+# AppKit takes the main bundle from the executable's path, so when the
+# daemon's cursor overlay starts AppKit there it checks in with
+# LaunchServices as the app itself, and opening Cua Spaces then activates
+# the windowless daemon instead of launching the app (see the
+# Contents/MacOS check below).
+mkdir -p "$app/Contents/Library/LaunchAgents" "$app/Contents/Helpers"
# shellcheck disable=SC2086 # one word per architecture
spacesd="$("$here/scripts/fetch-spacesd.sh" ${archs:-$(uname -m)})"
-cp "$spacesd" "$app/Contents/MacOS/cua-spacesd"
-chmod 0755 "$app/Contents/MacOS/cua-spacesd"
+cp "$spacesd" "$app/Contents/Helpers/cua-spacesd"
+chmod 0755 "$app/Contents/Helpers/cua-spacesd"
helper_plist="$app/Contents/Library/LaunchAgents/$helper_label.plist"
cp "$here/Support/Helper/com.trycua.spaces.helper.plist" "$helper_plist"
if [ "$channel" = local ]; then
@@ -218,7 +223,7 @@ if [ "$config" = release ]; then
syms="$out/dSYMs"
rm -rf "$syms"
mkdir -p "$syms"
- for f in "$app/Contents/MacOS/CuaSpacesMac" "$app/Contents/MacOS/cua" "$app/Contents/MacOS/cua-spacesd" \
+ for f in "$app/Contents/MacOS/CuaSpacesMac" "$app/Contents/MacOS/cua" "$app/Contents/Helpers/cua-spacesd" \
"$app/Contents/Frameworks/libcua_sdk.dylib"; do
[ -f "$f" ] || continue
# A prebuilt binary (cua-spacesd) has no debug map: its dSYM still
@@ -232,7 +237,7 @@ if [ "$config" = release ]; then
fi
# The daemon keeps a signature of its own (ad hoc here; build-release.sh
# signs it with the release identity).
-codesign -s - -f -i com.trycua.cua-env-driver "$app/Contents/MacOS/cua-spacesd"
+codesign -s - -f -i com.trycua.cua-env-driver "$app/Contents/Helpers/cua-spacesd"
if [ -x "$cli" ]; then
codesign -s - -f -i com.trycua.cua "$app/Contents/MacOS/cua"
@@ -286,13 +291,17 @@ fi
# only fail on the other kind of Mac).
if [ -n "$archs" ]; then
for f in "$app/Contents/MacOS/CuaSpacesMac" "$app/Contents/Frameworks/libcua_sdk.dylib" "$app/Contents/MacOS/cua" \
- "$app/Contents/Frameworks/Sparkle.framework/Versions/B/Sparkle" "$app/Contents/MacOS/cua-spacesd"; do
+ "$app/Contents/Frameworks/Sparkle.framework/Versions/B/Sparkle" "$app/Contents/Helpers/cua-spacesd"; do
[ -e "$f" ] || continue
for arch in $archs; do
lipo "$f" -verify_arch "$arch" || { echo "$f has no $arch slice ($(lipo -archs "$f"))" >&2; exit 1; }
done
done
fi
+# Only the app and the command-line tools are in Contents/MacOS
+# (scripts/check-bundle-layout.sh: a background process there that starts
+# AppKit registers as the app and takes over its launch).
+"$here/scripts/check-bundle-layout.sh" "$app" >&2
# It launches (scripts/check-launch.sh: libraries resolve and load; the app
# starts and exits before any window).
"$here/scripts/check-launch.sh" "$app" >&2
diff --git a/apps/cua-spaces-macos/scripts/build-release.sh b/apps/cua-spaces-macos/scripts/build-release.sh
index 01aa8a0338..910a30cd8b 100755
--- a/apps/cua-spaces-macos/scripts/build-release.sh
+++ b/apps/cua-spaces-macos/scripts/build-release.sh
@@ -18,9 +18,10 @@
# Contents/MacOS/cua-vz ai.cua.vz, libs/cua/vz/cua-vz.entitlements
# (the microVM monitor; arm64 builds)
# Contents/Resources/cua-microvm-init the microVMs' Linux guest init (data)
-# Contents/MacOS/cua-spacesd com.trycua.cua-env-driver (the host service,
+# Contents/Helpers/cua-spacesd com.trycua.cua-env-driver (the host service,
# which the app's own executable runs as its
-# login item)
+# login item; never in Contents/MacOS, where
+# it would register as the app)
# Cua Spaces.app com.trycua.spaces.macos, Support/CuaSpacesMac.entitlements
#
# scripts/build-release.sh --version 0.2.0[-suffix] [--build-number N]
@@ -160,7 +161,7 @@ if [ -n "$feed_url" ]; then
case "$feed_url" in https://*) ;; *) echo "--feed-url must be https" >&2; exit 2 ;; esac
/usr/libexec/PlistBuddy -c "Set :SUFeedURL $feed_url" "$plist"
fi
-[ -x "$app/Contents/MacOS/cua-spacesd" ] || { echo "$app has no Contents/MacOS/cua-spacesd" >&2; exit 1; }
+[ -x "$app/Contents/Helpers/cua-spacesd" ] || { echo "$app has no Contents/Helpers/cua-spacesd" >&2; exit 1; }
[ -f "$app/Contents/Library/LaunchAgents/com.trycua.spaces.helper.plist" ] ||
{ echo "$app has no com.trycua.spaces.helper.plist" >&2; exit 1; }
# The symbols build-app.sh took out of the binaries, for symbolicating crash
@@ -211,7 +212,7 @@ fi
# The host service. The app's own executable runs it, so its permissions
# are the app's (designated requirement: identifier and team, checked
# below), and they stay granted across updates.
-"${sign[@]}" --identifier com.trycua.cua-env-driver "$app/Contents/MacOS/cua-spacesd"
+"${sign[@]}" --identifier com.trycua.cua-env-driver "$app/Contents/Helpers/cua-spacesd"
app_entitlements="$here/Support/CuaSpacesMac.entitlements"
if [ "$identity" = "-" ]; then
app_entitlements="$out/.adhoc.entitlements"
@@ -223,7 +224,7 @@ fi
codesign --verify --deep --strict --verbose=2 "$app" >&2
for f in "$app" "$app/Contents/MacOS/cua" "$app/Contents/Frameworks/libcua_sdk.dylib" "${sparkle_parts[@]}" \
- "$app/Contents/MacOS/cua-spacesd" ${vz_parts[@]+"${vz_parts[@]}"}; do
+ "$app/Contents/Helpers/cua-spacesd" ${vz_parts[@]+"${vz_parts[@]}"}; do
flags="$(codesign -dv "$f" 2>&1 | sed -n 's/^CodeDirectory.*flags=\([^ ]*\).*/\1/p')"
case "$flags" in *runtime*) ;; *) echo "$f is not signed with the hardened runtime ($flags)" >&2; exit 1 ;; esac
done
@@ -266,7 +267,7 @@ fi
# A Developer ID build signs Sparkle with the same team (library
# validation stays on: the app loads only its own team's code).
if [ "$identity" != "-" ]; then
- for f in "${sparkle_parts[@]}" "$app/Contents/MacOS/cua-spacesd"; do
+ for f in "${sparkle_parts[@]}" "$app/Contents/Helpers/cua-spacesd"; do
codesign --verify -R="anchor apple generic and certificate leaf[subject.OU] = \"$team\"" "$f" ||
{ echo "$f is not signed by team $team" >&2; exit 1; }
done
@@ -277,6 +278,8 @@ for f in "$app/Contents/MacOS/CuaSpacesMac" "$app/Contents/MacOS/cua" "$app/Cont
grep -vE '^(/usr/lib/|/System/Library/|@rpath/libcua_sdk\.dylib$|@rpath/Sparkle\.framework/Versions/B/Sparkle$)' || true)"
[ -z "$bad" ] || { echo "$f links outside the bundle and the OS: $bad" >&2; exit 1; }
done
+# The host service is outside Contents/MacOS (see build-app.sh).
+"$here/scripts/check-bundle-layout.sh" "$app" >&2
# It launches: every library resolves inside the bundle and passes library
# validation, and the app starts and exits (--check-launch-only).
"$here/scripts/check-launch.sh" "$app" >&2
diff --git a/apps/cua-spaces-macos/scripts/check-bundle-layout.sh b/apps/cua-spaces-macos/scripts/check-bundle-layout.sh
new file mode 100755
index 0000000000..0557e7535f
--- /dev/null
+++ b/apps/cua-spaces-macos/scripts/check-bundle-layout.sh
@@ -0,0 +1,44 @@
+#!/usr/bin/env bash
+# SPDX-License-Identifier: FSL-1.1-MIT
+# Copyright (c) 2026 Cua AI, Inc.
+
+# Checks where a built Cua Spaces app keeps its executables:
+#
+# Contents/MacOS only the app's own executable (CFBundleExecutable),
+# the `cua` CLI and the microVM monitor `cua-vz`
+# Contents/Helpers the host service, cua-spacesd
+#
+# Why: AppKit and LaunchServices take a process's bundle from its
+# executable's path, and any executable in Contents/MacOS is the app. When
+# a background process there starts AppKit (cua-spacesd does, for its cursor
+# overlay), it checks in with LaunchServices under the app's bundle id and
+# name, and opening Cua Spaces (Dock, Finder, `open -a`) then activates that
+# windowless process instead of launching the app: no window ever appears.
+# From Contents/Helpers it has no bundle and runs as an unnamed UI element.
+# A new executable goes to Contents/Helpers unless it is the app itself or a
+# command-line tool that never starts AppKit.
+#
+# scripts/check-bundle-layout.sh <App.app>
+set -euo pipefail
+app="${1:?usage: check-bundle-layout.sh <App.app>}"
+[ -d "$app/Contents" ] || { echo "$app is not an app bundle" >&2; exit 1; }
+main="$(/usr/libexec/PlistBuddy -c "Print :CFBundleExecutable" "$app/Contents/Info.plist" 2>/dev/null || true)"
+[ -n "$main" ] || { echo "$app/Contents/Info.plist has no CFBundleExecutable" >&2; exit 1; }
+
+bad=0
+for f in "$app/Contents/MacOS"/*; do
+ [ -e "$f" ] || continue
+ name="$(basename "$f")"
+ case "$name" in
+ "$main" | cua | cua-vz) ;;
+ *)
+ echo "$app: Contents/MacOS/$name is not the app or a command-line tool; put it in Contents/Helpers (from Contents/MacOS, a process that starts AppKit registers as the app and takes over its launch)" >&2
+ bad=1
+ ;;
+ esac
+done
+if [ ! -x "$app/Contents/Helpers/cua-spacesd" ]; then
+ echo "$app has no Contents/Helpers/cua-spacesd (the host service)" >&2
+ bad=1
+fi
+exit "$bad"
diff --git a/apps/cua-spaces-macos/scripts/fetch-spacesd.sh b/apps/cua-spaces-macos/scripts/fetch-spacesd.sh
index 459e267cbf..de3c8798cb 100755
--- a/apps/cua-spaces-macos/scripts/fetch-spacesd.sh
+++ b/apps/cua-spaces-macos/scripts/fetch-spacesd.sh
@@ -2,7 +2,7 @@
# SPDX-License-Identifier: FSL-1.1-MIT
# Copyright (c) 2026 Cua AI, Inc.
-# Prints the path of the cua-spacesd the app bundles in Contents/MacOS (its host service):
+# Prints the path of the cua-spacesd the app bundles in Contents/Helpers (its host service):
# $CUA_SPACESD_BIN when set, else the pinned release (libs/cua-spacesd/VERSION,
# the version cua-host downloads for CLI-only installs), downloaded once into
# .build/spacesd/<version>/ and verified against its published sha256.
diff --git a/apps/cua-spaces-macos/scripts/install-local.sh b/apps/cua-spaces-macos/scripts/install-local.sh
index a709024e6a..8bb254811e 100755
--- a/apps/cua-spaces-macos/scripts/install-local.sh
+++ b/apps/cua-spaces-macos/scripts/install-local.sh
@@ -706,9 +706,9 @@ EOF
# The host service is this checkout's build, not the pinned release (which
# would ignore the Local ports and take the released app's).
- if [ ! -x "$app/Contents/MacOS/cua-spacesd" ]; then
- bad "it has no Contents/MacOS/cua-spacesd"
- elif [ "$(code_hash "$app/Contents/MacOS/cua-spacesd" || true)" != "$SPACESD_CODE_HASH" ]; then
+ if [ ! -x "$app/Contents/Helpers/cua-spacesd" ]; then
+ bad "it has no Contents/Helpers/cua-spacesd"
+ elif [ "$(code_hash "$app/Contents/Helpers/cua-spacesd" || true)" != "$SPACESD_CODE_HASH" ]; then
bad "the bundled cua-spacesd is not the build of this checkout ($SPACESD_BIN), probably the pinned release, which ignores the Local ports. build-app.sh must bundle \$CUA_SPACESD_BIN."
fi
diff --git a/apps/cua-spaces-macos/scripts/test-helper-upgrade.sh b/apps/cua-spaces-macos/scripts/test-helper-upgrade.sh
index 11dd3c9a18..94fa790994 100755
--- a/apps/cua-spaces-macos/scripts/test-helper-upgrade.sh
+++ b/apps/cua-spaces-macos/scripts/test-helper-upgrade.sh
@@ -82,6 +82,15 @@ same_machine_checks() {
'"$cua" sandbox exec "relay:$(cat "$state/machine-id")" -- echo ok 2>/dev/null | grep -qx ok'
}
+# Whether LaunchServices lists a cua-spacesd under the app's bundle id: it
+# then owns the app's launch (opening Cua Spaces activates it, no window).
+spacesd_is_the_app() {
+ lsappinfo list | awk '
+ /bundleID=/ { id = $0 }
+ /executable path=/ { if (id ~ /"com\.trycua\.spaces\.macos"/ && $0 ~ /\/cua-spacesd"/) found = 1 }
+ END { exit !found }'
+}
+
helper_checks() {
local s
s="$(status_json)"
@@ -89,7 +98,8 @@ helper_checks() {
check "the app's login item is running" 'launchctl print "$gui/$label_new" 2>/dev/null | grep -q "state = running"'
check "the app's own executable runs it" 'pgrep -f "CuaSpacesMac --service-helper run" >/dev/null'
check "cua-spacesd runs inside the app" \
- 'pgrep -fl "Cua Spaces.app/Contents/MacOS/cua-spacesd" >/dev/null'
+ 'pgrep -fl "Cua Spaces.app/Contents/Helpers/cua-spacesd" >/dev/null'
+ check "cua-spacesd is not registered as the app (opening it shows a window)" '! spacesd_is_the_app'
check "the old agent is gone from launchd" '! launchctl print "$gui/$label_old" >/dev/null 2>&1'
check "the old plist is gone" '[ ! -e "$HOME/Library/LaunchAgents/$label_old.plist" ]'
check "the old binary is gone" '[ ! -e "$HOME/.cua/host/bin/cua-spacesd" ]'
diff --git a/apps/cua-spaces-macos/scripts/tests/install-local-test.sh b/apps/cua-spaces-macos/scripts/tests/install-local-test.sh
index e1a8f5932f..6bd809c06a 100755
--- a/apps/cua-spaces-macos/scripts/tests/install-local-test.sh
+++ b/apps/cua-spaces-macos/scripts/tests/install-local-test.sh
@@ -123,15 +123,15 @@ helper="${FAKE_BUILD_HELPER_LABEL:-com.trycua.spaces.local.helper}"
associated="${FAKE_BUILD_ASSOCIATED:-$id}"
app="$out/$name.app"
rm -rf "$app"
-mkdir -p "$app/Contents/MacOS" "$app/Contents/Resources" "$app/Contents/Frameworks" "$app/Contents/Library/LaunchAgents"
+mkdir -p "$app/Contents/MacOS" "$app/Contents/Helpers" "$app/Contents/Resources" "$app/Contents/Frameworks" "$app/Contents/Library/LaunchAgents"
for b in CuaSpacesMac cua; do cp "$FAKE_STUB" "$app/Contents/MacOS/$b"; done
# The host service, as the real build-app.sh gets it: from fetch-spacesd.sh,
# which prints $CUA_SPACESD_BIN when set and the pinned release otherwise.
# FAKE_BUILD_IGNORE_SPACESD_BIN stands for a build-app.sh that does not honour it.
if [ "${FAKE_BUILD_IGNORE_SPACESD_BIN:-0}" = 1 ]; then unset CUA_SPACESD_BIN; fi
spacesd="$("$(dirname "$0")/fetch-spacesd.sh")"
-cp "$spacesd" "$app/Contents/MacOS/cua-spacesd"
-chmod 0755 "$app/Contents/MacOS/cua-spacesd"
+cp "$spacesd" "$app/Contents/Helpers/cua-spacesd"
+chmod 0755 "$app/Contents/Helpers/cua-spacesd"
cp "$FAKE_DYLIB" "$app/Contents/Frameworks/libfake.dylib"
fw="$app/Contents/Frameworks/Fake.framework"
mkdir -p "$fw/Versions/A/Resources"
@@ -185,7 +185,7 @@ cat > "$app/Contents/Library/LaunchAgents/$helper.plist" <<PLIST
<key>AssociatedBundleIdentifiers</key><array><string>$associated</string></array>
</dict></plist>
PLIST
-/usr/bin/codesign -s - -f -i "$id" "$app/Contents/MacOS/cua-spacesd" >/dev/null 2>&1
+/usr/bin/codesign -s - -f -i "$id" "$app/Contents/Helpers/cua-spacesd" >/dev/null 2>&1
/usr/bin/codesign -s - -f -i "$id" "$app" >/dev/null 2>&1
echo "$app"
EOF
@@ -481,7 +481,7 @@ check "builds with --channel local debug <out>" 'grep >/dev/null -- "^--channel
check "the app is ~/Applications/Cua Spaces Local.app with the Local bundle id" '[ "$(installed_id "$LOCAL_APP")" = com.trycua.spaces.local ]'
check "the signature verifies (deep, strict)" '/usr/bin/codesign --verify --deep --strict "$LOCAL_APP" 2>/dev/null'
check "nested code was re-signed with the app's identity (cua-spacesd keeps its identifier)" \
- '/usr/bin/codesign -dv "$LOCAL_APP/Contents/MacOS/cua-spacesd" 2>&1 | grep >/dev/null "^Identifier=com.trycua.spaces.local$"'
+ '/usr/bin/codesign -dv "$LOCAL_APP/Contents/Helpers/cua-spacesd" 2>&1 | grep >/dev/null "^Identifier=com.trycua.spaces.local$"'
check "the nested framework is signed and sealed" '/usr/bin/codesign --verify --strict "$LOCAL_APP/Contents/Frameworks/Fake.framework" 2>/dev/null'
check "cua-local links to the bundled cua" '[ "$(readlink "$LOCAL_CLI")" = "$LOCAL_APP/Contents/MacOS/cua" ]'
check "cua-local runs the bundled cua" 'STUB_LOG="$STUB_LOG" "$LOCAL_CLI" status && grep >/dev/null "cua-local status" "$STUB_LOG"'
@@ -536,8 +536,8 @@ check "the library and CLI are built and staged" \
check "cua-spacesd is built from this checkout's libs/cua-spacesd" \
'grep >/dev/null "^cargo build --locked --release -p cua-spacesd --bin cua-spacesd \[in cua-spacesd\]$" "$CARGO_LOG"'
check "(the checkout's and the pinned daemon of this fixture differ in code)" '[ "$(text_hash "$DAEMON_CHECKOUT")" != "$(text_hash "$DAEMON_PINNED")" ]'
-check "the bundled cua-spacesd is this checkout's build" '[ "$(text_hash "$LOCAL_APP/Contents/MacOS/cua-spacesd")" = "$(text_hash "$DAEMON_CHECKOUT")" ]'
-check "and not the pinned release" '[ "$(text_hash "$LOCAL_APP/Contents/MacOS/cua-spacesd")" != "$(text_hash "$DAEMON_PINNED")" ]'
+check "the bundled cua-spacesd is this checkout's build" '[ "$(text_hash "$LOCAL_APP/Contents/Helpers/cua-spacesd")" = "$(text_hash "$DAEMON_CHECKOUT")" ]'
+check "and not the pinned release" '[ "$(text_hash "$LOCAL_APP/Contents/Helpers/cua-spacesd")" != "$(text_hash "$DAEMON_PINNED")" ]'
ALL_BEFORE="$(snap_all)"
FAKE_BUILD_SALT=pinned FAKE_BUILD_IGNORE_SPACESD_BIN=1 install
@@ -560,7 +560,7 @@ install
: > "$CARGO_LOG"
FAKE_BUILD_SALT=skip install --skip-rust-build
check "--skip-rust-build uses the existing build: no cargo, the same daemon bundled (status $RC)" \
- '[ "$RC" = 0 ] && [ ! -s "$CARGO_LOG" ] && [ "$(cat "$LOCAL_APP/Contents/Resources/salt.txt")" = skip ] && [ "$(text_hash "$LOCAL_APP/Contents/MacOS/cua-spacesd")" = "$(text_hash "$DAEMON_CHECKOUT")" ]'
+ '[ "$RC" = 0 ] && [ ! -s "$CARGO_LOG" ] && [ "$(cat "$LOCAL_APP/Contents/Resources/salt.txt")" = skip ] && [ "$(text_hash "$LOCAL_APP/Contents/Helpers/cua-spacesd")" = "$(text_hash "$DAEMON_CHECKOUT")" ]'
reset_fixture
run env CARGO_TARGET_DIR=relative/target "$FAKE_SCRIPTS/install-local.sh" --no-launch
check "a relative CARGO_TARGET_DIR is refused (the daemon could not be found)" '[ "$RC" != 0 ] && printf "%s" "$OUT" | grep >/dev/null "CARGO_TARGET_DIR must be an absolute path"'
@@ -1038,7 +1038,7 @@ if [ -n "${CUA_TEST_SIGNING_KEYCHAIN:-}" ]; then
check "a rebuild keeps the same designated requirement, so TCC grants survive" '[ -n "$REQ1" ] && [ "$REQ1" = "$REQ2" ] && [ "$(cat "$SIGNED_APP/Contents/Resources/salt.txt")" = rebuilt ]'
check "a rebuild signed with the certificate resets no TCC rows" '! grep >/dev/null "^tccutil" "$SHIM_LOG"'
check "every nested piece is signed with the same certificate" \
- 'for f in Contents/MacOS/cua Contents/MacOS/cua-spacesd Contents/Frameworks/libfake.dylib Contents/Frameworks/Fake.framework; do /usr/bin/codesign -d -r- "$SIGNED_APP/$f" 2>&1 | grep >/dev/null "certificate leaf" || exit 1; done'
+ 'for f in Contents/MacOS/cua Contents/Helpers/cua-spacesd Contents/Frameworks/libfake.dylib Contents/Frameworks/Fake.framework; do /usr/bin/codesign -d -r- "$SIGNED_APP/$f" 2>&1 | grep >/dev/null "certificate leaf" || exit 1; done'
check "the fake HOME was not written" '[ "$(snap_all)" = "$ALL_BEFORE" ]'
else
fail "install with the signing keychain $CUA_TEST_SIGNING_KEYCHAIN failed (status $RC)"
diff --git a/libs/cua/crates/cua-host/src/driver.rs b/libs/cua/crates/cua-host/src/driver.rs
index 4273810d71..a2fb26ebcf 100644
--- a/libs/cua/crates/cua-host/src/driver.rs
+++ b/libs/cua/crates/cua-host/src/driver.rs
@@ -159,10 +159,11 @@ pub fn locate(explicit: Option<&Path>) -> Result<DriverSource> {
if let Ok(exe) = std::env::current_exe()
&& let Some(dir) = exe.parent()
{
- // Next to the CLI, or in a macOS bundle's Contents/MacOS or
- // Contents/Resources.
+ // Next to the CLI (also a Cua Spaces app before 0.15), or in a macOS
+ // bundle's Contents/Helpers (the app's own) or Contents/Resources.
for candidate in [
dir.join(binary_name()),
+ dir.join("../Helpers").join(binary_name()),
dir.join("../Resources").join(binary_name()),
] {
if candidate.is_file() {
diff --git a/libs/cua/crates/cua-host/src/service.rs b/libs/cua/crates/cua-host/src/service.rs
index 5d6d398edc..a2fd2a14ca 100644
--- a/libs/cua/crates/cua-host/src/service.rs
+++ b/libs/cua/crates/cua-host/src/service.rs
@@ -112,8 +112,13 @@ pub fn app_helper_name() -> &'static str {
CuaChannel::current().app_name()
}
/// The cua-spacesd the app ships, inside the app (the service runs only
-/// this one).
-pub const APP_HELPER_DAEMON: &str = "Contents/MacOS/cua-spacesd";
+/// this one). In `Contents/Helpers`, not `Contents/MacOS`: from there, AppKit
+/// (its cursor overlay) registered it with LaunchServices as the app itself,
+/// and opening the app activated the windowless daemon instead of launching
+/// it.
+pub const APP_HELPER_DAEMON: &str = "Contents/Helpers/cua-spacesd";
+/// Where apps before 0.15 kept it (they run it from there).
+pub const APP_HELPER_DAEMON_BEFORE_0_15: &str = "Contents/MacOS/cua-spacesd";
/// The `SMAppService.agent` plist of `channel`'s app, inside the app:
/// `Contents/Library/LaunchAgents/<helper label>.plist` (the label is
/// [`CuaChannel::helper_label`]; `build-app.sh` stamps it per channel).
@@ -1337,7 +1342,8 @@ pub fn app_helper_launcher(app: &Path) -> PathBuf {
/// of the other's helper.
pub fn has_app_helper(app: &Path, channel: CuaChannel) -> bool {
app.join(app_helper_plist(channel)).is_file()
- && app.join(APP_HELPER_DAEMON).is_file()
+ && (app.join(APP_HELPER_DAEMON).is_file()
+ || app.join(APP_HELPER_DAEMON_BEFORE_0_15).is_file())
&& app.join(APP_EXECUTABLE).is_file()
}
@@ -2063,8 +2069,13 @@ mod tests {
!has_app_helper(&app, stable),
"an app without its own cua-spacesd (0.9.4)"
);
+ std::fs::create_dir_all(app.join(APP_HELPER_DAEMON).parent().unwrap()).unwrap();
std::fs::write(app.join(APP_HELPER_DAEMON), "").unwrap();
assert!(has_app_helper(&app, stable));
+ // An app before 0.15 kept it in Contents/MacOS.
+ std::fs::remove_file(app.join(APP_HELPER_DAEMON)).unwrap();
+ std::fs::write(app.join(APP_HELPER_DAEMON_BEFORE_0_15), "").unwrap();
+ assert!(has_app_helper(&app, stable));
let launcher = app_helper_launcher(&app);
assert_eq!(launcher, app.join(APP_EXECUTABLE));
assert!(is_app_helper_launcher(&launcher));
@@ -2080,6 +2091,14 @@ mod tests {
);
}
+ #[test]
+ fn the_app_helper_daemon_is_outside_contents_macos() {
+ // Any executable in Contents/MacOS is the app to LaunchServices once
+ // it starts AppKit; the daemon there took over the app's launch.
+ assert!(APP_HELPER_DAEMON.starts_with("Contents/Helpers/"));
+ assert!(!APP_HELPER_DAEMON.starts_with("Contents/MacOS/"));
+ }
+
/// A Cua Spaces app of `channel` with the helper, in `parent`.
fn fake_app(parent: &Path, channel: CuaChannel) -> PathBuf {
let app = parent.join(format!("{}.app", channel.app_name()));