Files
Moltbot/apps/ios/Sources/Location/SignificantLocationMonitor.swift
Nimrod Gutman 5a39e13c92 fix(ios): restore missing location monitor merge files (#18260)
Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: f60cd10f6d0b089efc2f146c570efc4c8c250175
Co-authored-by: ngutman <1540134+ngutman@users.noreply.github.com>
Co-authored-by: ngutman <1540134+ngutman@users.noreply.github.com>
Reviewed-by: @ngutman
2026-02-17 01:41:53 +08:00

39 lines
1.4 KiB
Swift

import CoreLocation
import Foundation
import OpenClawKit
/// Monitors significant location changes and pushes `location.update`
/// events to the gateway so the severance hook can determine whether
/// the user is at their configured work location.
@MainActor
enum SignificantLocationMonitor {
static func startIfNeeded(
locationService: any LocationServicing,
locationMode: OpenClawLocationMode,
gateway: GatewayNodeSession
) {
guard locationMode == .always else { return }
let status = locationService.authorizationStatus()
guard status == .authorizedAlways else { return }
locationService.startMonitoringSignificantLocationChanges { location in
struct Payload: Codable {
var lat: Double
var lon: Double
var accuracyMeters: Double
var source: String?
}
let payload = Payload(
lat: location.coordinate.latitude,
lon: location.coordinate.longitude,
accuracyMeters: location.horizontalAccuracy,
source: "ios-significant-location")
guard let data = try? JSONEncoder().encode(payload),
let json = String(data: data, encoding: .utf8)
else { return }
Task { @MainActor in
await gateway.sendEvent(event: "location.update", payloadJSON: json)
}
}
}
}