fix(mac): harden relay spawn path and show status
This commit is contained in:
@@ -297,7 +297,8 @@ enum PermissionManager {
|
|||||||
let trusted = AXIsProcessTrusted()
|
let trusted = AXIsProcessTrusted()
|
||||||
results[cap] = trusted
|
results[cap] = trusted
|
||||||
if interactive, !trusted {
|
if interactive, !trusted {
|
||||||
_ = AXIsProcessTrustedWithOptions(nil)
|
let opts: NSDictionary = ["AXTrustedCheckOptionPrompt": true]
|
||||||
|
_ = AXIsProcessTrustedWithOptions(opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
case .screenRecording:
|
case .screenRecording:
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ final class RelayProcessManager: ObservableObject {
|
|||||||
let result = try await run(
|
let result = try await run(
|
||||||
.name(command.first ?? "clawdis"),
|
.name(command.first ?? "clawdis"),
|
||||||
arguments: Arguments(Array(command.dropFirst())),
|
arguments: Arguments(Array(command.dropFirst())),
|
||||||
environment: .inherit,
|
environment: self.makeEnvironment(),
|
||||||
workingDirectory: nil
|
workingDirectory: nil
|
||||||
) { execution, stdin, stdout, stderr in
|
) { execution, stdin, stdout, stderr in
|
||||||
self.didStart(execution)
|
self.didStart(execution)
|
||||||
@@ -145,8 +145,12 @@ final class RelayProcessManager: ObservableObject {
|
|||||||
|
|
||||||
private func handleError(_ error: any Error) async {
|
private func handleError(_ error: any Error) async {
|
||||||
self.execution = nil
|
self.execution = nil
|
||||||
self.appendLog("[relay] failed: \(error.localizedDescription)\n")
|
var message = error.localizedDescription
|
||||||
self.logger.error("relay failed: \(error.localizedDescription, privacy: .public)")
|
if let sp = error as? SubprocessError {
|
||||||
|
message = "SubprocessError \(sp.code.value): \(sp)"
|
||||||
|
}
|
||||||
|
self.appendLog("[relay] failed: \(message)\n")
|
||||||
|
self.logger.error("relay failed: \(message, privacy: .public)")
|
||||||
if self.desiredActive && !self.shouldGiveUpAfterCrashes() {
|
if self.desiredActive && !self.shouldGiveUpAfterCrashes() {
|
||||||
self.status = .restarting
|
self.status = .restarting
|
||||||
self.recentCrashes.append(Date())
|
self.recentCrashes.append(Date())
|
||||||
@@ -190,6 +194,26 @@ final class RelayProcessManager: ObservableObject {
|
|||||||
{
|
{
|
||||||
return override.split(separator: " ").map(String.init)
|
return override.split(separator: " ").map(String.init)
|
||||||
}
|
}
|
||||||
|
if let found = self.preferredPaths()
|
||||||
|
.lazy
|
||||||
|
.map({ ($0 as NSString).appendingPathComponent("clawdis") })
|
||||||
|
.first(where: { FileManager.default.isExecutableFile(atPath: $0) })
|
||||||
|
{
|
||||||
|
return [found, "relay"]
|
||||||
|
}
|
||||||
return ["clawdis", "relay"]
|
return ["clawdis", "relay"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func makeEnvironment() -> Environment {
|
||||||
|
let merged = self.preferredPaths().joined(separator: ":")
|
||||||
|
return .inherit.updating(["PATH": merged])
|
||||||
|
}
|
||||||
|
|
||||||
|
private func preferredPaths() -> [String] {
|
||||||
|
let current = ProcessInfo.processInfo.environment["PATH"]?
|
||||||
|
.split(separator: ":").map(String.init) ?? []
|
||||||
|
let extras = ["/opt/homebrew/bin", "/usr/local/bin", "/usr/bin", "/bin"]
|
||||||
|
var seen = Set<String>()
|
||||||
|
return (extras + current).filter { seen.insert($0).inserted }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user