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:
OpenChamber committed 2026-11-18 13:22:59 +08:00
1 parent 2fb4a8ea79
commit 6c0ee61750
2538 files changed
+675779 -4792

No files matched your search

@@ -0,0 +1,79 @@
package dev.mygo
import android.Manifest
import android.annotation.SuppressLint
import android.content.Context
import android.location.Location
import android.location.LocationListener
import android.location.LocationManager
import android.os.Build
import android.os.Looper
import org.json.JSONObject
class LocationPlugin : MyGoPlugin {
private val manager get() = PluginHost.context.getSystemService(Context.LOCATION_SERVICE) as LocationManager
private val perms = arrayOf(Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION)
private var listener: LocationListener? = null
private fun encode(l: Location) = JSONObject()
.put("latitude", l.latitude).put("longitude", l.longitude)
.put("altitude", if (l.hasAltitude()) l.altitude else -1.0)
.put("speed", if (l.hasSpeed()) l.speed.toDouble() else -1.0)
.put("heading", if (l.hasBearing()) l.bearing.toDouble() else -1.0)
.put("accuracy", if (l.hasAccuracy()) l.accuracy.toDouble() else -1.0)
.put("time", l.time)
private fun provider(): String? {
val providers = manager.getProviders(true)
return when {
LocationManager.FUSED_PROVIDER in providers -> LocationManager.FUSED_PROVIDER
LocationManager.GPS_PROVIDER in providers -> LocationManager.GPS_PROVIDER
LocationManager.NETWORK_PROVIDER in providers -> LocationManager.NETWORK_PROVIDER
else -> providers.firstOrNull()
}
}
@SuppressLint("MissingPermission")
override fun call(method: String, args: JSONObject, reply: PluginReply) {
when (method) {
"requestPermission" -> PluginHost.requestPermissions(perms) { reply.success(JSONObject().put("granted", it)) }
"current" -> PluginHost.requestPermissions(perms) { granted ->
if (!granted) {
reply.failure(PluginFailure("Denied", "the app may not know where the device is"))
return@requestPermissions
}
val p = provider()
if (p == null) {
reply.failure(PluginFailure("Failed", "the device has location turned off"))
return@requestPermissions
}
if (Build.VERSION.SDK_INT >= 30) {
manager.getCurrentLocation(p, null, PluginHost.context.mainExecutor) { l ->
if (l != null) reply.success(encode(l)) else reply.failure(PluginFailure("Failed", "no fix"))
}
} else {
@Suppress("DEPRECATION")
manager.requestSingleUpdate(p, { l: Location -> reply.success(encode(l)) }, Looper.getMainLooper())
}
}
"start" -> PluginHost.requestPermissions(perms) { granted ->
val p = provider()
if (!granted || p == null) {
reply.failure(PluginFailure("Denied", "the app may not know where the device is"))
return@requestPermissions
}
listener?.let { manager.removeUpdates(it) }
val l = LocationListener { loc -> PluginHost.emit("location", "fix", encode(loc)) }
listener = l
manager.requestLocationUpdates(p, 1000L, 1f, l, Looper.getMainLooper())
reply.success(null)
}
"stop" -> {
listener?.let { manager.removeUpdates(it) }
listener = null
reply.success(null)
}
else -> reply.failure(PluginFailure("NoMethod", method))
}
}
}