feat: port the client to MyGo native UI (0.3.0)
Switch from Asuka to MyGo, keeping the API client and the feature set: - servers: saved servers, passwordless and password login, proxy, self-signed certificates, per-server device tokens (Keystore), connect form, instance list sheet with switch/disconnect - sessions: virtualized list, search, new session, rename/archive/delete, running indicator, event stream keeps it live - chat: pushed window with system back bar, streaming Markdown via ui/markdown, reasoning and tool rows with image previews, footer menu (read aloud via a Kotlin TTS plugin, copy, fork), user message menu (copy, revert, fork), context usage ring and detail sheet, attachments (photos/files via the document picker), permissions - release builds allow plain http:// LAN servers (Go's net/http dials directly, no cleartext manifest needed) - a local fork of MyGo (third_party/mygo) lowers the Android host's minSdk to 24 (Android 7.0); Go 1.27.4 via mise Version 0.3.0.
This commit is contained in:
1 parent
2fb4a8ea79
commit
6c0ee61750
2538 files changed
+675779
-4792
No files matched your search
@@ -0,0 +1,90 @@
|
||||
import CoreLocation
|
||||
import Foundation
|
||||
|
||||
final class LocationPlugin: NSObject, MyGoPlugin, CLLocationManagerDelegate {
|
||||
private let manager = CLLocationManager()
|
||||
private var waitingFix: [PluginReply] = []
|
||||
private var waitingAuth: [PluginReply] = []
|
||||
private var watching = false
|
||||
|
||||
override init() {
|
||||
super.init()
|
||||
manager.delegate = self
|
||||
manager.desiredAccuracy = kCLLocationAccuracyBest
|
||||
}
|
||||
|
||||
private var granted: Bool {
|
||||
let s = manager.authorizationStatus
|
||||
return s == .authorizedWhenInUse || s == .authorizedAlways
|
||||
}
|
||||
|
||||
func call(_ method: String, _ args: [String: Any], _ reply: @escaping PluginReply) {
|
||||
switch method {
|
||||
case "requestPermission":
|
||||
if manager.authorizationStatus == .notDetermined {
|
||||
waitingAuth.append(reply)
|
||||
manager.requestWhenInUseAuthorization()
|
||||
} else {
|
||||
reply(.success(["granted": granted]))
|
||||
}
|
||||
case "current":
|
||||
waitingFix.append(reply)
|
||||
if manager.authorizationStatus == .notDetermined {
|
||||
manager.requestWhenInUseAuthorization()
|
||||
} else if !granted {
|
||||
failFixes(PluginFailure("Denied", "the app may not know where the device is"))
|
||||
} else {
|
||||
manager.requestLocation()
|
||||
}
|
||||
case "start":
|
||||
watching = true
|
||||
if manager.authorizationStatus == .notDetermined { manager.requestWhenInUseAuthorization() }
|
||||
manager.startUpdatingLocation()
|
||||
reply(.success(nil))
|
||||
case "stop":
|
||||
watching = false
|
||||
manager.stopUpdatingLocation()
|
||||
reply(.success(nil))
|
||||
default:
|
||||
reply(.failure(PluginFailure("NoMethod", method)))
|
||||
}
|
||||
}
|
||||
|
||||
private func failFixes(_ f: PluginFailure) {
|
||||
let list = waitingFix
|
||||
waitingFix = []
|
||||
for r in list { r(.failure(f)) }
|
||||
}
|
||||
|
||||
func locationManagerDidChangeAuthorization(_ m: CLLocationManager) {
|
||||
guard m.authorizationStatus != .notDetermined else { return }
|
||||
let auth = waitingAuth
|
||||
waitingAuth = []
|
||||
for r in auth { r(.success(["granted": granted])) }
|
||||
if !waitingFix.isEmpty {
|
||||
if granted {
|
||||
m.requestLocation()
|
||||
} else {
|
||||
failFixes(PluginFailure("Denied", "the app may not know where the device is"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func encode(_ l: CLLocation) -> [String: Any] {
|
||||
["latitude": l.coordinate.latitude, "longitude": l.coordinate.longitude, "altitude": l.verticalAccuracy >= 0 ? l.altitude : -1,
|
||||
"speed": l.speed, "heading": l.course, "accuracy": l.horizontalAccuracy, "time": Int64(l.timestamp.timeIntervalSince1970 * 1000)]
|
||||
}
|
||||
|
||||
func locationManager(_ m: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
|
||||
guard let l = locations.last else { return }
|
||||
let fix = encode(l)
|
||||
let list = waitingFix
|
||||
waitingFix = []
|
||||
for r in list { r(.success(fix)) }
|
||||
if watching { PluginHost.emit("location", "fix", fix) }
|
||||
}
|
||||
|
||||
func locationManager(_ m: CLLocationManager, didFailWithError error: Error) {
|
||||
failFixes(PluginFailure("Failed", error.localizedDescription))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user