|
| 1 | +import CoreLocation |
| 2 | +import Foundation |
| 3 | +import OpenClawKit |
| 4 | + |
| 5 | +struct LocationPermissionSummary: Equatable { |
| 6 | + var desiredMode: OpenClawLocationMode |
| 7 | + var locationServicesEnabled: Bool |
| 8 | + var authorizationStatus: CLAuthorizationStatus |
| 9 | + var accuracyAuthorization: CLAccuracyAuthorization |
| 10 | + |
| 11 | + var effectiveMode: OpenClawLocationMode { |
| 12 | + guard self.desiredMode != .off else { return .off } |
| 13 | + guard self.locationServicesEnabled else { return .off } |
| 14 | + switch self.authorizationStatus { |
| 15 | + case .authorizedAlways: |
| 16 | + return self.desiredMode == .always ? .always : .whileUsing |
| 17 | + case .authorizedWhenInUse: |
| 18 | + return .whileUsing |
| 19 | + default: |
| 20 | + return .off |
| 21 | + } |
| 22 | + } |
| 23 | + |
| 24 | + var canUseLocationInBackground: Bool { |
| 25 | + self.locationServicesEnabled && self.desiredMode == .always && self.authorizationStatus == .authorizedAlways |
| 26 | + } |
| 27 | + |
| 28 | + var needsAttention: Bool { |
| 29 | + switch self.desiredMode { |
| 30 | + case .off: |
| 31 | + false |
| 32 | + case .whileUsing: |
| 33 | + !self.locationServicesEnabled || |
| 34 | + (self.authorizationStatus != .authorizedWhenInUse && self.authorizationStatus != .authorizedAlways) |
| 35 | + case .always: |
| 36 | + !self.locationServicesEnabled || self.authorizationStatus != .authorizedAlways |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + var statusText: String { |
| 41 | + switch self.effectiveMode { |
| 42 | + case .off: |
| 43 | + "Off" |
| 44 | + case .whileUsing: |
| 45 | + "While Using" |
| 46 | + case .always: |
| 47 | + "Always" |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + var detailText: String { |
| 52 | + switch ( |
| 53 | + self.desiredMode, |
| 54 | + self.locationServicesEnabled, |
| 55 | + self.authorizationStatus, |
| 56 | + self.accuracyAuthorization) |
| 57 | + { |
| 58 | + case (.off, false, _, _): |
| 59 | + "Location sharing is disabled in OpenClaw. Location Services are off in iOS Settings." |
| 60 | + case (.off, true, .authorizedAlways, _): |
| 61 | + "Location sharing is disabled in OpenClaw. iOS currently allows Always." |
| 62 | + case (.off, true, .authorizedWhenInUse, _): |
| 63 | + "Location sharing is disabled in OpenClaw. iOS currently allows While Using." |
| 64 | + case (.off, _, _, _): |
| 65 | + "Location sharing is disabled." |
| 66 | + case (_, false, _, _): |
| 67 | + "Location Services are off in iOS Settings." |
| 68 | + case (.whileUsing, true, .authorizedWhenInUse, .fullAccuracy): |
| 69 | + "Foreground location requests are allowed. Precise Location is on." |
| 70 | + case (.whileUsing, true, .authorizedAlways, .fullAccuracy): |
| 71 | + "Foreground location requests are allowed. Precise Location is on." |
| 72 | + case (.whileUsing, true, .authorizedWhenInUse, .reducedAccuracy): |
| 73 | + "Foreground location requests are allowed. Precise Location is off." |
| 74 | + case (.whileUsing, true, .authorizedAlways, .reducedAccuracy): |
| 75 | + "Foreground location requests are allowed. Precise Location is off." |
| 76 | + case (.whileUsing, true, .authorizedWhenInUse, _): |
| 77 | + "Foreground location requests are allowed." |
| 78 | + case (.whileUsing, true, .authorizedAlways, _): |
| 79 | + "Foreground location requests are allowed." |
| 80 | + case (.always, true, .authorizedAlways, .fullAccuracy): |
| 81 | + "Background location requests and significant-change updates are allowed. Precise Location is on." |
| 82 | + case (.always, true, .authorizedAlways, .reducedAccuracy): |
| 83 | + "Background location requests and significant-change updates are allowed. Precise Location is off." |
| 84 | + case (.always, true, .authorizedAlways, _): |
| 85 | + "Background location requests and significant-change updates are allowed." |
| 86 | + case (.always, true, .authorizedWhenInUse, .fullAccuracy): |
| 87 | + "Always is selected, but iOS currently allows location only while using the app. Precise Location is on." |
| 88 | + case (.always, true, .authorizedWhenInUse, .reducedAccuracy): |
| 89 | + "Always is selected, but iOS currently allows location only while using the app. Precise Location is off." |
| 90 | + case (.always, true, .authorizedWhenInUse, _): |
| 91 | + "Always is selected, but iOS currently allows location only while using the app." |
| 92 | + case (_, true, .denied, _): |
| 93 | + "Location permission is denied in iOS Settings." |
| 94 | + case (_, true, .restricted, _): |
| 95 | + "Location permission is restricted on this device." |
| 96 | + case (_, true, .notDetermined, _): |
| 97 | + "Choose a location mode to request iOS permission." |
| 98 | + @unknown default: |
| 99 | + "OpenClaw cannot determine the current iOS location permission." |
| 100 | + } |
| 101 | + } |
| 102 | +} |
0 commit comments