@g9tm/app-diagnostic-lynx 0.0.0-stage → 0.2.1
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/Native-Validation-Pending.md +33 -0
- package/README.md +42 -3
- package/android/build.gradle.kts +45 -0
- package/android/consumer-rules.pro +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/G9AppDiagnosticModule.kt +224 -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 +126 -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 +175 -0
- package/android/src/main/java/com/g9tm/appdiagnostic/generated/G9AppDiagnosticModuleSpec.java +45 -0
- package/generated/G9AppDiagnosticModule.ts +70 -0
- package/lynx.lib.json +12 -0
- package/package.json +39 -6
- package/src/index.ts +157 -0
- package/types/g9-app-diagnostic-module.d.ts +57 -0
|
@@ -0,0 +1,175 @@
|
|
|
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, in its mode) nothing is held: that surface stays native.
|
|
19
|
+
*/
|
|
20
|
+
class TouchCore(private val slopPx: Float, private val clock: () -> Long) {
|
|
21
|
+
companion object {
|
|
22
|
+
const val DOWN = 0
|
|
23
|
+
const val UP = 1
|
|
24
|
+
const val MOVE = 2
|
|
25
|
+
const val CANCEL = 3
|
|
26
|
+
const val POINTER_DOWN = 5
|
|
27
|
+
const val POINTER_UP = 6
|
|
28
|
+
|
|
29
|
+
const val MAX_TAP_MS = 350L
|
|
30
|
+
const val MAX_THREE_FINGER_TAP_MS = 500L
|
|
31
|
+
const val SECOND_FINGER_WINDOW_MS = 250L
|
|
32
|
+
|
|
33
|
+
fun maxTapMsFor(fingers: Int): Long = if (fingers >= 3) MAX_THREE_FINGER_TAP_MS else MAX_TAP_MS
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** One pointer of an event, in window pixels. */
|
|
37
|
+
data class Pointer(val id: Int, val x: Float, val y: Float)
|
|
38
|
+
|
|
39
|
+
/** One event: its masked action (the MotionEvent constants) and every pointer down in it. */
|
|
40
|
+
data class Sample(val action: Int, val pointers: List<Pointer>)
|
|
41
|
+
|
|
42
|
+
/** What the watcher tells JS. */
|
|
43
|
+
data class Emit(val type: String, val fingers: Int, val x: Float, val y: Float, val excluded: Boolean)
|
|
44
|
+
|
|
45
|
+
enum class Verdict {
|
|
46
|
+
/** The views get the event as it is. */
|
|
47
|
+
PASS,
|
|
48
|
+
|
|
49
|
+
/** Held here: the views do not get it. */
|
|
50
|
+
CONSUME,
|
|
51
|
+
|
|
52
|
+
/** The views get a CANCEL of this event, then nothing (the hold begins). */
|
|
53
|
+
CANCEL_THEN_CONSUME,
|
|
54
|
+
|
|
55
|
+
/** The views get a fresh DOWN + POINTER_DOWNs at the fingers' current places, then this event (the hold ends). */
|
|
56
|
+
REPLAY,
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
data class Result(val verdict: Verdict, val emits: List<Emit>)
|
|
60
|
+
|
|
61
|
+
private enum class Phase { IDLE, HOLDING, RELEASED, PASSING }
|
|
62
|
+
|
|
63
|
+
@Volatile var taps = false
|
|
64
|
+
@Volatile var touches = false
|
|
65
|
+
@Volatile var consume = false
|
|
66
|
+
@Volatile var excludeSurfaces = false
|
|
67
|
+
|
|
68
|
+
/** Whether a window point is on a surface the host excludes (the map's view). Asked only on a first finger down. */
|
|
69
|
+
var isExcluded: (Float, Float) -> Boolean = { _, _ -> false }
|
|
70
|
+
|
|
71
|
+
private var downAt = 0L
|
|
72
|
+
private var maxPointers = 0
|
|
73
|
+
private var moved = false
|
|
74
|
+
private var downX = 0f
|
|
75
|
+
private var downY = 0f
|
|
76
|
+
private var downExcluded = false
|
|
77
|
+
|
|
78
|
+
private var phase = Phase.IDLE
|
|
79
|
+
private val held = HashMap<Int, Pair<Float, Float>>()
|
|
80
|
+
|
|
81
|
+
val watching: Boolean
|
|
82
|
+
get() = taps || touches
|
|
83
|
+
|
|
84
|
+
/** Every event of the window, in order. Never throws. */
|
|
85
|
+
fun onEvent(s: Sample): Result {
|
|
86
|
+
if (!watching) {
|
|
87
|
+
phase = Phase.IDLE
|
|
88
|
+
return Result(Verdict.PASS, emptyList())
|
|
89
|
+
}
|
|
90
|
+
val emits = ArrayList<Emit>(1)
|
|
91
|
+
observe(s, emits)
|
|
92
|
+
val verdict = if (taps && consume) intercept(s) else Verdict.PASS
|
|
93
|
+
return Result(verdict, emits)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
private fun observe(s: Sample, emits: MutableList<Emit>) {
|
|
97
|
+
val first = s.pointers.firstOrNull()
|
|
98
|
+
when (s.action) {
|
|
99
|
+
DOWN -> {
|
|
100
|
+
downAt = clock()
|
|
101
|
+
maxPointers = 1
|
|
102
|
+
moved = false
|
|
103
|
+
downX = first?.x ?: 0f
|
|
104
|
+
downY = first?.y ?: 0f
|
|
105
|
+
downExcluded = runCatching { isExcluded(downX, downY) }.getOrDefault(false)
|
|
106
|
+
if (touches) emits += Emit("down", 1, downX, downY, false)
|
|
107
|
+
}
|
|
108
|
+
POINTER_DOWN -> maxPointers = maxOf(maxPointers, s.pointers.size)
|
|
109
|
+
MOVE -> if (!moved && first != null && (Math.abs(first.x - downX) > slopPx || Math.abs(first.y - downY) > slopPx)) moved = true
|
|
110
|
+
UP -> {
|
|
111
|
+
if (taps && !moved && maxPointers >= 2 && clock() - downAt <= maxTapMsFor(maxPointers)) {
|
|
112
|
+
emits += Emit("tap", maxPointers, downX, downY, downExcluded)
|
|
113
|
+
}
|
|
114
|
+
maxPointers = 0
|
|
115
|
+
}
|
|
116
|
+
CANCEL -> {
|
|
117
|
+
maxPointers = 0
|
|
118
|
+
moved = true
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
private fun intercept(s: Sample): Verdict =
|
|
124
|
+
when (s.action) {
|
|
125
|
+
DOWN -> {
|
|
126
|
+
phase = Phase.IDLE
|
|
127
|
+
held.clear()
|
|
128
|
+
Verdict.PASS
|
|
129
|
+
}
|
|
130
|
+
POINTER_DOWN ->
|
|
131
|
+
when {
|
|
132
|
+
phase == Phase.HOLDING -> {
|
|
133
|
+
remember(s)
|
|
134
|
+
Verdict.CONSUME
|
|
135
|
+
}
|
|
136
|
+
phase != Phase.IDLE -> Verdict.PASS
|
|
137
|
+
s.pointers.size == 2 && !moved && clock() - downAt <= SECOND_FINGER_WINDOW_MS && !(excludeSurfaces && downExcluded) -> {
|
|
138
|
+
remember(s)
|
|
139
|
+
phase = Phase.HOLDING
|
|
140
|
+
Verdict.CANCEL_THEN_CONSUME
|
|
141
|
+
}
|
|
142
|
+
else -> {
|
|
143
|
+
phase = Phase.PASSING
|
|
144
|
+
Verdict.PASS
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
MOVE ->
|
|
148
|
+
if (phase != Phase.HOLDING) {
|
|
149
|
+
Verdict.PASS
|
|
150
|
+
} else if (anyMoved(s) || clock() - downAt > maxTapMsFor(s.pointers.size)) {
|
|
151
|
+
phase = Phase.RELEASED
|
|
152
|
+
Verdict.REPLAY
|
|
153
|
+
} else {
|
|
154
|
+
Verdict.CONSUME
|
|
155
|
+
}
|
|
156
|
+
POINTER_UP -> if (phase == Phase.HOLDING) Verdict.CONSUME else Verdict.PASS
|
|
157
|
+
UP, CANCEL -> {
|
|
158
|
+
val wasHeld = phase == Phase.HOLDING
|
|
159
|
+
phase = Phase.IDLE
|
|
160
|
+
held.clear()
|
|
161
|
+
if (wasHeld) Verdict.CONSUME else Verdict.PASS
|
|
162
|
+
}
|
|
163
|
+
else -> if (phase == Phase.HOLDING) Verdict.CONSUME else Verdict.PASS
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
private fun remember(s: Sample) {
|
|
167
|
+
for (p in s.pointers) held.putIfAbsent(p.id, p.x to p.y)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
private fun anyMoved(s: Sample): Boolean =
|
|
171
|
+
s.pointers.any { p ->
|
|
172
|
+
val start = held[p.id] ?: return@any false
|
|
173
|
+
Math.abs(p.x - start.first) > slopPx || Math.abs(p.y - start.second) > slopPx
|
|
174
|
+
}
|
|
175
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Generated by @lynx-js/autolink-codegen. Do not edit.
|
|
2
|
+
// Parameter types: scripts/android-bridge-types.mjs --fix (Lynx's bridge rejects the generator's Object).
|
|
3
|
+
package com.g9tm.appdiagnostic.generated;
|
|
4
|
+
|
|
5
|
+
import androidx.annotation.Nullable;
|
|
6
|
+
import com.lynx.jsbridge.LynxContextModule;
|
|
7
|
+
import com.lynx.jsbridge.LynxMethod;
|
|
8
|
+
import com.lynx.react.bridge.Callback;
|
|
9
|
+
import com.lynx.tasm.behavior.LynxContext;
|
|
10
|
+
|
|
11
|
+
public abstract class G9AppDiagnosticModuleSpec extends LynxContextModule {
|
|
12
|
+
public G9AppDiagnosticModuleSpec(LynxContext context) {
|
|
13
|
+
super(context);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@LynxMethod
|
|
17
|
+
public abstract void capabilities(Callback callback);
|
|
18
|
+
|
|
19
|
+
@LynxMethod
|
|
20
|
+
public abstract void state(Callback callback);
|
|
21
|
+
|
|
22
|
+
@LynxMethod
|
|
23
|
+
public abstract void startScreen(String dir, double maxFps, Callback callback);
|
|
24
|
+
|
|
25
|
+
@LynxMethod
|
|
26
|
+
public abstract void stopScreen(Callback callback);
|
|
27
|
+
|
|
28
|
+
@LynxMethod
|
|
29
|
+
public abstract void startVoice(String dir, Callback callback);
|
|
30
|
+
|
|
31
|
+
@LynxMethod
|
|
32
|
+
public abstract void stopVoice(Callback callback);
|
|
33
|
+
|
|
34
|
+
@LynxMethod
|
|
35
|
+
public abstract void watchTouches(boolean taps, boolean touches, boolean consume, boolean excludeSurfaces, Callback callback);
|
|
36
|
+
|
|
37
|
+
@LynxMethod
|
|
38
|
+
public abstract void screenshot(String dir, double maxEdge, double quality, Callback callback);
|
|
39
|
+
|
|
40
|
+
@LynxMethod
|
|
41
|
+
public abstract void sendRange(String requestJson, Callback callback);
|
|
42
|
+
|
|
43
|
+
@LynxMethod
|
|
44
|
+
public abstract void touch(String kind, double x, double y, double toX, double toY, double durationMs, Callback callback);
|
|
45
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Generated by @lynx-js/autolink-codegen. Do not edit.
|
|
2
|
+
|
|
3
|
+
const ADDON_NAME = "G9AppDiagnosticModule";
|
|
4
|
+
|
|
5
|
+
export interface G9AppDiagnosticModuleSpec {
|
|
6
|
+
capabilities(callback: (reply: Record<string, unknown>) => void): void;
|
|
7
|
+
state(callback: (reply: Record<string, unknown>) => void): void;
|
|
8
|
+
startScreen(dir: string, maxFps: number, callback: (reply: Record<string, unknown>) => void): void;
|
|
9
|
+
stopScreen(callback: (reply: Record<string, unknown>) => void): void;
|
|
10
|
+
startVoice(dir: string, callback: (reply: Record<string, unknown>) => void): void;
|
|
11
|
+
stopVoice(callback: (reply: Record<string, unknown>) => void): void;
|
|
12
|
+
watchTouches(taps: boolean, touches: boolean, consume: boolean, excludeSurfaces: boolean, callback: (reply: Record<string, unknown>) => void): void;
|
|
13
|
+
screenshot(dir: string, maxEdge: number, quality: number, callback: (reply: Record<string, unknown>) => void): void;
|
|
14
|
+
sendRange(requestJson: string, callback: (reply: Record<string, unknown>) => void): void;
|
|
15
|
+
touch(kind: string, x: number, y: number, toX: number, toY: number, durationMs: number, callback: (reply: Record<string, unknown>) => void): void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
type AddonExports = Record<string, unknown>;
|
|
19
|
+
|
|
20
|
+
declare let NativeModules: Record<string, unknown>;
|
|
21
|
+
|
|
22
|
+
declare global {
|
|
23
|
+
interface LynxNapiLoader {
|
|
24
|
+
load(moduleName: string): AddonExports | null | undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// eslint-disable-next-line no-var
|
|
28
|
+
var __lynxNapiLoader: LynxNapiLoader | undefined;
|
|
29
|
+
|
|
30
|
+
function getNapiLoader(): LynxNapiLoader | undefined;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
declare const lynx: {
|
|
34
|
+
getModuleLoader?(): LynxNapiLoader | undefined;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
function getNativeModules(): Record<string, unknown> | undefined {
|
|
38
|
+
const globalObject = globalThis as unknown as {
|
|
39
|
+
NativeModules?: Record<string, unknown>;
|
|
40
|
+
};
|
|
41
|
+
return typeof NativeModules !== 'undefined'
|
|
42
|
+
? NativeModules
|
|
43
|
+
: globalObject.NativeModules;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function installG9AppDiagnosticModuleShim(): void {
|
|
47
|
+
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function requireG9AppDiagnosticModule(): G9AppDiagnosticModuleSpec {
|
|
51
|
+
const nativeModules = getNativeModules();
|
|
52
|
+
const existingModule = nativeModules?.[ADDON_NAME];
|
|
53
|
+
if (existingModule !== undefined && existingModule !== null) {
|
|
54
|
+
return existingModule as G9AppDiagnosticModuleSpec;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
throw new Error(`Native module "${ADDON_NAME}" is unavailable.`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export const G9AppDiagnosticModule = new Proxy({}, {
|
|
63
|
+
get(_target, property) {
|
|
64
|
+
return requireG9AppDiagnosticModule()[property as keyof G9AppDiagnosticModuleSpec];
|
|
65
|
+
},
|
|
66
|
+
}) as G9AppDiagnosticModuleSpec;
|
|
67
|
+
|
|
68
|
+
installG9AppDiagnosticModuleShim();
|
|
69
|
+
|
|
70
|
+
export default G9AppDiagnosticModule;
|
package/lynx.lib.json
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,39 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@g9tm/app-diagnostic-lynx",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@g9tm/app-diagnostic-lynx",
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "Lynx native half of @g9tm/app-diagnostic: the app's own window as an MP4, a spoken note, the window screenshot, a file range sent natively, and the tester gesture (observed or consumed). No product names: the host configures everything.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.ts",
|
|
7
|
+
"types": "src/index.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"source": "./src/index.ts",
|
|
11
|
+
"types": "./src/index.ts",
|
|
12
|
+
"default": "./src/index.ts"
|
|
13
|
+
},
|
|
14
|
+
"./package.json": "./package.json"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"src",
|
|
18
|
+
"generated",
|
|
19
|
+
"types",
|
|
20
|
+
"android/build.gradle.kts",
|
|
21
|
+
"android/consumer-rules.pro",
|
|
22
|
+
"android/src/main",
|
|
23
|
+
"ios/g9tm-app-diagnostic-lynx.podspec",
|
|
24
|
+
"ios/src",
|
|
25
|
+
"lynx.lib.json",
|
|
26
|
+
"README.md",
|
|
27
|
+
"Native-Validation-Pending.md"
|
|
28
|
+
],
|
|
29
|
+
"scripts": {
|
|
30
|
+
"test": "node --test test/*.test.ts",
|
|
31
|
+
"test:android-jvm": "node scripts/run-gradle.mjs -p jvm test",
|
|
32
|
+
"check:android-module": "node scripts/run-gradle.mjs -p android-check build"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@g9tm/app-diagnostic": "^0.2.1"
|
|
36
|
+
},
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"engines": { "node": ">=22.6" }
|
|
39
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
// @g9tm/app-diagnostic-lynx — the native half of @g9tm/app-diagnostic on Lynx: the `G9AppDiagnosticModule` native module
|
|
2
|
+
// (Android android/, iOS ios/, Autolink) turned into promises, and the core's platform interfaces built on it. Runs on
|
|
3
|
+
// Lynx's background thread: ES2019, no timers of its own. The module's envelopes and error codes:
|
|
4
|
+
// types/g9-app-diagnostic-module.d.ts.
|
|
5
|
+
import type { DiagnosticSendRange, RangeRequest, RangeResponse, Unsubscribe } from '@g9tm/app-diagnostic';
|
|
6
|
+
import { type G9AppDiagnosticModuleSpec, requireG9AppDiagnosticModule } from '../generated/G9AppDiagnosticModule.ts';
|
|
7
|
+
|
|
8
|
+
/** The module's shape, for a host that calls it through its own bridge layer (its own error type). */
|
|
9
|
+
export type { G9AppDiagnosticModuleSpec };
|
|
10
|
+
|
|
11
|
+
/** Error codes of the module contract. Public API: add, never rename or repurpose. */
|
|
12
|
+
export const DiagnosticNativeErrorCode = {
|
|
13
|
+
Busy: 'busy',
|
|
14
|
+
Permission: 'permission',
|
|
15
|
+
Unavailable: 'unavailable',
|
|
16
|
+
Invalid: 'invalid',
|
|
17
|
+
NotFound: 'not-found',
|
|
18
|
+
Network: 'network',
|
|
19
|
+
Timeout: 'timeout',
|
|
20
|
+
Io: 'io',
|
|
21
|
+
} as const;
|
|
22
|
+
|
|
23
|
+
/** A native error with the contract's code. */
|
|
24
|
+
export class DiagnosticNativeError extends Error {
|
|
25
|
+
readonly code: string;
|
|
26
|
+
|
|
27
|
+
constructor(code: string, message: string) {
|
|
28
|
+
super(message);
|
|
29
|
+
this.name = 'DiagnosticNativeError';
|
|
30
|
+
this.code = code;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface DiagnosticNativeCapabilities {
|
|
35
|
+
readonly version: string;
|
|
36
|
+
readonly platform: 'android' | 'ios' | string;
|
|
37
|
+
readonly screen: boolean;
|
|
38
|
+
readonly voice: boolean;
|
|
39
|
+
/** The gesture can be held away from the views (E-20). */
|
|
40
|
+
readonly consume: boolean;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface DiagnosticRecording {
|
|
44
|
+
readonly path: string;
|
|
45
|
+
readonly bytes: number;
|
|
46
|
+
readonly durationMs: number;
|
|
47
|
+
readonly width?: number;
|
|
48
|
+
readonly height?: number;
|
|
49
|
+
/** The 10-minute cap ended it. */
|
|
50
|
+
readonly capped?: boolean;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** One touch the watcher reports (x, y: fractions of the window). */
|
|
54
|
+
export interface DiagnosticTouchEvent {
|
|
55
|
+
readonly type: 'tap' | 'down';
|
|
56
|
+
readonly fingers: number;
|
|
57
|
+
readonly x: number;
|
|
58
|
+
readonly y: number;
|
|
59
|
+
/** On a surface the host excludes (its map). */
|
|
60
|
+
readonly excluded: boolean;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** One remote touch: points in dp from the window's top-left. */
|
|
64
|
+
export interface DiagnosticTouch {
|
|
65
|
+
readonly kind: 'tap' | 'longPress' | 'drag';
|
|
66
|
+
readonly x: number;
|
|
67
|
+
readonly y: number;
|
|
68
|
+
readonly toX?: number;
|
|
69
|
+
readonly toY?: number;
|
|
70
|
+
readonly durationMs?: number;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface DiagnosticWatchOptions {
|
|
74
|
+
/** Report completed multi-finger taps (the gesture). */
|
|
75
|
+
readonly taps: boolean;
|
|
76
|
+
/** Report every first finger down (a recording's timeline). */
|
|
77
|
+
readonly touches: boolean;
|
|
78
|
+
/** Hold a two-finger touch away from the views so the gesture never also presses what is under it. */
|
|
79
|
+
readonly consume: boolean;
|
|
80
|
+
/** Never hold over an excluded surface (the «except the map» mode). */
|
|
81
|
+
readonly excludeSurfaces: boolean;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** The global events a Lynx page receives (`lynx.getJSModule('GlobalEventEmitter')`), or a test's stand-in. */
|
|
85
|
+
export interface GlobalEvents {
|
|
86
|
+
addListener(name: string, listener: (...args: unknown[]) => void): void;
|
|
87
|
+
removeListener(name: string, listener: (...args: unknown[]) => void): void;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export const TOUCH_EVENT = 'g9:diagnostic-touch';
|
|
91
|
+
|
|
92
|
+
type Reply = Record<string, unknown>;
|
|
93
|
+
|
|
94
|
+
function unwrap<T>(reply: Reply): T {
|
|
95
|
+
if (reply && reply.ok === true) return reply.value as T;
|
|
96
|
+
const error = (reply?.error ?? {}) as { code?: unknown; message?: unknown };
|
|
97
|
+
throw new DiagnosticNativeError(typeof error.code === 'string' ? error.code : DiagnosticNativeErrorCode.Io, typeof error.message === 'string' ? error.message : 'native call failed');
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function call<T>(invoke: (callback: (reply: Reply) => void) => void): Promise<T> {
|
|
101
|
+
return new Promise<T>((resolve, reject) => {
|
|
102
|
+
try {
|
|
103
|
+
invoke((reply) => {
|
|
104
|
+
try {
|
|
105
|
+
resolve(unwrap<T>(reply));
|
|
106
|
+
} catch (error) {
|
|
107
|
+
reject(error);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
} catch (error) {
|
|
111
|
+
reject(new DiagnosticNativeError(DiagnosticNativeErrorCode.Unavailable, String((error as Error)?.message ?? error)));
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** The module as promises. `module` defaults to the registered native module (tests pass a fake with the same shape). */
|
|
117
|
+
export function createDiagnosticNative(module: G9AppDiagnosticModuleSpec = requireG9AppDiagnosticModule()) {
|
|
118
|
+
return {
|
|
119
|
+
capabilities: () => call<DiagnosticNativeCapabilities>((cb) => module.capabilities(cb)),
|
|
120
|
+
state: () => call<{ readonly screen: boolean; readonly voice: boolean }>((cb) => module.state(cb)),
|
|
121
|
+
startScreen: (dir: string, maxFps = 10) => call<null>((cb) => module.startScreen(dir, maxFps, cb)).then(() => undefined),
|
|
122
|
+
stopScreen: () => call<DiagnosticRecording | null>((cb) => module.stopScreen(cb)),
|
|
123
|
+
startVoice: (dir: string) => call<null>((cb) => module.startVoice(dir, cb)).then(() => undefined),
|
|
124
|
+
stopVoice: () => call<DiagnosticRecording | null>((cb) => module.stopVoice(cb)),
|
|
125
|
+
watchTouches: (o: DiagnosticWatchOptions) => call<null>((cb) => module.watchTouches(o.taps, o.touches, o.consume, o.excludeSurfaces, cb)).then(() => undefined),
|
|
126
|
+
screenshot: (dir: string, maxEdge: number, quality: number) =>
|
|
127
|
+
call<{ readonly path: string; readonly width: number; readonly height: number; readonly bytes: number }>((cb) => module.screenshot(dir, maxEdge, quality, cb)),
|
|
128
|
+
sendRange: (request: RangeRequest) => call<RangeResponse>((cb) => module.sendRange(JSON.stringify(request), cb)),
|
|
129
|
+
/** A real touch for the operator's remote control (E-13): dp from the window's top-left; check the user's consent first. */
|
|
130
|
+
touch: (t: DiagnosticTouch) =>
|
|
131
|
+
call<{ readonly handled: boolean }>((cb) => module.touch(t.kind, t.x, t.y, t.toX ?? t.x, t.toY ?? t.y, t.durationMs ?? (t.kind === 'longPress' ? 800 : t.kind === 'drag' ? 300 : 50), cb)),
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export type DiagnosticNative = ReturnType<typeof createDiagnosticNative>;
|
|
136
|
+
|
|
137
|
+
/** The core's `DiagnosticSendRange` (the tester report's resumable PUT) on the native module. */
|
|
138
|
+
export function nativeSendRange(native: Pick<DiagnosticNative, 'sendRange'>): DiagnosticSendRange {
|
|
139
|
+
return (request) => native.sendRange(request);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** The watcher's events, parsed; a malformed one is dropped. */
|
|
143
|
+
export function onDiagnosticTouch(events: GlobalEvents, listener: (event: DiagnosticTouchEvent) => void): Unsubscribe {
|
|
144
|
+
const handler = (...args: unknown[]) => {
|
|
145
|
+
const raw = args[0];
|
|
146
|
+
try {
|
|
147
|
+
const e = (typeof raw === 'string' ? JSON.parse(raw) : raw) as Partial<DiagnosticTouchEvent>;
|
|
148
|
+
if ((e.type === 'tap' || e.type === 'down') && typeof e.fingers === 'number' && typeof e.x === 'number' && typeof e.y === 'number') {
|
|
149
|
+
listener({ type: e.type, fingers: e.fingers, x: e.x, y: e.y, excluded: e.excluded === true });
|
|
150
|
+
}
|
|
151
|
+
} catch {
|
|
152
|
+
// not ours
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
events.addListener(TOUCH_EVENT, handler);
|
|
156
|
+
return () => events.removeListener(TOUCH_EVENT, handler);
|
|
157
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// The native module of @g9tm/app-diagnostic-lynx. The Android/iOS specs and the JS accessor (generated/) follow this
|
|
2
|
+
// declaration. Every reply is an envelope `{ ok: true, value } | { ok: false, error: { code, message } }` so the error
|
|
3
|
+
// fields survive the bridge.
|
|
4
|
+
//
|
|
5
|
+
// Error codes (public API — add, never rename or repurpose):
|
|
6
|
+
// busy a recorder of that kind is already running
|
|
7
|
+
// permission the microphone permission was refused
|
|
8
|
+
// unavailable no encoder / microphone / laid-out window
|
|
9
|
+
// invalid a folder or file outside the folders the host allows, or a malformed request
|
|
10
|
+
// not-found the file to send does not exist
|
|
11
|
+
// network the range request failed in transport (any HTTP status is a value, not an error)
|
|
12
|
+
// timeout the range request ran past its time limit
|
|
13
|
+
// io the platform refused (a capture that failed, no space)
|
|
14
|
+
//
|
|
15
|
+
// Events (global, JSON text): `g9:diagnostic-touch` — {type: 'tap', fingers, x, y, excluded} for a completed multi-finger
|
|
16
|
+
// tap, {type: 'down', fingers: 1, x, y, excluded: false} for a first finger down (only while `touches` is on). x, y are
|
|
17
|
+
// fractions of the window; `excluded` = the first finger landed on a surface the host excludes (a map).
|
|
18
|
+
|
|
19
|
+
/** @lynxmodule */
|
|
20
|
+
export declare class G9AppDiagnosticModule {
|
|
21
|
+
/** `{ version, platform: 'android' | 'ios', screen, voice, consume }`: what this device can record, whether a gesture can be consumed. */
|
|
22
|
+
capabilities(callback: (reply: Record<string, unknown>) => void): void;
|
|
23
|
+
/** `{ screen, voice }`: which recorder runs now (a recorder outlives a reload of the app's script). */
|
|
24
|
+
state(callback: (reply: Record<string, unknown>) => void): void;
|
|
25
|
+
/**
|
|
26
|
+
* Records the app's OWN window into `<dir>/screen-<ms>.mp4` (H.264, long edge ≤ 960 px, no system consent) at an adaptive
|
|
27
|
+
* rate starting at `maxFps` (4-20). Stops itself at 10 minutes and keeps the file for `stopScreen`. Value: null.
|
|
28
|
+
*/
|
|
29
|
+
startScreen(dir: string, maxFps: number, callback: (reply: Record<string, unknown>) => void): void;
|
|
30
|
+
/** `{ path, bytes, durationMs, width, height, capped }`, or null when nothing usable was recorded. */
|
|
31
|
+
stopScreen(callback: (reply: Record<string, unknown>) => void): void;
|
|
32
|
+
/** Records the microphone into `<dir>/voice-<ms>.m4a` (AAC, mono, 44.1 kHz); asks the permission first. Value: null. */
|
|
33
|
+
startVoice(dir: string, callback: (reply: Record<string, unknown>) => void): void;
|
|
34
|
+
/** `{ path, bytes, durationMs }`, or null. */
|
|
35
|
+
stopVoice(callback: (reply: Record<string, unknown>) => void): void;
|
|
36
|
+
/**
|
|
37
|
+
* The tester gesture's watcher: `taps` reports completed multi-finger taps, `touches` every first finger down, `consume`
|
|
38
|
+
* holds a two-finger touch away from the views (cancelled, replayed when it turns out to be a pinch or pan) so the
|
|
39
|
+
* gesture never also presses what is under it; `excludeSurfaces` keeps the excluded surfaces native (never held). All
|
|
40
|
+
* false = nothing is watched. Value: null.
|
|
41
|
+
*/
|
|
42
|
+
watchTouches(taps: boolean, touches: boolean, consume: boolean, excludeSurfaces: boolean, callback: (reply: Record<string, unknown>) => void): void;
|
|
43
|
+
/** The window as the user sees it (the map included), JPEG at `quality` (10-100), long edge ≤ `maxEdge`, into `dir`: `{ path, width, height, bytes }`. */
|
|
44
|
+
screenshot(dir: string, maxEdge: number, quality: number, callback: (reply: Record<string, unknown>) => void): void;
|
|
45
|
+
/**
|
|
46
|
+
* One HTTP request whose body is a byte range of a file, read natively: `{url, method, path, offset, length, contentType,
|
|
47
|
+
* headers, timeoutMs}` as JSON. Every HTTP status resolves `{ status, body, headers }`; only a transport failure rejects.
|
|
48
|
+
*/
|
|
49
|
+
sendRange(requestJson: string, callback: (reply: Record<string, unknown>) => void): void;
|
|
50
|
+
/**
|
|
51
|
+
* A REAL touch for the operator's remote control (the live channel's remote input, E-13; the caller checks the user's
|
|
52
|
+
* consent first): `kind` 'tap' | 'longPress' | 'drag', points in dp from the window's top-left, dispatched into the
|
|
53
|
+
* window's decor view with real time between DOWN, MOVEs and UP — whatever is on top gets it as it gets a finger.
|
|
54
|
+
* `{ handled }`.
|
|
55
|
+
*/
|
|
56
|
+
touch(kind: string, x: number, y: number, toX: number, toY: number, durationMs: number, callback: (reply: Record<string, unknown>) => void): void;
|
|
57
|
+
}
|