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.
43 lines
2.1 KiB
Swift
43 lines
2.1 KiB
Swift
import CoreMotion
|
|
import Foundation
|
|
|
|
final class SensorsPlugin: MyGoPlugin {
|
|
private let motion = CMMotionManager()
|
|
private let queue = OperationQueue()
|
|
|
|
private func send(_ sensor: String, _ x: Double, _ y: Double, _ z: Double) {
|
|
PluginHost.emit("sensors", sensor, ["X": x, "Y": y, "Z": z, "T": Int64(Date().timeIntervalSince1970 * 1000)])
|
|
}
|
|
|
|
func call(_ method: String, _ args: [String: Any], _ reply: @escaping PluginReply) {
|
|
let sensor = args["sensor"] as? String ?? ""
|
|
let every = max(Double(args["intervalMs"] as? Int ?? 100), 10) / 1000
|
|
switch (method, sensor) {
|
|
case ("start", "accelerometer"):
|
|
guard motion.isAccelerometerAvailable else { return reply(.failure(PluginFailure("NoSensor"))) }
|
|
motion.accelerometerUpdateInterval = every
|
|
motion.startAccelerometerUpdates(to: queue) { [weak self] d, _ in
|
|
// Core Motion counts in gravities, against the screen's z.
|
|
if let a = d?.acceleration { self?.send(sensor, a.x * 9.81, a.y * 9.81, a.z * 9.81) }
|
|
}
|
|
case ("start", "gyroscope"):
|
|
guard motion.isGyroAvailable else { return reply(.failure(PluginFailure("NoSensor"))) }
|
|
motion.gyroUpdateInterval = every
|
|
motion.startGyroUpdates(to: queue) { [weak self] d, _ in
|
|
if let r = d?.rotationRate { self?.send(sensor, r.x, r.y, r.z) }
|
|
}
|
|
case ("start", "magnetometer"):
|
|
guard motion.isMagnetometerAvailable else { return reply(.failure(PluginFailure("NoSensor"))) }
|
|
motion.magnetometerUpdateInterval = every
|
|
motion.startMagnetometerUpdates(to: queue) { [weak self] d, _ in
|
|
if let m = d?.magneticField { self?.send(sensor, m.x, m.y, m.z) }
|
|
}
|
|
case ("stop", "accelerometer"): motion.stopAccelerometerUpdates()
|
|
case ("stop", "gyroscope"): motion.stopGyroUpdates()
|
|
case ("stop", "magnetometer"): motion.stopMagnetometerUpdates()
|
|
default: return reply(.failure(PluginFailure("NoMethod", method)))
|
|
}
|
|
reply(.success(nil))
|
|
}
|
|
}
|