mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 17:31:06 +00:00
fix(macos): keep attach-only from stopping gateway launchd
This commit is contained in:
committed by
Peter Steinberger
parent
ffe67e9cdc
commit
25d2e9bdac
@@ -92,14 +92,6 @@ struct DebugSettings: View {
|
||||
self.launchAgentWriteDisabled = GatewayLaunchAgentManager.isLaunchAgentWriteDisabled()
|
||||
return
|
||||
}
|
||||
if newValue {
|
||||
Task {
|
||||
_ = await GatewayLaunchAgentManager.set(
|
||||
enabled: false,
|
||||
bundlePath: Bundle.main.bundlePath,
|
||||
port: GatewayEnvironment.gatewayPort())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Text(
|
||||
|
||||
@@ -5,7 +5,12 @@ enum GatewayLaunchAgentManager {
|
||||
private static let disableLaunchAgentMarker = ".openclaw/disable-launchagent"
|
||||
|
||||
private static var disableLaunchAgentMarkerURL: URL {
|
||||
FileManager().homeDirectoryForCurrentUser
|
||||
#if DEBUG
|
||||
if let testingDisableLaunchAgentMarkerURL {
|
||||
return testingDisableLaunchAgentMarkerURL
|
||||
}
|
||||
#endif
|
||||
return FileManager().homeDirectoryForCurrentUser
|
||||
.appendingPathComponent(self.disableLaunchAgentMarker)
|
||||
}
|
||||
|
||||
@@ -19,6 +24,10 @@ enum GatewayLaunchAgentManager {
|
||||
return false
|
||||
}
|
||||
|
||||
static func applyAttachOnlyRuntimeOverride() -> String? {
|
||||
self.setLaunchAgentWriteDisabled(true)
|
||||
}
|
||||
|
||||
static func setLaunchAgentWriteDisabled(_ disabled: Bool) -> String? {
|
||||
let marker = self.disableLaunchAgentMarkerURL
|
||||
if disabled {
|
||||
@@ -144,6 +153,15 @@ extension GatewayLaunchAgentManager {
|
||||
timeout: Double,
|
||||
quiet: Bool) async -> CommandResult
|
||||
{
|
||||
#if DEBUG
|
||||
if self.testingInterceptDaemonCommands {
|
||||
self.testingDaemonCommandCalls.append(args)
|
||||
return CommandResult(
|
||||
success: true,
|
||||
payload: Data("{\"ok\":true}".utf8),
|
||||
message: nil)
|
||||
}
|
||||
#endif
|
||||
let command = CommandResolver.openclawCommand(
|
||||
subcommand: "gateway",
|
||||
extraArgs: self.withJsonFlag(args),
|
||||
@@ -187,4 +205,26 @@ extension GatewayLaunchAgentManager {
|
||||
private static func summarize(_ text: String) -> String? {
|
||||
TextSummarySupport.summarizeLastLine(text)
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
nonisolated(unsafe) private static var testingDisableLaunchAgentMarkerURL: URL?
|
||||
nonisolated(unsafe) private static var testingInterceptDaemonCommands = false
|
||||
nonisolated(unsafe) private static var testingDaemonCommandCalls: [[String]] = []
|
||||
|
||||
static func setTestingDisableLaunchAgentMarkerURL(_ url: URL?) {
|
||||
self.testingDisableLaunchAgentMarkerURL = url
|
||||
}
|
||||
|
||||
static func setTestingInterceptDaemonCommands(_ intercept: Bool) {
|
||||
self.testingInterceptDaemonCommands = intercept
|
||||
}
|
||||
|
||||
static func clearTestingDaemonCommandCalls() {
|
||||
self.testingDaemonCommandCalls.removeAll(keepingCapacity: false)
|
||||
}
|
||||
|
||||
static func testingDaemonCommandCallsSnapshot() -> [[String]] {
|
||||
self.testingDaemonCommandCalls
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -98,16 +98,10 @@ struct OpenClawApp: App {
|
||||
private static func applyAttachOnlyOverrideIfNeeded() {
|
||||
let args = CommandLine.arguments
|
||||
guard args.contains("--attach-only") || args.contains("--no-launchd") else { return }
|
||||
if let error = GatewayLaunchAgentManager.setLaunchAgentWriteDisabled(true) {
|
||||
if let error = GatewayLaunchAgentManager.applyAttachOnlyRuntimeOverride() {
|
||||
Self.logger.error("attach-only flag failed: \(error, privacy: .public)")
|
||||
return
|
||||
}
|
||||
Task {
|
||||
_ = await GatewayLaunchAgentManager.set(
|
||||
enabled: false,
|
||||
bundlePath: Bundle.main.bundlePath,
|
||||
port: GatewayEnvironment.gatewayPort())
|
||||
}
|
||||
Self.logger.info("attach-only flag enabled")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user