mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
* macOS: honor Nix defaults suite; auto launch in Nix mode Fixes repeated onboarding in Nix deployments by detecting nixMode from the stable defaults suite (ai.openclaw.mac) and bridging key settings into the current defaults domain. Also enables LaunchAgent autostart by default in Nix mode (escape hatch: openclaw.nixAutoLaunchAtLogin=false). * macOS: keep Nix mode fix focused Drop the automatic launch-at-login behavior from the Nix defaults patch; keep this PR scoped to reliable nixMode detection + defaults bridging. * macOS: simplify nixMode fix Remove the defaults-bridging helper and rely on a single, stable defaults suite (ai.openclaw.mac) for nixMode detection when running as an app bundle. This keeps the fix focused on onboarding suppression and rename churn resilience. * macOS: fix nixMode defaults suite churn (#12205)
49 lines
2.0 KiB
Swift
49 lines
2.0 KiB
Swift
import Foundation
|
|
|
|
extension ProcessInfo {
|
|
var isPreview: Bool {
|
|
guard let raw = getenv("XCODE_RUNNING_FOR_PREVIEWS") else { return false }
|
|
return String(cString: raw) == "1"
|
|
}
|
|
|
|
/// Nix deployments may write defaults into a stable suite (`ai.openclaw.mac`) even if the shipped
|
|
/// app bundle identifier changes (and therefore `UserDefaults.standard` domain changes).
|
|
static func resolveNixMode(
|
|
environment: [String: String],
|
|
standard: UserDefaults,
|
|
stableSuite: UserDefaults?,
|
|
isAppBundle: Bool
|
|
) -> Bool {
|
|
if environment["OPENCLAW_NIX_MODE"] == "1" { return true }
|
|
if standard.bool(forKey: "openclaw.nixMode") { return true }
|
|
|
|
// Only consult the stable suite when running as a .app bundle.
|
|
// This avoids local developer machines accidentally influencing unit tests.
|
|
if isAppBundle, let stableSuite, stableSuite.bool(forKey: "openclaw.nixMode") { return true }
|
|
|
|
return false
|
|
}
|
|
|
|
var isNixMode: Bool {
|
|
let isAppBundle = Bundle.main.bundleURL.pathExtension == "app"
|
|
let stableSuite = UserDefaults(suiteName: launchdLabel)
|
|
return Self.resolveNixMode(
|
|
environment: self.environment,
|
|
standard: .standard,
|
|
stableSuite: stableSuite,
|
|
isAppBundle: isAppBundle)
|
|
}
|
|
|
|
var isRunningTests: Bool {
|
|
// SwiftPM tests load one or more `.xctest` bundles. With Swift Testing, `Bundle.main` is not
|
|
// guaranteed to be the `.xctest` bundle, so check all loaded bundles.
|
|
if Bundle.allBundles.contains(where: { $0.bundleURL.pathExtension == "xctest" }) { return true }
|
|
if Bundle.main.bundleURL.pathExtension == "xctest" { return true }
|
|
|
|
// Backwards-compatible fallbacks for runners that still set XCTest env vars.
|
|
return self.environment["XCTestConfigurationFilePath"] != nil
|
|
|| self.environment["XCTestBundlePath"] != nil
|
|
|| self.environment["XCTestSessionIdentifier"] != nil
|
|
}
|
|
}
|