Skip to content

Commit 43f76f3

Browse files
roboclaw-botVACInc
andauthored
fix: macOS app relaunches normally after installation (#134074)
* fix(macos): secure transient app relaunch Co-authored-by: Vito Cappello <[email protected]> * fix: macOS app relaunches normally after installation Worked on by: - @VACInc Co-authored-by: VACInc <[email protected]> OpenClaw-Publication: 4fd5c6fb-fdcf-4c07-a3cd-e2bf5bea447f * fix: macOS app relaunches normally after installation Worked on by: - @VACInc Co-authored-by: VACInc <[email protected]> OpenClaw-Publication: 4fd5c6fb-fdcf-4c07-a3cd-e2bf5bea447f * fix: macOS app relaunches normally after installation Worked on by: - @VACInc Co-authored-by: VACInc <[email protected]> OpenClaw-Publication: c566e93b-392d-4b0b-a6ff-fde7a2e25d2d * fix(macos): type quarantine errno Co-authored-by: VACInc <[email protected]> * fix: macOS app relaunches normally after installation Worked on by: - @VACInc Co-authored-by: VACInc <[email protected]> OpenClaw-Publication: a6ad7aa3-936c-4df4-8c39-9250381cc5cd * style(macos): satisfy Swift self formatting Co-authored-by: VACInc <[email protected]> * fix: macOS app relaunches normally after installation Worked on by: - @VACInc Co-authored-by: VACInc <[email protected]> OpenClaw-Publication: 69829d8f-9623-481c-843e-7f3474599809 * fix(macos): type quarantine xattr result Co-authored-by: VACInc <[email protected]> * fix: macOS app relaunches normally after installation Worked on by: - @VACInc Co-authored-by: VACInc <[email protected]> OpenClaw-Publication: 82d819ca-7ba8-4451-99e6-002e5ff00efe * test(macos): type quarantine xattr result Co-authored-by: VACInc <[email protected]> * fix: macOS app relaunches normally after installation Worked on by: - @VACInc Co-authored-by: VACInc <[email protected]> OpenClaw-Publication: 5c4146ef-04ca-4010-b05e-9bddcc558b2a * fix(macos): reuse localized relaunch recovery Co-authored-by: VACInc <[email protected]> * fix: macOS app relaunches normally after installation Worked on by: - @VACInc Co-authored-by: VACInc <[email protected]> OpenClaw-Publication: ec750425-0dd4-404c-823d-529244e31424 * fix(macos): bind quarantine release to verified app Co-authored-by: VACInc <[email protected]> * Publish openclaw/openclaw-issue-134034 Worked on by: - @VACInc Co-authored-by: VACInc <[email protected]> OpenClaw-Publication: 15cacc5f-1b75-4075-9c65-9db17b83f204 * fix(macos): assess relaunch with Gatekeeper Co-authored-by: VACInc <[email protected]> * Publish openclaw/openclaw-issue-134034 Worked on by: - @VACInc Co-authored-by: VACInc <[email protected]> OpenClaw-Publication: 62888804-db86-497f-b9bd-3f13e11ab292 * fix(macos): bound relocation relaunch attempts Worked on by: - @VACInc Co-authored-by: VACInc <[email protected]> --------- Co-authored-by: roboclaw-bot <[email protected]> Co-authored-by: Vito Cappello <[email protected]> Co-authored-by: VACInc <[email protected]>
1 parent c0f1cbf commit 43f76f3

2 files changed

Lines changed: 52 additions & 2 deletions

File tree

‎apps/macos/Sources/OpenClaw/ApplicationRelocator.swift‎

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ enum ApplicationRelocator {
183183
"OPENCLAW_REPLACEMENT_SUPERVISOR_LABEL"
184184
private nonisolated static let replacementSupervisorPlistEnvironmentKey =
185185
"OPENCLAW_REPLACEMENT_SUPERVISOR_PLIST"
186+
nonisolated static let relocationRelaunchArgument = "--openclaw-relocation-relaunch"
186187

187188
static func recommendation(for environment: Environment) -> Recommendation {
188189
guard !environment.isDebugOrTesting,
@@ -251,7 +252,16 @@ enum ApplicationRelocator {
251252
bundle: bundle,
252253
fileManager: fileManager,
253254
processInfo: processInfo)
254-
switch self.recommendation(for: environment) {
255+
let recommendation = self.recommendation(for: environment)
256+
if self.shouldStopRelocationRelaunch(
257+
recommendation: recommendation,
258+
arguments: processInfo.arguments)
259+
{
260+
self.showFailure(
261+
"OpenClaw is installed in Applications, but couldn’t reopen automatically. Open it there manually.")
262+
return .continueLaunch(startUpdater: false)
263+
}
264+
switch recommendation {
255265
case .continueLaunch:
256266
#if DEBUG
257267
let monitorDebugReplacement = processInfo.environment["OPENCLAW_MONITOR_APP_REPLACEMENT"] == "1"
@@ -293,6 +303,19 @@ enum ApplicationRelocator {
293303
}
294304
}
295305

306+
static func shouldStopRelocationRelaunch(
307+
recommendation: Recommendation,
308+
arguments: [String]) -> Bool
309+
{
310+
guard arguments.contains(self.relocationRelaunchArgument) else { return false }
311+
switch recommendation {
312+
case .handOff, .offerInstall:
313+
return true
314+
case .continueLaunch, .cannotInstall:
315+
return false
316+
}
317+
}
318+
296319
static func currentBundleAllowsPersistentIntegration(
297320
bundle: Bundle = .main,
298321
fileManager: FileManager = .default,
@@ -1006,10 +1029,12 @@ extension ApplicationRelocator {
10061029
let processInfo = ProcessInfo.processInfo
10071030
helper.arguments = [
10081031
"-c",
1009-
"while /bin/kill -0 \"$2\" 2>/dev/null; do /bin/sleep 0.1; done; exec /usr/bin/open -n \"$1\"",
1032+
"while /bin/kill -0 \"$2\" 2>/dev/null; do /bin/sleep 0.1; done; " +
1033+
"exec /usr/bin/open -n \"$1\" --args \"$3\"",
10101034
"openclaw-relocation",
10111035
destination.path,
10121036
String(processInfo.processIdentifier),
1037+
self.relocationRelaunchArgument,
10131038
]
10141039
do {
10151040
try helper.run()

‎apps/macos/Tests/OpenClawIPCTests/ApplicationRelocatorTests.swift‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,31 @@ struct ApplicationRelocatorTests {
9797
}
9898
}
9999

100+
@Test
101+
func `relaunch marker stops a repeated transient handoff`() {
102+
let destination = URL(fileURLWithPath: "/Applications/OpenClaw.app")
103+
let markedArguments = [
104+
"/private/var/folders/x/AppTranslocation/y/d/OpenClaw.app/Contents/MacOS/OpenClaw",
105+
ApplicationRelocator.relocationRelaunchArgument,
106+
]
107+
108+
let repeatedRecommendations: [ApplicationRelocator.Recommendation] = [
109+
.handOff(destination),
110+
.offerInstall(destination: destination, replacing: true),
111+
]
112+
for recommendation in repeatedRecommendations {
113+
#expect(ApplicationRelocator.shouldStopRelocationRelaunch(
114+
recommendation: recommendation,
115+
arguments: markedArguments))
116+
}
117+
#expect(!ApplicationRelocator.shouldStopRelocationRelaunch(
118+
recommendation: .continueLaunch,
119+
arguments: markedArguments))
120+
#expect(!ApplicationRelocator.shouldStopRelocationRelaunch(
121+
recommendation: .handOff(destination),
122+
arguments: []))
123+
}
124+
100125
@Test
101126
func `older installed build can be replaced`() {
102127
let destination = URL(fileURLWithPath: "/Applications/OpenClaw.app")

0 commit comments

Comments
 (0)