@g9tm/app-diagnostic-tauri 0.0.0-stage → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.toml +18 -0
- package/README.md +21 -3
- package/android/build.gradle.kts +29 -0
- package/android/proguard-rules.pro +2 -0
- package/android/settings.gradle +2 -0
- package/android/src/main/AndroidManifest.xml +5 -0
- package/android/src/main/java/com/g9tm/appdiagnostic/G9AppDiagnosticHost.kt +131 -0
- package/android/src/main/java/com/g9tm/appdiagnostic/RemoteTouch.kt +67 -0
- package/android/src/main/java/com/g9tm/appdiagnostic/ScreenRecorder.kt +250 -0
- package/android/src/main/java/com/g9tm/appdiagnostic/TouchWatcher.kt +129 -0
- package/android/src/main/java/com/g9tm/appdiagnostic/VoiceRecorder.kt +82 -0
- package/android/src/main/java/com/g9tm/appdiagnostic/WindowCapture.kt +92 -0
- package/android/src/main/java/com/g9tm/appdiagnostic/core/TouchCore.kt +270 -0
- package/android/src/main/java/com/g9tm/appdiagnostic/tauri/G9DiagnosticPlugin.kt +180 -0
- package/build.rs +13 -0
- package/ios/Package.swift +20 -0
- package/ios/Sources/G9AppDiagnosticCore/G9AppDiagnosticHost.m +72 -0
- package/ios/Sources/G9AppDiagnosticCore/G9DiagnosticRecorders.m +514 -0
- package/ios/Sources/G9AppDiagnosticCore/include/G9AppDiagnosticHost.h +32 -0
- package/ios/Sources/G9AppDiagnosticCore/include/G9DiagnosticRecorders.h +36 -0
- package/ios/Sources/G9DiagnosticPlugin/G9DiagnosticPlugin.swift +135 -0
- package/package.json +43 -6
- package/permissions/autogenerated/commands/capabilities.toml +13 -0
- package/permissions/autogenerated/commands/read_chunk.toml +13 -0
- package/permissions/autogenerated/commands/registerListener.toml +13 -0
- package/permissions/autogenerated/commands/remove.toml +13 -0
- package/permissions/autogenerated/commands/remove_listener.toml +13 -0
- package/permissions/autogenerated/commands/screenshot.toml +13 -0
- package/permissions/autogenerated/commands/start_screen.toml +13 -0
- package/permissions/autogenerated/commands/start_voice.toml +13 -0
- package/permissions/autogenerated/commands/state.toml +13 -0
- package/permissions/autogenerated/commands/stop_screen.toml +13 -0
- package/permissions/autogenerated/commands/stop_voice.toml +13 -0
- package/permissions/autogenerated/commands/touch.toml +13 -0
- package/permissions/autogenerated/commands/watch_touches.toml +13 -0
- package/permissions/autogenerated/reference.md +367 -0
- package/permissions/default.toml +9 -0
- package/permissions/schemas/schema.json +462 -0
- package/src/index.ts +97 -0
- package/src/lib.rs +119 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
package com.g9tm.appdiagnostic
|
|
2
|
+
|
|
3
|
+
import android.content.pm.PackageManager
|
|
4
|
+
import android.media.MediaRecorder
|
|
5
|
+
import android.os.Build
|
|
6
|
+
import android.os.SystemClock
|
|
7
|
+
import java.io.File
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The tester's spoken note (G9AppDiagnostic.Maui AndroidVoiceRecorder): the microphone into AAC in an MP4 container (`.m4a`), mono,
|
|
11
|
+
* 44.1 kHz, 96 kbit/s — every player and the Diagnostic server's preview open it. 10 minutes at most (MediaRecorder's
|
|
12
|
+
* own max duration: the file is finalised and kept). The RECORD_AUDIO grant is asked by the module before [start] (the package's manifest declares it).
|
|
13
|
+
*
|
|
14
|
+
* TWIN: ios/src/G9AppDiagnosticMedia.m (AVAudioRecorder, the same format and cap).
|
|
15
|
+
*/
|
|
16
|
+
internal object VoiceRecorder {
|
|
17
|
+
private const val MAX_DURATION_MS = 10 * 60_000
|
|
18
|
+
|
|
19
|
+
class Result(val path: String, val bytes: Long, val durationMs: Long)
|
|
20
|
+
|
|
21
|
+
private val lock = Any()
|
|
22
|
+
private var recorder: MediaRecorder? = null
|
|
23
|
+
private var file: File? = null
|
|
24
|
+
private var startedAt = 0L
|
|
25
|
+
|
|
26
|
+
val isRecording: Boolean
|
|
27
|
+
get() = synchronized(lock) { recorder != null }
|
|
28
|
+
|
|
29
|
+
fun supported(): Boolean = G9AppDiagnosticHost.app.packageManager.hasSystemFeature(PackageManager.FEATURE_MICROPHONE)
|
|
30
|
+
|
|
31
|
+
fun start(dir: File) =
|
|
32
|
+
synchronized(lock) {
|
|
33
|
+
if (recorder != null) throw G9DiagnosticException("busy", "A voice note is already being recorded")
|
|
34
|
+
dir.mkdirs()
|
|
35
|
+
val target = File(dir, "voice-${System.currentTimeMillis()}.m4a")
|
|
36
|
+
@Suppress("DEPRECATION")
|
|
37
|
+
val r = if (Build.VERSION.SDK_INT >= 31) MediaRecorder(G9AppDiagnosticHost.app) else MediaRecorder()
|
|
38
|
+
try {
|
|
39
|
+
r.setAudioSource(MediaRecorder.AudioSource.MIC)
|
|
40
|
+
r.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4)
|
|
41
|
+
r.setAudioEncoder(MediaRecorder.AudioEncoder.AAC)
|
|
42
|
+
r.setAudioChannels(1)
|
|
43
|
+
r.setAudioSamplingRate(44_100)
|
|
44
|
+
r.setAudioEncodingBitRate(96_000)
|
|
45
|
+
r.setMaxDuration(MAX_DURATION_MS)
|
|
46
|
+
r.setOutputFile(target.path)
|
|
47
|
+
r.prepare()
|
|
48
|
+
r.start()
|
|
49
|
+
} catch (e: Exception) {
|
|
50
|
+
r.release()
|
|
51
|
+
target.delete()
|
|
52
|
+
throw G9DiagnosticException("unavailable", "The microphone could not start: ${e.message}", e)
|
|
53
|
+
}
|
|
54
|
+
recorder = r
|
|
55
|
+
file = target
|
|
56
|
+
startedAt = SystemClock.elapsedRealtime()
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Stops and hands over the note (null when nothing was recorded — a stop right after start). */
|
|
60
|
+
fun stop(): Result? =
|
|
61
|
+
synchronized(lock) {
|
|
62
|
+
val r = recorder ?: return null
|
|
63
|
+
val f = file
|
|
64
|
+
val duration = SystemClock.elapsedRealtime() - startedAt
|
|
65
|
+
recorder = null
|
|
66
|
+
file = null
|
|
67
|
+
val ok =
|
|
68
|
+
try {
|
|
69
|
+
r.stop()
|
|
70
|
+
true
|
|
71
|
+
} catch (_: RuntimeException) {
|
|
72
|
+
false // stop() throws when no audio was captured yet: the file is unusable
|
|
73
|
+
} finally {
|
|
74
|
+
r.release()
|
|
75
|
+
}
|
|
76
|
+
if (!ok || f == null || !f.isFile || f.length() == 0L) {
|
|
77
|
+
f?.delete()
|
|
78
|
+
return null
|
|
79
|
+
}
|
|
80
|
+
Result(f.path, f.length(), duration)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
package com.g9tm.appdiagnostic
|
|
2
|
+
|
|
3
|
+
import android.app.Activity
|
|
4
|
+
import android.graphics.Bitmap
|
|
5
|
+
import android.graphics.Canvas
|
|
6
|
+
import android.graphics.Color
|
|
7
|
+
import android.graphics.Rect
|
|
8
|
+
import android.os.Handler
|
|
9
|
+
import android.os.Looper
|
|
10
|
+
import android.view.PixelCopy
|
|
11
|
+
import android.view.SurfaceView
|
|
12
|
+
import android.view.View
|
|
13
|
+
import android.view.ViewGroup
|
|
14
|
+
import kotlin.coroutines.resume
|
|
15
|
+
import kotlinx.coroutines.Dispatchers
|
|
16
|
+
import kotlinx.coroutines.suspendCancellableCoroutine
|
|
17
|
+
import kotlinx.coroutines.withContext
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The app window as the user sees it, at any output size: the screenshot (G9AppDiagnosticModule.screenshot) and the tester screen
|
|
21
|
+
* recording (media/ScreenRecorder, 4 times a second) both read it here.
|
|
22
|
+
*
|
|
23
|
+
* PixelCopy(Window) reads the window's own surface, where a SurfaceView (a map, a video) is only a transparent hole:
|
|
24
|
+
* each visible SurfaceView is copied too and drawn UNDER the window, so the map shows through its hole and the chrome
|
|
25
|
+
* above it stays on top. PixelCopy scales into the destination bitmap, so a small output never allocates a full-size
|
|
26
|
+
* frame first (a recording at 960 px reads 960 px, not 2400).
|
|
27
|
+
*
|
|
28
|
+
* TWIN: ios/src/G9AppDiagnosticCapture.m (drawViewHierarchyInRect, which includes the Metal map layer).
|
|
29
|
+
*/
|
|
30
|
+
internal object WindowCapture {
|
|
31
|
+
/** The decor view's size in pixels, read on the main thread (0 × 0 before layout). */
|
|
32
|
+
suspend fun windowSize(activity: Activity): Pair<Int, Int> =
|
|
33
|
+
withContext(Dispatchers.Main) { activity.window.decorView.let { it.width to it.height } }
|
|
34
|
+
|
|
35
|
+
/** The window composited at [outWidth] × [outHeight] (the caller keeps the aspect ratio). */
|
|
36
|
+
suspend fun capture(activity: Activity, outWidth: Int, outHeight: Int): Bitmap {
|
|
37
|
+
val (width, height) = windowSize(activity)
|
|
38
|
+
if (width <= 0 || height <= 0) throw G9DiagnosticException("unavailable", "The window is not laid out")
|
|
39
|
+
val sx = outWidth.toFloat() / width
|
|
40
|
+
val sy = outHeight.toFloat() / height
|
|
41
|
+
val window = copyWindow(activity, outWidth, outHeight)
|
|
42
|
+
val surfaces = withContext(Dispatchers.Main) { surfaceViews(activity.window.decorView) }
|
|
43
|
+
if (surfaces.isEmpty()) return window
|
|
44
|
+
val frame = Bitmap.createBitmap(outWidth, outHeight, Bitmap.Config.ARGB_8888)
|
|
45
|
+
val canvas = Canvas(frame)
|
|
46
|
+
canvas.drawColor(Color.BLACK)
|
|
47
|
+
for ((view, x, y) in surfaces) {
|
|
48
|
+
val w = (view.width * sx).toInt().coerceAtLeast(1)
|
|
49
|
+
val h = (view.height * sy).toInt().coerceAtLeast(1)
|
|
50
|
+
val copy = copySurface(view, w, h) ?: continue
|
|
51
|
+
canvas.drawBitmap(copy, null, Rect((x * sx).toInt(), (y * sy).toInt(), (x * sx).toInt() + w, (y * sy).toInt() + h), null)
|
|
52
|
+
copy.recycle()
|
|
53
|
+
}
|
|
54
|
+
canvas.drawBitmap(window, 0f, 0f, null)
|
|
55
|
+
window.recycle()
|
|
56
|
+
return frame
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
private suspend fun copyWindow(activity: Activity, width: Int, height: Int): Bitmap =
|
|
60
|
+
suspendCancellableCoroutine { cont ->
|
|
61
|
+
val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
|
|
62
|
+
PixelCopy.request(activity.window, bitmap, { rc ->
|
|
63
|
+
if (rc == PixelCopy.SUCCESS) cont.resume(bitmap) else cont.cancel(G9DiagnosticException("io", "PixelCopy failed ($rc)"))
|
|
64
|
+
}, Handler(Looper.getMainLooper()))
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
private suspend fun copySurface(view: SurfaceView, width: Int, height: Int): Bitmap? =
|
|
68
|
+
suspendCancellableCoroutine { cont ->
|
|
69
|
+
val surface = view.holder.surface
|
|
70
|
+
if (!surface.isValid || view.width <= 0 || view.height <= 0) {
|
|
71
|
+
cont.resume(null)
|
|
72
|
+
return@suspendCancellableCoroutine
|
|
73
|
+
}
|
|
74
|
+
val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
|
|
75
|
+
PixelCopy.request(view, bitmap, { rc -> cont.resume(if (rc == PixelCopy.SUCCESS) bitmap else null) }, Handler(Looper.getMainLooper()))
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
private fun surfaceViews(root: View): List<Triple<SurfaceView, Int, Int>> {
|
|
79
|
+
val found = ArrayList<Triple<SurfaceView, Int, Int>>()
|
|
80
|
+
fun walk(v: View) {
|
|
81
|
+
if (v.visibility != View.VISIBLE) return
|
|
82
|
+
if (v is SurfaceView) {
|
|
83
|
+
val at = IntArray(2)
|
|
84
|
+
v.getLocationInWindow(at)
|
|
85
|
+
found += Triple(v, at[0], at[1])
|
|
86
|
+
}
|
|
87
|
+
if (v is ViewGroup) for (i in 0 until v.childCount) walk(v.getChildAt(i))
|
|
88
|
+
}
|
|
89
|
+
walk(root)
|
|
90
|
+
return found
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
package com.g9tm.appdiagnostic.core
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The tester gesture's decisions, free of Android types so the JVM suite drives them (../../jvm): the TWIN of
|
|
5
|
+
* G9AppDiagnostic.Maui TesterGestureService (OnTouch + InterceptDispatch, 2026-10-24) and of the Lynx app's own observer.
|
|
6
|
+
*
|
|
7
|
+
* OBSERVE. A completed multi-finger tap — all fingers down and up within [MAX_TAP_MS] (350 ms for two, 500 for three), no
|
|
8
|
+
* finger moved past the slop — is reported; JS pairs two of them into the gesture (@g9tm/app-diagnostic tester/gesture.ts).
|
|
9
|
+
* With [touches], every first finger down is reported too (a recording's timeline). A pinch or a pan moves, so it never
|
|
10
|
+
* counts.
|
|
11
|
+
*
|
|
12
|
+
* CONSUME (E-20). Observed only, the gesture's first finger also pressed whatever was under it (a button, a list row, a
|
|
13
|
+
* tree on the map), and the report began over a screen the gesture had just changed (QA, 2026-10-24). With [consume], a
|
|
14
|
+
* SECOND finger that lands within [SECOND_FINGER_WINDOW_MS] of the first, unmoved, makes the views get a CANCEL (a pressed
|
|
15
|
+
* button un-presses; a click is on UP) and the stream is HELD. Lifted as a tap: the views saw only a cancelled touch. Moved
|
|
16
|
+
* past the slop or held longer than a tap: a pinch or a pan — the held stream is REPLAYED (a fresh DOWN and POINTER_DOWNs
|
|
17
|
+
* where the fingers are now) and the rest flows through, so pinch-zoom still works, a slop late. A second finger that comes
|
|
18
|
+
* late passes untouched. Over an excluded surface (the map) nothing is held, in any mode: that surface stays native.
|
|
19
|
+
*
|
|
20
|
+
* EVERY FINGER AGAINST ITS OWN LANDING POINT (2026-11-15). A tap «moved» when any finger left ITS OWN landing point by
|
|
21
|
+
* more than the slop. Until then only `pointers[0]` was compared, with the FIRST finger's landing point: when the first
|
|
22
|
+
* finger lifted first, index 0 became the second finger — a finger's width away — and the next MOVE dropped the tap (a
|
|
23
|
+
* two-finger double tap failed about every other time on a DOOGEE). A tap reports the fingers' midpoint at the most
|
|
24
|
+
* fingers (`cx`, `cy`) beside the first finger (`x`, `y`): which finger lands first changes from tap to tap, the midpoint
|
|
25
|
+
* does not.
|
|
26
|
+
*
|
|
27
|
+
* THE TRACE. With [touches] on, every touch that could have been a tap (two fingers or more, or a short one-finger
|
|
28
|
+
* touch) ends with one `seq` report: its fingers, time, how far a finger moved, whether it was held and why it was or was
|
|
29
|
+
* not a tap — the field record of a gesture that «does not work».
|
|
30
|
+
*/
|
|
31
|
+
class TouchCore(private val slopPx: Float, private val clock: () -> Long) {
|
|
32
|
+
companion object {
|
|
33
|
+
const val DOWN = 0
|
|
34
|
+
const val UP = 1
|
|
35
|
+
const val MOVE = 2
|
|
36
|
+
const val CANCEL = 3
|
|
37
|
+
const val POINTER_DOWN = 5
|
|
38
|
+
const val POINTER_UP = 6
|
|
39
|
+
|
|
40
|
+
const val MAX_TAP_MS = 350L
|
|
41
|
+
const val MAX_THREE_FINGER_TAP_MS = 500L
|
|
42
|
+
const val SECOND_FINGER_WINDOW_MS = 250L
|
|
43
|
+
|
|
44
|
+
fun maxTapMsFor(fingers: Int): Long = if (fingers >= 3) MAX_THREE_FINGER_TAP_MS else MAX_TAP_MS
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** One pointer of an event, in window pixels. */
|
|
48
|
+
data class Pointer(val id: Int, val x: Float, val y: Float)
|
|
49
|
+
|
|
50
|
+
/** One event: its masked action (the MotionEvent constants) and every pointer down in it. */
|
|
51
|
+
data class Sample(val action: Int, val pointers: List<Pointer>)
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* What the watcher tells JS. [x], [y]: the first finger; [cx], [cy]: the fingers' midpoint at the most fingers (a tap);
|
|
55
|
+
* [info]: a `seq` report's fields.
|
|
56
|
+
*/
|
|
57
|
+
data class Emit(
|
|
58
|
+
val type: String,
|
|
59
|
+
val fingers: Int,
|
|
60
|
+
val x: Float,
|
|
61
|
+
val y: Float,
|
|
62
|
+
val excluded: Boolean,
|
|
63
|
+
val cx: Float = x,
|
|
64
|
+
val cy: Float = y,
|
|
65
|
+
val info: Map<String, Any>? = null,
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
enum class Verdict {
|
|
69
|
+
/** The views get the event as it is. */
|
|
70
|
+
PASS,
|
|
71
|
+
|
|
72
|
+
/** Held here: the views do not get it. */
|
|
73
|
+
CONSUME,
|
|
74
|
+
|
|
75
|
+
/** The views get a CANCEL of this event, then nothing (the hold begins). */
|
|
76
|
+
CANCEL_THEN_CONSUME,
|
|
77
|
+
|
|
78
|
+
/** The views get a fresh DOWN + POINTER_DOWNs at the fingers' current places, then this event (the hold ends). */
|
|
79
|
+
REPLAY,
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
data class Result(val verdict: Verdict, val emits: List<Emit>)
|
|
83
|
+
|
|
84
|
+
private enum class Phase { IDLE, HOLDING, RELEASED, PASSING }
|
|
85
|
+
|
|
86
|
+
@Volatile var taps = false
|
|
87
|
+
@Volatile var touches = false
|
|
88
|
+
@Volatile var consume = false
|
|
89
|
+
@Volatile var excludeSurfaces = false
|
|
90
|
+
|
|
91
|
+
/** Whether a window point is on a surface the host excludes (the map's view). Asked only on a first finger down. */
|
|
92
|
+
var isExcluded: (Float, Float) -> Boolean = { _, _ -> false }
|
|
93
|
+
|
|
94
|
+
private var downAt = 0L
|
|
95
|
+
private var maxPointers = 0
|
|
96
|
+
private var moved = false
|
|
97
|
+
private var downX = 0f
|
|
98
|
+
private var downY = 0f
|
|
99
|
+
private var downExcluded = false
|
|
100
|
+
|
|
101
|
+
// This touch's record: every finger's own landing point, the midpoint at the most fingers, and the trace's facts.
|
|
102
|
+
private val starts = HashMap<Int, Pair<Float, Float>>()
|
|
103
|
+
private var midX = 0f
|
|
104
|
+
private var midY = 0f
|
|
105
|
+
private var maxMovePx = 0f
|
|
106
|
+
private var secondAtMs = -1L
|
|
107
|
+
private var firstUpAtMs = -1L
|
|
108
|
+
private var firstOnlyMoved = false
|
|
109
|
+
private var everHeld = false
|
|
110
|
+
|
|
111
|
+
private var phase = Phase.IDLE
|
|
112
|
+
private val held = HashMap<Int, Pair<Float, Float>>()
|
|
113
|
+
|
|
114
|
+
val watching: Boolean
|
|
115
|
+
get() = taps || touches
|
|
116
|
+
|
|
117
|
+
/** Every event of the window, in order. Never throws. */
|
|
118
|
+
fun onEvent(s: Sample): Result {
|
|
119
|
+
if (!watching) {
|
|
120
|
+
phase = Phase.IDLE
|
|
121
|
+
return Result(Verdict.PASS, emptyList())
|
|
122
|
+
}
|
|
123
|
+
val emits = ArrayList<Emit>(1)
|
|
124
|
+
observe(s, emits)
|
|
125
|
+
val verdict = if (taps && consume) intercept(s) else Verdict.PASS
|
|
126
|
+
return Result(verdict, emits)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
private fun observe(s: Sample, emits: MutableList<Emit>) {
|
|
130
|
+
val first = s.pointers.firstOrNull()
|
|
131
|
+
when (s.action) {
|
|
132
|
+
DOWN -> {
|
|
133
|
+
downAt = clock()
|
|
134
|
+
maxPointers = 1
|
|
135
|
+
moved = false
|
|
136
|
+
downX = first?.x ?: 0f
|
|
137
|
+
downY = first?.y ?: 0f
|
|
138
|
+
downExcluded = runCatching { isExcluded(downX, downY) }.getOrDefault(false)
|
|
139
|
+
starts.clear()
|
|
140
|
+
for (p in s.pointers) starts[p.id] = p.x to p.y
|
|
141
|
+
midX = downX
|
|
142
|
+
midY = downY
|
|
143
|
+
maxMovePx = 0f
|
|
144
|
+
secondAtMs = -1L
|
|
145
|
+
firstUpAtMs = -1L
|
|
146
|
+
firstOnlyMoved = false
|
|
147
|
+
everHeld = false
|
|
148
|
+
if (touches) emits += Emit("down", 1, downX, downY, false)
|
|
149
|
+
}
|
|
150
|
+
POINTER_DOWN -> {
|
|
151
|
+
for (p in s.pointers) starts.putIfAbsent(p.id, p.x to p.y)
|
|
152
|
+
if (secondAtMs < 0 && s.pointers.size >= 2) secondAtMs = clock() - downAt
|
|
153
|
+
if (s.pointers.size > maxPointers) {
|
|
154
|
+
maxPointers = s.pointers.size
|
|
155
|
+
midX = s.pointers.map { it.x }.average().toFloat()
|
|
156
|
+
midY = s.pointers.map { it.y }.average().toFloat()
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
MOVE -> {
|
|
160
|
+
for (p in s.pointers) {
|
|
161
|
+
val start = starts[p.id] ?: continue
|
|
162
|
+
val d = maxOf(Math.abs(p.x - start.first), Math.abs(p.y - start.second))
|
|
163
|
+
if (d > maxMovePx) maxMovePx = d
|
|
164
|
+
if (d > slopPx) moved = true
|
|
165
|
+
}
|
|
166
|
+
// The rule before 2026-11-15 (index 0 against the first finger's landing point), kept for the trace only.
|
|
167
|
+
if (!firstOnlyMoved && first != null && (Math.abs(first.x - downX) > slopPx || Math.abs(first.y - downY) > slopPx)) firstOnlyMoved = true
|
|
168
|
+
}
|
|
169
|
+
POINTER_UP -> if (firstUpAtMs < 0) firstUpAtMs = clock() - downAt
|
|
170
|
+
UP -> {
|
|
171
|
+
val ms = clock() - downAt
|
|
172
|
+
val tap = taps && !moved && maxPointers >= 2 && ms <= maxTapMsFor(maxPointers)
|
|
173
|
+
if (tap) emits += Emit("tap", maxPointers, downX, downY, downExcluded, midX, midY)
|
|
174
|
+
if (touches) trace(emits, ms, tap, cancelled = false)
|
|
175
|
+
maxPointers = 0
|
|
176
|
+
}
|
|
177
|
+
CANCEL -> {
|
|
178
|
+
if (touches) trace(emits, clock() - downAt, tap = false, cancelled = true)
|
|
179
|
+
maxPointers = 0
|
|
180
|
+
moved = true
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** The `seq` report of a touch that could have been a tap (two fingers or more, or a short one-finger touch). */
|
|
186
|
+
private fun trace(emits: MutableList<Emit>, ms: Long, tap: Boolean, cancelled: Boolean) {
|
|
187
|
+
if (maxPointers < 2 && (ms > 600 || moved)) return
|
|
188
|
+
val why =
|
|
189
|
+
when {
|
|
190
|
+
tap -> "tap"
|
|
191
|
+
cancelled -> "cancelled"
|
|
192
|
+
maxPointers < 2 -> "one-finger"
|
|
193
|
+
moved -> "moved"
|
|
194
|
+
ms > maxTapMsFor(maxPointers) -> "too-long"
|
|
195
|
+
!taps -> "not-watching"
|
|
196
|
+
else -> "other"
|
|
197
|
+
}
|
|
198
|
+
val info =
|
|
199
|
+
mapOf(
|
|
200
|
+
"ms" to ms,
|
|
201
|
+
"secondMs" to secondAtMs,
|
|
202
|
+
"firstUpMs" to firstUpAtMs,
|
|
203
|
+
"movePx" to Math.round(maxMovePx),
|
|
204
|
+
"slopPx" to Math.round(slopPx),
|
|
205
|
+
"held" to everHeld,
|
|
206
|
+
"oldRuleMoved" to firstOnlyMoved,
|
|
207
|
+
"why" to why,
|
|
208
|
+
)
|
|
209
|
+
emits += Emit("seq", maxPointers, downX, downY, downExcluded, midX, midY, info)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
private fun intercept(s: Sample): Verdict =
|
|
213
|
+
when (s.action) {
|
|
214
|
+
DOWN -> {
|
|
215
|
+
phase = Phase.IDLE
|
|
216
|
+
held.clear()
|
|
217
|
+
Verdict.PASS
|
|
218
|
+
}
|
|
219
|
+
POINTER_DOWN ->
|
|
220
|
+
when {
|
|
221
|
+
phase == Phase.HOLDING -> {
|
|
222
|
+
remember(s)
|
|
223
|
+
Verdict.CONSUME
|
|
224
|
+
}
|
|
225
|
+
phase != Phase.IDLE -> Verdict.PASS
|
|
226
|
+
// Never over an excluded surface, in ANY mode (two tester reports — «two-finger zoom
|
|
227
|
+
// comes and goes» with tester mode on): a held pinch reached the map only as a REPLAY — late (110–360 ms), its
|
|
228
|
+
// first moves swallowed — and when the hold ran to its 350 ms limit MapLibre never began the scale (device trace,
|
|
229
|
+
// 2026-11-13). Over the map the gesture is only OBSERVED: the two-finger double tap still opens the tester (in
|
|
230
|
+
// the modes that count it there); the map also takes it as its own two-finger tap.
|
|
231
|
+
s.pointers.size == 2 && !moved && clock() - downAt <= SECOND_FINGER_WINDOW_MS && !downExcluded -> {
|
|
232
|
+
remember(s)
|
|
233
|
+
phase = Phase.HOLDING
|
|
234
|
+
everHeld = true
|
|
235
|
+
Verdict.CANCEL_THEN_CONSUME
|
|
236
|
+
}
|
|
237
|
+
else -> {
|
|
238
|
+
phase = Phase.PASSING
|
|
239
|
+
Verdict.PASS
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
MOVE ->
|
|
243
|
+
if (phase != Phase.HOLDING) {
|
|
244
|
+
Verdict.PASS
|
|
245
|
+
} else if (anyMoved(s) || clock() - downAt > maxTapMsFor(s.pointers.size)) {
|
|
246
|
+
phase = Phase.RELEASED
|
|
247
|
+
Verdict.REPLAY
|
|
248
|
+
} else {
|
|
249
|
+
Verdict.CONSUME
|
|
250
|
+
}
|
|
251
|
+
POINTER_UP -> if (phase == Phase.HOLDING) Verdict.CONSUME else Verdict.PASS
|
|
252
|
+
UP, CANCEL -> {
|
|
253
|
+
val wasHeld = phase == Phase.HOLDING
|
|
254
|
+
phase = Phase.IDLE
|
|
255
|
+
held.clear()
|
|
256
|
+
if (wasHeld) Verdict.CONSUME else Verdict.PASS
|
|
257
|
+
}
|
|
258
|
+
else -> if (phase == Phase.HOLDING) Verdict.CONSUME else Verdict.PASS
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
private fun remember(s: Sample) {
|
|
262
|
+
for (p in s.pointers) held.putIfAbsent(p.id, p.x to p.y)
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
private fun anyMoved(s: Sample): Boolean =
|
|
266
|
+
s.pointers.any { p ->
|
|
267
|
+
val start = held[p.id] ?: return@any false
|
|
268
|
+
Math.abs(p.x - start.first) > slopPx || Math.abs(p.y - start.second) > slopPx
|
|
269
|
+
}
|
|
270
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
package com.g9tm.appdiagnostic.tauri
|
|
2
|
+
|
|
3
|
+
import android.Manifest
|
|
4
|
+
import android.app.Activity
|
|
5
|
+
import android.graphics.Bitmap
|
|
6
|
+
import android.util.Base64
|
|
7
|
+
import android.webkit.WebView
|
|
8
|
+
import app.tauri.PermissionState
|
|
9
|
+
import app.tauri.annotation.Command
|
|
10
|
+
import app.tauri.annotation.InvokeArg
|
|
11
|
+
import app.tauri.annotation.Permission
|
|
12
|
+
import app.tauri.annotation.PermissionCallback
|
|
13
|
+
import app.tauri.annotation.TauriPlugin
|
|
14
|
+
import app.tauri.plugin.Invoke
|
|
15
|
+
import app.tauri.plugin.JSObject
|
|
16
|
+
import app.tauri.plugin.Plugin
|
|
17
|
+
import com.g9tm.appdiagnostic.G9AppDiagnosticHost
|
|
18
|
+
import com.g9tm.appdiagnostic.G9DiagnosticException
|
|
19
|
+
import com.g9tm.appdiagnostic.RemoteTouch
|
|
20
|
+
import com.g9tm.appdiagnostic.ScreenRecorder
|
|
21
|
+
import com.g9tm.appdiagnostic.TouchWatcher
|
|
22
|
+
import com.g9tm.appdiagnostic.VoiceRecorder
|
|
23
|
+
import com.g9tm.appdiagnostic.WindowCapture
|
|
24
|
+
import java.io.File
|
|
25
|
+
import java.io.FileOutputStream
|
|
26
|
+
import java.io.RandomAccessFile
|
|
27
|
+
import kotlinx.coroutines.CoroutineScope
|
|
28
|
+
import kotlinx.coroutines.Dispatchers
|
|
29
|
+
import kotlinx.coroutines.SupervisorJob
|
|
30
|
+
import kotlinx.coroutines.launch
|
|
31
|
+
|
|
32
|
+
@InvokeArg class ScreenArgs { var maxFps: Int = 10 }
|
|
33
|
+
|
|
34
|
+
@InvokeArg class ShotArgs {
|
|
35
|
+
var maxEdge: Int = 1600
|
|
36
|
+
var quality: Int = 80
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@InvokeArg class WatchArgs {
|
|
40
|
+
var taps: Boolean = false
|
|
41
|
+
var touches: Boolean = false
|
|
42
|
+
var consume: Boolean = false
|
|
43
|
+
var excludeSurfaces: Boolean = false
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@InvokeArg class TouchArgs {
|
|
47
|
+
var kind: String = "tap"
|
|
48
|
+
var x: Double = 0.0
|
|
49
|
+
var y: Double = 0.0
|
|
50
|
+
var toX: Double? = null
|
|
51
|
+
var toY: Double? = null
|
|
52
|
+
var durationMs: Double = 50.0
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@InvokeArg class ChunkArgs {
|
|
56
|
+
var path: String = ""
|
|
57
|
+
var offset: Double = 0.0
|
|
58
|
+
var length: Int = 0
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@InvokeArg class PathArgs { var path: String = "" }
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* G9AppDiagnostic for a Tauri v2 app on Android (0.5.0): the SAME recorders, window capture, gesture and remote touch as
|
|
65
|
+
* @g9tm/app-diagnostic-lynx (copied by scripts/sync-native.mjs — never edited here), behind Tauri's mobile bridge. Files
|
|
66
|
+
* go to the app's cache (g9diag-native/); the JS side moves them into the WebView's files with read_chunk.
|
|
67
|
+
*/
|
|
68
|
+
@TauriPlugin(permissions = [Permission(strings = [Manifest.permission.RECORD_AUDIO], alias = "microphone")])
|
|
69
|
+
class G9DiagnosticPlugin(private val activity: Activity) : Plugin(activity) {
|
|
70
|
+
private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
|
|
71
|
+
private val folder by lazy { File(activity.cacheDir, "g9diag-native").apply { mkdirs() } }
|
|
72
|
+
|
|
73
|
+
override fun load(webView: WebView) {
|
|
74
|
+
G9AppDiagnosticHost.attach(activity.application, activity)
|
|
75
|
+
G9AppDiagnosticHost.addSink { _, json -> trigger("touch", JSObject().put("json", json)) }
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
private fun run(invoke: Invoke, work: suspend () -> JSObject?) {
|
|
79
|
+
scope.launch {
|
|
80
|
+
try {
|
|
81
|
+
invoke.resolve(work() ?: JSObject())
|
|
82
|
+
} catch (e: G9DiagnosticException) {
|
|
83
|
+
invoke.reject(e.message ?: e.code, e.code)
|
|
84
|
+
} catch (e: Throwable) {
|
|
85
|
+
invoke.reject(e.message ?: e.javaClass.simpleName, "io")
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
@Command fun capabilities(invoke: Invoke) = run(invoke) {
|
|
91
|
+
JSObject().put("version", "0.5.0").put("platform", "android").put("screen", ScreenRecorder.supported()).put("voice", VoiceRecorder.supported()).put("consume", true).put("native", true)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
@Command fun state(invoke: Invoke) = run(invoke) { JSObject().put("screen", ScreenRecorder.isRecording).put("voice", VoiceRecorder.isRecording) }
|
|
95
|
+
|
|
96
|
+
@Command fun startScreen(invoke: Invoke) {
|
|
97
|
+
val a = invoke.parseArgs(ScreenArgs::class.java)
|
|
98
|
+
run(invoke) { ScreenRecorder.start(folder, a.maxFps); null }
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
@Command fun stopScreen(invoke: Invoke) = run(invoke) {
|
|
102
|
+
val r = ScreenRecorder.stop()
|
|
103
|
+
JSObject().put("recording", r?.let { JSObject().put("path", it.path).put("bytes", it.bytes).put("durationMs", it.durationMs).put("width", it.width).put("height", it.height).put("capped", it.capped) })
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
@Command fun startVoice(invoke: Invoke) {
|
|
107
|
+
if (getPermissionState("microphone") != PermissionState.GRANTED) {
|
|
108
|
+
requestPermissionForAlias("microphone", invoke, "microphoneAnswered")
|
|
109
|
+
return
|
|
110
|
+
}
|
|
111
|
+
run(invoke) { VoiceRecorder.start(folder); null }
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
@PermissionCallback
|
|
115
|
+
private fun microphoneAnswered(invoke: Invoke) {
|
|
116
|
+
if (getPermissionState("microphone") != PermissionState.GRANTED) invoke.reject("The microphone permission was refused", "permission")
|
|
117
|
+
else run(invoke) { VoiceRecorder.start(folder); null }
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
@Command fun stopVoice(invoke: Invoke) = run(invoke) {
|
|
121
|
+
val r = VoiceRecorder.stop()
|
|
122
|
+
JSObject().put("recording", r?.let { JSObject().put("path", it.path).put("bytes", it.bytes).put("durationMs", it.durationMs) })
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
@Command fun screenshot(invoke: Invoke) {
|
|
126
|
+
val a = invoke.parseArgs(ShotArgs::class.java)
|
|
127
|
+
run(invoke) {
|
|
128
|
+
val act = G9AppDiagnosticHost.awaitActivity()
|
|
129
|
+
val (width, height) = WindowCapture.windowSize(act)
|
|
130
|
+
if (width <= 0 || height <= 0) throw G9DiagnosticException("unavailable", "The window is not laid out")
|
|
131
|
+
val scale = minOf(1.0, a.maxEdge.coerceIn(64, 4096).toDouble() / maxOf(width, height))
|
|
132
|
+
val out = WindowCapture.capture(act, (width * scale).toInt().coerceAtLeast(1), (height * scale).toInt().coerceAtLeast(1))
|
|
133
|
+
val file = File(folder, "shot-${System.currentTimeMillis()}.jpg")
|
|
134
|
+
FileOutputStream(file).use { out.compress(Bitmap.CompressFormat.JPEG, a.quality.coerceIn(10, 100), it) }
|
|
135
|
+
val r = JSObject().put("path", file.path).put("width", out.width).put("height", out.height).put("bytes", file.length())
|
|
136
|
+
out.recycle()
|
|
137
|
+
r
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
@Command fun watchTouches(invoke: Invoke) {
|
|
142
|
+
val a = invoke.parseArgs(WatchArgs::class.java)
|
|
143
|
+
run(invoke) {
|
|
144
|
+
G9AppDiagnosticHost.onMain { TouchWatcher.configure(G9AppDiagnosticHost.activityNow(), a.taps, a.touches, a.consume, a.excludeSurfaces) }
|
|
145
|
+
null
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
@Command fun touch(invoke: Invoke) {
|
|
150
|
+
val a = invoke.parseArgs(TouchArgs::class.java)
|
|
151
|
+
run(invoke) { JSObject().put("handled", RemoteTouch.perform(a.kind, a.x, a.y, a.toX ?: a.x, a.toY ?: a.y, a.durationMs.toLong())) }
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
@Command fun readChunk(invoke: Invoke) {
|
|
155
|
+
val a = invoke.parseArgs(ChunkArgs::class.java)
|
|
156
|
+
run(invoke) {
|
|
157
|
+
val file = own(a.path)
|
|
158
|
+
val offset = a.offset.toLong().coerceAtLeast(0)
|
|
159
|
+
val data = RandomAccessFile(file, "r").use { f ->
|
|
160
|
+
if (offset >= f.length()) ByteArray(0) else {
|
|
161
|
+
f.seek(offset)
|
|
162
|
+
ByteArray(minOf(a.length.coerceIn(0, 4 * 1024 * 1024).toLong(), f.length() - offset).toInt()).also { f.readFully(it) }
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
JSObject().put("data", Base64.encodeToString(data, Base64.NO_WRAP))
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
@Command fun remove(invoke: Invoke) {
|
|
170
|
+
val a = invoke.parseArgs(PathArgs::class.java)
|
|
171
|
+
run(invoke) { own(a.path).delete(); null }
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
private fun own(path: String): File {
|
|
175
|
+
val f = File(path).canonicalFile
|
|
176
|
+
if (!f.path.startsWith(folder.canonicalPath + File.separator)) throw G9DiagnosticException("invalid", "Not a file of this plugin: $path")
|
|
177
|
+
if (!f.isFile) throw G9DiagnosticException("not-found", "No such file: $path")
|
|
178
|
+
return f
|
|
179
|
+
}
|
|
180
|
+
}
|
package/build.rs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// The plugin's commands (each a permission `g9-diagnostic:allow-<command>`, the set `g9-diagnostic:default`) and its mobile
|
|
2
|
+
// halves: android/ (Kotlin, the Lynx package's recorders copied by scripts/sync-native.mjs) and ios/ (Swift + the Lynx
|
|
3
|
+
// package's Objective-C recorders).
|
|
4
|
+
const COMMANDS: &[&str] = &[
|
|
5
|
+
"capabilities", "state", "start_screen", "stop_screen", "start_voice", "stop_voice", "screenshot", "watch_touches", "touch", "read_chunk", "remove",
|
|
6
|
+
// The mobile halves' event channel: @tauri-apps/api's addPluginListener sends these two to the plugin, and the ACL refuses
|
|
7
|
+
// them unless they are permissions too (found on a real phone: without them no touch ever reached the web layer).
|
|
8
|
+
"registerListener", "remove_listener",
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
fn main() {
|
|
12
|
+
tauri_plugin::Builder::new(COMMANDS).android_path("android").ios_path("ios").build();
|
|
13
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// swift-tools-version:5.3
|
|
2
|
+
// tauri-plugin-g9-diagnostic for iOS: the plugin (Swift) over @g9tm/app-diagnostic-lynx's Objective-C recorders
|
|
3
|
+
// (Sources/G9AppDiagnosticCore, copied by scripts/sync-native.mjs — never edited here).
|
|
4
|
+
import PackageDescription
|
|
5
|
+
|
|
6
|
+
let package = Package(
|
|
7
|
+
name: "tauri-plugin-g9-diagnostic",
|
|
8
|
+
platforms: [.iOS(.v14)],
|
|
9
|
+
products: [
|
|
10
|
+
.library(name: "tauri-plugin-g9-diagnostic", type: .static, targets: ["tauri-plugin-g9-diagnostic"]),
|
|
11
|
+
],
|
|
12
|
+
dependencies: [
|
|
13
|
+
.package(name: "Tauri", path: "../.tauri/tauri-api"),
|
|
14
|
+
],
|
|
15
|
+
targets: [
|
|
16
|
+
.target(name: "G9AppDiagnosticCore", path: "Sources/G9AppDiagnosticCore", publicHeadersPath: "include",
|
|
17
|
+
linkerSettings: [.linkedFramework("AVFoundation"), .linkedFramework("CoreVideo"), .linkedFramework("CoreMedia"), .linkedFramework("UIKit")]),
|
|
18
|
+
.target(name: "tauri-plugin-g9-diagnostic", dependencies: [.byName(name: "Tauri"), "G9AppDiagnosticCore"], path: "Sources/G9DiagnosticPlugin"),
|
|
19
|
+
]
|
|
20
|
+
)
|