@g9tm/app-diagnostic-lynx 0.3.1 → 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/Native-Validation-Pending.md +1 -1
- package/README.md +63 -42
- package/android/build.gradle.kts +45 -45
- package/android/src/main/java/com/g9tm/appdiagnostic/G9AppDiagnosticHost.kt +19 -19
- package/android/src/main/java/com/g9tm/appdiagnostic/G9AppDiagnosticModule.kt +2 -2
- package/android/src/main/java/com/g9tm/appdiagnostic/LynxBridge.kt +41 -0
- package/android/src/main/java/com/g9tm/appdiagnostic/TouchWatcher.kt +129 -129
- package/android/src/main/java/com/g9tm/appdiagnostic/core/TouchCore.kt +270 -270
- package/ios/g9tm-app-diagnostic-lynx.podspec +23 -0
- package/ios/src/G9AppDiagnosticHost.h +32 -0
- package/ios/src/G9AppDiagnosticHost.m +72 -0
- package/ios/src/G9AppDiagnosticModule.h +23 -0
- package/ios/src/G9AppDiagnosticModule.m +238 -0
- package/ios/src/G9DiagnosticRecorders.h +36 -0
- package/ios/src/G9DiagnosticRecorders.m +514 -0
- package/package.json +17 -4
- package/src/index.ts +178 -175
- package/src/ui/TesterPanel.tsx +224 -0
- package/types/g9-app-diagnostic-module.d.ts +60 -60
package/src/index.ts
CHANGED
|
@@ -1,175 +1,178 @@
|
|
|
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
|
-
/**
|
|
54
|
-
* One touch the watcher reports (fractions of the window). `tap`: a completed multi-finger tap; `down`: a first finger
|
|
55
|
-
* down; `seq` (only while `touches` is on): the trace of a touch that could have been a tap — why it was or was not one.
|
|
56
|
-
*/
|
|
57
|
-
export interface DiagnosticTouchEvent {
|
|
58
|
-
readonly type: 'tap' | 'down' | 'seq';
|
|
59
|
-
readonly fingers: number;
|
|
60
|
-
/** The first finger. */
|
|
61
|
-
readonly x: number;
|
|
62
|
-
readonly y: number;
|
|
63
|
-
/** The fingers' midpoint at the most fingers (a tap, a trace); the first finger otherwise. */
|
|
64
|
-
readonly cx: number;
|
|
65
|
-
readonly cy: number;
|
|
66
|
-
/** On a surface the host excludes (its map). */
|
|
67
|
-
readonly excluded: boolean;
|
|
68
|
-
/** A `seq` trace's facts (ms, secondMs, firstUpMs, movePx, slopPx, held, why, …). */
|
|
69
|
-
readonly info?: Readonly<Record<string, unknown>>;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/** One remote touch: points in dp from the window's top-left. */
|
|
73
|
-
export interface DiagnosticTouch {
|
|
74
|
-
readonly kind: 'tap' | 'longPress' | 'drag';
|
|
75
|
-
readonly x: number;
|
|
76
|
-
readonly y: number;
|
|
77
|
-
readonly toX?: number;
|
|
78
|
-
readonly toY?: number;
|
|
79
|
-
readonly durationMs?: number;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export interface DiagnosticWatchOptions {
|
|
83
|
-
/** Report completed multi-finger taps (the gesture). */
|
|
84
|
-
readonly taps: boolean;
|
|
85
|
-
/** Report every first finger down (a recording's timeline). */
|
|
86
|
-
readonly touches: boolean;
|
|
87
|
-
/** Hold a two-finger touch away from the views so the gesture never also presses what is under it. */
|
|
88
|
-
readonly consume: boolean;
|
|
89
|
-
/** Never hold over an excluded surface (the «except the map» mode). */
|
|
90
|
-
readonly excludeSurfaces: boolean;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/** The global events a Lynx page receives (`lynx.getJSModule('GlobalEventEmitter')`), or a test's stand-in. */
|
|
94
|
-
export interface GlobalEvents {
|
|
95
|
-
addListener(name: string, listener: (...args: unknown[]) => void): void;
|
|
96
|
-
removeListener(name: string, listener: (...args: unknown[]) => void): void;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export const TOUCH_EVENT = 'g9:diagnostic-touch';
|
|
100
|
-
|
|
101
|
-
type Reply = Record<string, unknown>;
|
|
102
|
-
|
|
103
|
-
function unwrap<T>(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
export
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
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
|
+
/**
|
|
54
|
+
* One touch the watcher reports (fractions of the window). `tap`: a completed multi-finger tap; `down`: a first finger
|
|
55
|
+
* down; `seq` (only while `touches` is on): the trace of a touch that could have been a tap — why it was or was not one.
|
|
56
|
+
*/
|
|
57
|
+
export interface DiagnosticTouchEvent {
|
|
58
|
+
readonly type: 'tap' | 'down' | 'seq';
|
|
59
|
+
readonly fingers: number;
|
|
60
|
+
/** The first finger. */
|
|
61
|
+
readonly x: number;
|
|
62
|
+
readonly y: number;
|
|
63
|
+
/** The fingers' midpoint at the most fingers (a tap, a trace); the first finger otherwise. */
|
|
64
|
+
readonly cx: number;
|
|
65
|
+
readonly cy: number;
|
|
66
|
+
/** On a surface the host excludes (its map). */
|
|
67
|
+
readonly excluded: boolean;
|
|
68
|
+
/** A `seq` trace's facts (ms, secondMs, firstUpMs, movePx, slopPx, held, why, …). */
|
|
69
|
+
readonly info?: Readonly<Record<string, unknown>>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** One remote touch: points in dp from the window's top-left. */
|
|
73
|
+
export interface DiagnosticTouch {
|
|
74
|
+
readonly kind: 'tap' | 'longPress' | 'drag';
|
|
75
|
+
readonly x: number;
|
|
76
|
+
readonly y: number;
|
|
77
|
+
readonly toX?: number;
|
|
78
|
+
readonly toY?: number;
|
|
79
|
+
readonly durationMs?: number;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface DiagnosticWatchOptions {
|
|
83
|
+
/** Report completed multi-finger taps (the gesture). */
|
|
84
|
+
readonly taps: boolean;
|
|
85
|
+
/** Report every first finger down (a recording's timeline). */
|
|
86
|
+
readonly touches: boolean;
|
|
87
|
+
/** Hold a two-finger touch away from the views so the gesture never also presses what is under it. */
|
|
88
|
+
readonly consume: boolean;
|
|
89
|
+
/** Never hold over an excluded surface (the «except the map» mode). */
|
|
90
|
+
readonly excludeSurfaces: boolean;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** The global events a Lynx page receives (`lynx.getJSModule('GlobalEventEmitter')`), or a test's stand-in. */
|
|
94
|
+
export interface GlobalEvents {
|
|
95
|
+
addListener(name: string, listener: (...args: unknown[]) => void): void;
|
|
96
|
+
removeListener(name: string, listener: (...args: unknown[]) => void): void;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export const TOUCH_EVENT = 'g9:diagnostic-touch';
|
|
100
|
+
|
|
101
|
+
type Reply = Record<string, unknown>;
|
|
102
|
+
|
|
103
|
+
function unwrap<T>(raw: Reply | string): T {
|
|
104
|
+
// A map (Android, iOS) or its JSON text (a host that answers strings): the same envelope either way.
|
|
105
|
+
let reply: Reply;
|
|
106
|
+
try { reply = typeof raw === 'string' ? (JSON.parse(raw) as Reply) : raw; } catch { reply = { ok: false, error: { code: DiagnosticNativeErrorCode.Io, message: 'the native reply is not JSON' } }; }
|
|
107
|
+
if (reply && reply.ok === true) return reply.value as T;
|
|
108
|
+
const error = (reply?.error ?? {}) as { code?: unknown; message?: unknown };
|
|
109
|
+
throw new DiagnosticNativeError(typeof error.code === 'string' ? error.code : DiagnosticNativeErrorCode.Io, typeof error.message === 'string' ? error.message : 'native call failed');
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function call<T>(invoke: (callback: (reply: Reply) => void) => void): Promise<T> {
|
|
113
|
+
return new Promise<T>((resolve, reject) => {
|
|
114
|
+
try {
|
|
115
|
+
invoke((reply) => {
|
|
116
|
+
try {
|
|
117
|
+
resolve(unwrap<T>(reply));
|
|
118
|
+
} catch (error) {
|
|
119
|
+
reject(error);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
} catch (error) {
|
|
123
|
+
reject(new DiagnosticNativeError(DiagnosticNativeErrorCode.Unavailable, String((error as Error)?.message ?? error)));
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** The module as promises. `module` defaults to the registered native module (tests pass a fake with the same shape). */
|
|
129
|
+
export function createDiagnosticNative(module: G9AppDiagnosticModuleSpec = requireG9AppDiagnosticModule()) {
|
|
130
|
+
return {
|
|
131
|
+
capabilities: () => call<DiagnosticNativeCapabilities>((cb) => module.capabilities(cb)),
|
|
132
|
+
state: () => call<{ readonly screen: boolean; readonly voice: boolean }>((cb) => module.state(cb)),
|
|
133
|
+
startScreen: (dir: string, maxFps = 10) => call<null>((cb) => module.startScreen(dir, maxFps, cb)).then(() => undefined),
|
|
134
|
+
stopScreen: () => call<DiagnosticRecording | null>((cb) => module.stopScreen(cb)),
|
|
135
|
+
startVoice: (dir: string) => call<null>((cb) => module.startVoice(dir, cb)).then(() => undefined),
|
|
136
|
+
stopVoice: () => call<DiagnosticRecording | null>((cb) => module.stopVoice(cb)),
|
|
137
|
+
watchTouches: (o: DiagnosticWatchOptions) => call<null>((cb) => module.watchTouches(o.taps, o.touches, o.consume, o.excludeSurfaces, cb)).then(() => undefined),
|
|
138
|
+
screenshot: (dir: string, maxEdge: number, quality: number) =>
|
|
139
|
+
call<{ readonly path: string; readonly width: number; readonly height: number; readonly bytes: number }>((cb) => module.screenshot(dir, maxEdge, quality, cb)),
|
|
140
|
+
sendRange: (request: RangeRequest) => call<RangeResponse>((cb) => module.sendRange(JSON.stringify(request), cb)),
|
|
141
|
+
/** A real touch for the operator's remote control (E-13): dp from the window's top-left; check the user's consent first. */
|
|
142
|
+
touch: (t: DiagnosticTouch) =>
|
|
143
|
+
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)),
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export type DiagnosticNative = ReturnType<typeof createDiagnosticNative>;
|
|
148
|
+
|
|
149
|
+
/** The core's `DiagnosticSendRange` (the tester report's resumable PUT) on the native module. */
|
|
150
|
+
export function nativeSendRange(native: Pick<DiagnosticNative, 'sendRange'>): DiagnosticSendRange {
|
|
151
|
+
return (request) => native.sendRange(request);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** The watcher's events, parsed; a malformed one is dropped. */
|
|
155
|
+
export function onDiagnosticTouch(events: GlobalEvents, listener: (event: DiagnosticTouchEvent) => void): Unsubscribe {
|
|
156
|
+
const handler = (...args: unknown[]) => {
|
|
157
|
+
const raw = args[0];
|
|
158
|
+
try {
|
|
159
|
+
const e = (typeof raw === 'string' ? JSON.parse(raw) : raw) as Partial<DiagnosticTouchEvent>;
|
|
160
|
+
if ((e.type === 'tap' || e.type === 'down' || e.type === 'seq') && typeof e.fingers === 'number' && typeof e.x === 'number' && typeof e.y === 'number') {
|
|
161
|
+
listener({
|
|
162
|
+
type: e.type,
|
|
163
|
+
fingers: e.fingers,
|
|
164
|
+
x: e.x,
|
|
165
|
+
y: e.y,
|
|
166
|
+
cx: typeof e.cx === 'number' ? e.cx : e.x,
|
|
167
|
+
cy: typeof e.cy === 'number' ? e.cy : e.y,
|
|
168
|
+
excluded: e.excluded === true,
|
|
169
|
+
...(e.info && typeof e.info === 'object' ? { info: e.info } : {}),
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
} catch {
|
|
173
|
+
// not ours
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
events.addListener(TOUCH_EVENT, handler);
|
|
177
|
+
return () => events.removeListener(TOUCH_EVENT, handler);
|
|
178
|
+
}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
// The tester mode's default UI for a Lynx app (4.5.0; .agents/skills/g9-app-diagnostic/references/tester-mode.md «On
|
|
2
|
+
// Lynx»): the floating pill and the send form over @g9tm/app-diagnostic's TesterEngine — the same behaviour the first
|
|
3
|
+
// Lynx app built in its own theme (moved out of it on 2026-11-20 so every Lynx app has a tester mode). Plain Lynx elements,
|
|
4
|
+
// no design system: an app with one passes its own `style` or keeps its themed copy on top of the same engine.
|
|
5
|
+
//
|
|
6
|
+
// <TesterPanel engine={engine} language={() => 'fa'} /> the pill (gesture → screenshot → report)
|
|
7
|
+
// <TesterReports engine={engine} language={() => 'fa'} /> this device's reports and what waits in its outbox
|
|
8
|
+
//
|
|
9
|
+
// Never hidden while the screen records: a hidden Stop strands the tester until the 10-minute cap.
|
|
10
|
+
import { type ReactNode, useEffect, useState } from '@lynx-js/react';
|
|
11
|
+
import type { DiagLanguage, ReadableStore, TesterEngine, TesterFeed, TesterReportKind, TesterState } from '@g9tm/app-diagnostic';
|
|
12
|
+
import type { CSSProperties } from '@lynx-js/types';
|
|
13
|
+
|
|
14
|
+
/** The pill's and the form's own words (the engine's notices come translated from the package). */
|
|
15
|
+
const UI = {
|
|
16
|
+
fa: {
|
|
17
|
+
send: 'فرستادن', screenshot: 'عکس', record: 'ضبط صفحه', stop: 'توقف', voice: 'صدا', stopVoice: 'پایان صدا', attach: 'پیوست',
|
|
18
|
+
discard: 'حذف', confirmDiscard: 'گزارش و همهٔ شاهدهایش پاک شود؟', yes: 'پاک کن', no: 'نه', kind: 'نوع گزارش',
|
|
19
|
+
words: 'چه دیدی؟ چه انتظار داشتی؟', backup: 'پشتیبان دیتابیس هم برود', ai: 'هوش مصنوعی گزارش را بخواند', cancel: 'بستن',
|
|
20
|
+
review: 'فرستادن گزارش', evidence: 'شاهد', reports: 'گزارشهای این دستگاه', queued: 'در صف ارسال', none: 'هنوز گزارشی نیست',
|
|
21
|
+
loadFailed: 'فهرست گزارشها نیامد', refresh: 'تازه کن', start: 'گزارش تازه',
|
|
22
|
+
},
|
|
23
|
+
en: {
|
|
24
|
+
send: 'Send', screenshot: 'Shot', record: 'Record', stop: 'Stop', voice: 'Voice', stopVoice: 'End voice', attach: 'Attach',
|
|
25
|
+
discard: 'Delete', confirmDiscard: 'Delete the report and all its evidence?', yes: 'Delete', no: 'No', kind: 'Kind of report',
|
|
26
|
+
words: 'What did you see? What did you expect?', backup: 'Send the database backup too', ai: 'Let the AI read the report', cancel: 'Close',
|
|
27
|
+
review: 'Send the report', evidence: 'evidence', reports: 'This device\'s reports', queued: 'Waiting to be sent', none: 'No report yet',
|
|
28
|
+
loadFailed: 'The reports did not load', refresh: 'Refresh', start: 'New report',
|
|
29
|
+
},
|
|
30
|
+
} as const;
|
|
31
|
+
|
|
32
|
+
type Words = { readonly [K in keyof typeof UI.fa]: string };
|
|
33
|
+
const wordsOf = (language: () => DiagLanguage): Words => (language() === 'en' ? UI.en : UI.fa);
|
|
34
|
+
|
|
35
|
+
/** A store's value as React state (re-rendered on every change). */
|
|
36
|
+
function useStore<T>(store: ReadableStore<T>): T {
|
|
37
|
+
const [value, setValue] = useState<T>(store.get());
|
|
38
|
+
useEffect(() => store.subscribe(() => setValue(store.get())), [store]);
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const clock = (ms: number) => {
|
|
43
|
+
const s = Math.max(0, Math.floor(ms / 1000));
|
|
44
|
+
return `${String(Math.floor(s / 60)).padStart(2, '0')}:${String(s % 60).padStart(2, '0')}`;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export interface TesterPanelProps {
|
|
48
|
+
readonly engine: TesterEngine;
|
|
49
|
+
readonly language: () => DiagLanguage;
|
|
50
|
+
/** Where the pill sits (default: the bottom end corner, above the home indicator). */
|
|
51
|
+
readonly style?: Record<string, string | number>;
|
|
52
|
+
/** The pill's colours: background, foreground, the recording red. */
|
|
53
|
+
readonly colors?: { readonly bg?: string; readonly fg?: string; readonly red?: string; readonly accent?: string };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function Button(p: { readonly label: string; readonly onTap: () => void; readonly strong?: boolean; readonly fg: string; readonly accent: string; readonly badge?: number }): ReactNode {
|
|
57
|
+
return (
|
|
58
|
+
<view bindtap={p.onTap} style={{ paddingLeft: '10px', paddingRight: '10px', height: '40px', borderRadius: '20px', display: 'flex', alignItems: 'center', justifyContent: 'center', backgroundColor: p.strong ? p.accent : 'transparent', marginLeft: '2px', marginRight: '2px' }}>
|
|
59
|
+
<text style={{ color: p.strong ? '#ffffff' : p.fg, fontSize: '14px', fontWeight: p.strong ? 'bold' : 'normal' }}>{p.badge ? `${p.label} ${p.badge}` : p.label}</text>
|
|
60
|
+
</view>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** The floating capture pill: hidden with no report (the gesture starts one), the whole pill red with a clock while the screen records. */
|
|
65
|
+
export function TesterPanel(props: TesterPanelProps): ReactNode {
|
|
66
|
+
const { engine } = props;
|
|
67
|
+
const s: TesterState = useStore(engine.state);
|
|
68
|
+
const w = wordsOf(props.language);
|
|
69
|
+
const [form, setForm] = useState(false);
|
|
70
|
+
const [confirm, setConfirm] = useState(false);
|
|
71
|
+
const [now, setNow] = useState(Date.now());
|
|
72
|
+
const bg = props.colors?.bg ?? 'rgba(20,26,40,0.92)';
|
|
73
|
+
const fg = props.colors?.fg ?? '#e6eaf2';
|
|
74
|
+
const red = props.colors?.red ?? '#d8434a';
|
|
75
|
+
const accent = props.colors?.accent ?? '#0d8f84';
|
|
76
|
+
const recordingScreen = s.recording.screen;
|
|
77
|
+
// The clock ticks only while something records (Lynx's background thread has setTimeout through the runtime).
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
if (!recordingScreen && !s.recording.voice) return undefined;
|
|
80
|
+
const id = setInterval(() => setNow(Date.now()), 1000);
|
|
81
|
+
return () => clearInterval(id);
|
|
82
|
+
}, [recordingScreen, s.recording.voice]);
|
|
83
|
+
if (!s.enabled) return null;
|
|
84
|
+
const draft = s.draft;
|
|
85
|
+
if (!draft && !s.showButton && s.gestureSupported) return null;
|
|
86
|
+
if (s.capturing) return null; // the tester documents the APP, not this pill
|
|
87
|
+
const box = { position: 'fixed', bottom: '96px', right: '16px', display: 'flex', flexDirection: 'row', alignItems: 'center', padding: '4px', borderRadius: '24px', ...(props.style ?? {}) } as Record<string, string | number>;
|
|
88
|
+
if (!draft) {
|
|
89
|
+
return (
|
|
90
|
+
<view style={{ ...box, backgroundColor: bg }}>
|
|
91
|
+
<Button label={`+ ${w.start}`} onTap={() => void engine.screenshot()} fg={fg} accent={accent} />
|
|
92
|
+
</view>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
const elapsed = s.recordingStartedMs ? now - s.recordingStartedMs : 0;
|
|
96
|
+
if (recordingScreen) {
|
|
97
|
+
return (
|
|
98
|
+
<view style={{ ...box, backgroundColor: red }}>
|
|
99
|
+
<text style={{ color: '#ffffff', fontSize: '14px', fontWeight: 'bold', marginLeft: '12px', marginRight: '8px' }}>{`● ${clock(elapsed)}`}</text>
|
|
100
|
+
<Button label={`■ ${w.stop}`} onTap={() => void engine.toggleScreen()} fg="#ffffff" accent={accent} />
|
|
101
|
+
</view>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
return (
|
|
105
|
+
<view>
|
|
106
|
+
<view style={{ ...box, backgroundColor: bg }}>
|
|
107
|
+
{s.recording.voice ? <text style={{ color: red, fontSize: '14px', fontWeight: 'bold', marginLeft: '10px', marginRight: '4px' }}>{`● ${clock(elapsed)}`}</text> : null}
|
|
108
|
+
<Button label={w.send} strong onTap={() => setForm(true)} fg={fg} accent={accent} badge={draft.attachments.length} />
|
|
109
|
+
<Button label={w.screenshot} onTap={() => void engine.screenshot()} fg={fg} accent={accent} />
|
|
110
|
+
{s.support.screen ? <Button label={w.record} onTap={() => void engine.toggleScreen()} fg={fg} accent={accent} /> : null}
|
|
111
|
+
{s.support.voice ? <Button label={s.recording.voice ? w.stopVoice : w.voice} onTap={() => void engine.toggleVoice()} fg={fg} accent={accent} /> : null}
|
|
112
|
+
<Button label={w.attach} onTap={() => void engine.attach()} fg={fg} accent={accent} />
|
|
113
|
+
<Button label={w.discard} onTap={() => setConfirm(true)} fg={fg} accent={accent} />
|
|
114
|
+
</view>
|
|
115
|
+
{confirm ? (
|
|
116
|
+
<Sheet onClose={() => setConfirm(false)}>
|
|
117
|
+
<text style={{ fontSize: '16px', marginBottom: '16px' }}>{w.confirmDiscard}</text>
|
|
118
|
+
<view style={{ display: 'flex', flexDirection: 'row' }}>
|
|
119
|
+
<Button label={w.yes} strong onTap={() => { setConfirm(false); void engine.discard(); }} fg={fg} accent={red} />
|
|
120
|
+
<Button label={w.no} onTap={() => setConfirm(false)} fg="#46526a" accent={accent} />
|
|
121
|
+
</view>
|
|
122
|
+
</Sheet>
|
|
123
|
+
) : null}
|
|
124
|
+
{form ? <TesterForm engine={engine} language={props.language} onClose={() => setForm(false)} /> : null}
|
|
125
|
+
</view>
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function Sheet(p: { readonly onClose: () => void; readonly children: ReactNode }): ReactNode {
|
|
130
|
+
return (
|
|
131
|
+
<view style={{ position: 'fixed', left: '0px', right: '0px', top: '0px', bottom: '0px', backgroundColor: 'rgba(0,0,0,0.45)', display: 'flex', flexDirection: 'column', justifyContent: 'flex-end' }} bindtap={p.onClose}>
|
|
132
|
+
<view catchtap={() => undefined} style={{ backgroundColor: '#ffffff', borderTopLeftRadius: '18px', borderTopRightRadius: '18px', padding: '20px', paddingBottom: '36px' }}>
|
|
133
|
+
{p.children}
|
|
134
|
+
</view>
|
|
135
|
+
</view>
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** The send form: the kind, the tester's own words (the one box), the database backup and — when the fleet asks — the AI. */
|
|
140
|
+
export function TesterForm(props: { readonly engine: TesterEngine; readonly language: () => DiagLanguage; readonly onClose: () => void }): ReactNode {
|
|
141
|
+
const { engine } = props;
|
|
142
|
+
const w = wordsOf(props.language);
|
|
143
|
+
const t = engine.translate;
|
|
144
|
+
const s = useStore(engine.state);
|
|
145
|
+
const kinds: readonly TesterReportKind[] = engine.kinds;
|
|
146
|
+
const [kind, setKind] = useState<string>(s.draft?.kind ?? kinds[0]?.key ?? 'bug');
|
|
147
|
+
const [words, setWords] = useState<string>(s.draft?.description ?? '');
|
|
148
|
+
const [backup, setBackup] = useState<boolean>(s.draft?.includeDatabaseBackup ?? false);
|
|
149
|
+
const [ai, setAi] = useState<boolean>(true);
|
|
150
|
+
const [sending, setSending] = useState(false);
|
|
151
|
+
const required = engine.descriptionRequired(s.draft) && words.trim().length === 0;
|
|
152
|
+
const label = (k: TesterReportKind) => (typeof k.label === 'function' ? k.label(t) : t(k.label));
|
|
153
|
+
const chip = (on: boolean): CSSProperties => ({ paddingLeft: '12px', paddingRight: '12px', height: '34px', borderRadius: '17px', marginRight: '6px', marginBottom: '6px', display: 'flex', alignItems: 'center', backgroundColor: on ? '#0d8f84' : '#eef1f6' });
|
|
154
|
+
const send = async () => {
|
|
155
|
+
if (sending || required) return;
|
|
156
|
+
setSending(true);
|
|
157
|
+
const ok = await engine.send({ words, kind, includeDatabaseBackup: backup, ...(engine.asksAboutAi ? { useAi: ai } : {}) });
|
|
158
|
+
setSending(false);
|
|
159
|
+
if (ok) props.onClose();
|
|
160
|
+
};
|
|
161
|
+
return (
|
|
162
|
+
<Sheet onClose={props.onClose}>
|
|
163
|
+
<text style={{ fontSize: '18px', fontWeight: 'bold', marginBottom: '12px' }}>{w.review}</text>
|
|
164
|
+
<text style={{ fontSize: '13px', color: '#46526a', marginBottom: '6px' }}>{w.kind}</text>
|
|
165
|
+
<view style={{ display: 'flex', flexDirection: 'row', flexWrap: 'wrap', marginBottom: '10px' }}>
|
|
166
|
+
{kinds.map((k) => (
|
|
167
|
+
<view key={k.key} bindtap={() => setKind(k.key)} style={chip(kind === k.key)}>
|
|
168
|
+
<text style={{ color: kind === k.key ? '#ffffff' : '#172033', fontSize: '14px' }}>{label(k)}</text>
|
|
169
|
+
</view>
|
|
170
|
+
))}
|
|
171
|
+
</view>
|
|
172
|
+
<textarea
|
|
173
|
+
default-value={words}
|
|
174
|
+
placeholder={w.words}
|
|
175
|
+
bindinput={(e: { detail: { value: string } }) => setWords(e.detail.value)}
|
|
176
|
+
style={{ minHeight: '110px', borderWidth: '1px', borderColor: required ? '#c2283a' : '#d6dbe4', borderStyle: 'solid', borderRadius: '12px', padding: '10px', fontSize: '15px', marginBottom: '10px' }}
|
|
177
|
+
/>
|
|
178
|
+
{required ? <text style={{ color: '#c2283a', fontSize: '13px', marginBottom: '8px' }}>{t('TesterPanelDescriptionRequired')}</text> : null}
|
|
179
|
+
<text style={{ fontSize: '13px', color: '#46526a', marginBottom: '10px' }}>{`${s.draft?.attachments.length ?? 0} ${w.evidence}`}</text>
|
|
180
|
+
{engine.offersDatabaseBackup ? (
|
|
181
|
+
<view bindtap={() => setBackup(!backup)} style={{ display: 'flex', flexDirection: 'row', alignItems: 'center', marginBottom: '8px' }}>
|
|
182
|
+
<text style={{ fontSize: '15px' }}>{`${backup ? '☑' : '☐'} ${w.backup}`}</text>
|
|
183
|
+
</view>
|
|
184
|
+
) : null}
|
|
185
|
+
{engine.asksAboutAi ? (
|
|
186
|
+
<view bindtap={() => setAi(!ai)} style={{ display: 'flex', flexDirection: 'row', alignItems: 'center', marginBottom: '8px' }}>
|
|
187
|
+
<text style={{ fontSize: '15px' }}>{`${ai ? '☑' : '☐'} ${w.ai}`}</text>
|
|
188
|
+
</view>
|
|
189
|
+
) : null}
|
|
190
|
+
<view style={{ display: 'flex', flexDirection: 'row', marginTop: '10px' }}>
|
|
191
|
+
<Button label={sending ? '…' : w.send} strong onTap={() => void send()} fg="#172033" accent={required ? '#9aa6b8' : '#0d8f84'} />
|
|
192
|
+
<Button label={w.cancel} onTap={props.onClose} fg="#46526a" accent="#0d8f84" />
|
|
193
|
+
</view>
|
|
194
|
+
</Sheet>
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** This device's reports (the gateway's feed) and what still waits in the outbox. */
|
|
199
|
+
export function TesterReports(props: { readonly engine: TesterEngine; readonly language: () => DiagLanguage }): ReactNode {
|
|
200
|
+
const w = wordsOf(props.language);
|
|
201
|
+
const [feed, setFeed] = useState<TesterFeed | null>(null);
|
|
202
|
+
const load = () => { void props.engine.feed().then(setFeed, () => setFeed({ status: 'failed', reports: [], queued: [] })); };
|
|
203
|
+
useEffect(load, [props.engine]);
|
|
204
|
+
const row = { paddingTop: '10px', paddingBottom: '10px', borderBottomWidth: '1px', borderBottomColor: '#e6eaf2', borderBottomStyle: 'solid' };
|
|
205
|
+
return (
|
|
206
|
+
<scroll-view scroll-orientation="vertical" style={{ flex: 1 }}>
|
|
207
|
+
<view style={{ display: 'flex', flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', marginBottom: '8px' }}>
|
|
208
|
+
<text style={{ fontSize: '17px', fontWeight: 'bold' }}>{w.reports}</text>
|
|
209
|
+
<view bindtap={load}><text style={{ color: '#0d8f84', fontSize: '14px' }}>{w.refresh}</text></view>
|
|
210
|
+
</view>
|
|
211
|
+
{feed?.queued.map((title) => (
|
|
212
|
+
<view key={`q-${title}`} style={row}><text style={{ fontSize: '14px' }}>{`⏳ ${title}`}</text><text style={{ fontSize: '12px', color: '#7b8594' }}>{w.queued}</text></view>
|
|
213
|
+
))}
|
|
214
|
+
{feed?.status === 'failed' ? <text style={{ color: '#c2283a' }}>{w.loadFailed}</text> : null}
|
|
215
|
+
{feed && feed.reports.length === 0 && feed.queued.length === 0 && feed.status !== 'failed' ? <text style={{ color: '#7b8594' }}>{w.none}</text> : null}
|
|
216
|
+
{feed?.reports.map((r) => (
|
|
217
|
+
<view key={r.reportId} style={row}>
|
|
218
|
+
<text style={{ fontSize: '14px', fontWeight: 'bold' }}>{`${r.code} · ${r.title}`}</text>
|
|
219
|
+
<text style={{ fontSize: '12px', color: '#7b8594' }}>{[r.state, r.outcome, r.jiraKey, r.appVersion].filter(Boolean).join(' · ')}</text>
|
|
220
|
+
</view>
|
|
221
|
+
))}
|
|
222
|
+
</scroll-view>
|
|
223
|
+
);
|
|
224
|
+
}
|