@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.
Files changed (40) hide show
  1. package/Cargo.toml +18 -0
  2. package/README.md +21 -3
  3. package/android/build.gradle.kts +29 -0
  4. package/android/proguard-rules.pro +2 -0
  5. package/android/settings.gradle +2 -0
  6. package/android/src/main/AndroidManifest.xml +5 -0
  7. package/android/src/main/java/com/g9tm/appdiagnostic/G9AppDiagnosticHost.kt +131 -0
  8. package/android/src/main/java/com/g9tm/appdiagnostic/RemoteTouch.kt +67 -0
  9. package/android/src/main/java/com/g9tm/appdiagnostic/ScreenRecorder.kt +250 -0
  10. package/android/src/main/java/com/g9tm/appdiagnostic/TouchWatcher.kt +129 -0
  11. package/android/src/main/java/com/g9tm/appdiagnostic/VoiceRecorder.kt +82 -0
  12. package/android/src/main/java/com/g9tm/appdiagnostic/WindowCapture.kt +92 -0
  13. package/android/src/main/java/com/g9tm/appdiagnostic/core/TouchCore.kt +270 -0
  14. package/android/src/main/java/com/g9tm/appdiagnostic/tauri/G9DiagnosticPlugin.kt +180 -0
  15. package/build.rs +13 -0
  16. package/ios/Package.swift +20 -0
  17. package/ios/Sources/G9AppDiagnosticCore/G9AppDiagnosticHost.m +72 -0
  18. package/ios/Sources/G9AppDiagnosticCore/G9DiagnosticRecorders.m +514 -0
  19. package/ios/Sources/G9AppDiagnosticCore/include/G9AppDiagnosticHost.h +32 -0
  20. package/ios/Sources/G9AppDiagnosticCore/include/G9DiagnosticRecorders.h +36 -0
  21. package/ios/Sources/G9DiagnosticPlugin/G9DiagnosticPlugin.swift +135 -0
  22. package/package.json +43 -6
  23. package/permissions/autogenerated/commands/capabilities.toml +13 -0
  24. package/permissions/autogenerated/commands/read_chunk.toml +13 -0
  25. package/permissions/autogenerated/commands/registerListener.toml +13 -0
  26. package/permissions/autogenerated/commands/remove.toml +13 -0
  27. package/permissions/autogenerated/commands/remove_listener.toml +13 -0
  28. package/permissions/autogenerated/commands/screenshot.toml +13 -0
  29. package/permissions/autogenerated/commands/start_screen.toml +13 -0
  30. package/permissions/autogenerated/commands/start_voice.toml +13 -0
  31. package/permissions/autogenerated/commands/state.toml +13 -0
  32. package/permissions/autogenerated/commands/stop_screen.toml +13 -0
  33. package/permissions/autogenerated/commands/stop_voice.toml +13 -0
  34. package/permissions/autogenerated/commands/touch.toml +13 -0
  35. package/permissions/autogenerated/commands/watch_touches.toml +13 -0
  36. package/permissions/autogenerated/reference.md +367 -0
  37. package/permissions/default.toml +9 -0
  38. package/permissions/schemas/schema.json +462 -0
  39. package/src/index.ts +97 -0
  40. package/src/lib.rs +119 -0
@@ -0,0 +1,462 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "title": "PermissionFile",
4
+ "description": "Permission file that can define a default permission, a set of permissions or a list of inlined permissions.",
5
+ "type": "object",
6
+ "properties": {
7
+ "default": {
8
+ "description": "The default permission set for the plugin",
9
+ "anyOf": [
10
+ {
11
+ "$ref": "#/definitions/DefaultPermission"
12
+ },
13
+ {
14
+ "type": "null"
15
+ }
16
+ ]
17
+ },
18
+ "set": {
19
+ "description": "A list of permissions sets defined",
20
+ "type": "array",
21
+ "items": {
22
+ "$ref": "#/definitions/PermissionSet"
23
+ }
24
+ },
25
+ "permission": {
26
+ "description": "A list of inlined permissions",
27
+ "default": [],
28
+ "type": "array",
29
+ "items": {
30
+ "$ref": "#/definitions/Permission"
31
+ }
32
+ }
33
+ },
34
+ "definitions": {
35
+ "DefaultPermission": {
36
+ "description": "The default permission set of the plugin.\n\nWorks similarly to a permission with the \"default\" identifier.",
37
+ "type": "object",
38
+ "required": [
39
+ "permissions"
40
+ ],
41
+ "properties": {
42
+ "version": {
43
+ "description": "The version of the permission.",
44
+ "type": [
45
+ "integer",
46
+ "null"
47
+ ],
48
+ "format": "uint64",
49
+ "minimum": 1.0
50
+ },
51
+ "description": {
52
+ "description": "Human-readable description of what the permission does. Tauri convention is to use `<h4>` headings in markdown content for Tauri documentation generation purposes.",
53
+ "type": [
54
+ "string",
55
+ "null"
56
+ ]
57
+ },
58
+ "permissions": {
59
+ "description": "All permissions this set contains.",
60
+ "type": "array",
61
+ "items": {
62
+ "type": "string"
63
+ }
64
+ }
65
+ }
66
+ },
67
+ "PermissionSet": {
68
+ "description": "A set of direct permissions grouped together under a new name.",
69
+ "type": "object",
70
+ "required": [
71
+ "description",
72
+ "identifier",
73
+ "permissions"
74
+ ],
75
+ "properties": {
76
+ "identifier": {
77
+ "description": "A unique identifier for the permission.",
78
+ "type": "string"
79
+ },
80
+ "description": {
81
+ "description": "Human-readable description of what the permission does.",
82
+ "type": "string"
83
+ },
84
+ "permissions": {
85
+ "description": "All permissions this set contains.",
86
+ "type": "array",
87
+ "items": {
88
+ "$ref": "#/definitions/PermissionKind"
89
+ }
90
+ }
91
+ }
92
+ },
93
+ "Permission": {
94
+ "description": "Descriptions of explicit privileges of commands.\n\nIt can enable commands to be accessible in the frontend of the application.\n\nIf the scope is defined it can be used to fine grain control the access of individual or multiple commands.",
95
+ "type": "object",
96
+ "required": [
97
+ "identifier"
98
+ ],
99
+ "properties": {
100
+ "version": {
101
+ "description": "The version of the permission.",
102
+ "type": [
103
+ "integer",
104
+ "null"
105
+ ],
106
+ "format": "uint64",
107
+ "minimum": 1.0
108
+ },
109
+ "identifier": {
110
+ "description": "A unique identifier for the permission.",
111
+ "type": "string"
112
+ },
113
+ "description": {
114
+ "description": "Human-readable description of what the permission does. Tauri internal convention is to use `<h4>` headings in markdown content for Tauri documentation generation purposes.",
115
+ "type": [
116
+ "string",
117
+ "null"
118
+ ]
119
+ },
120
+ "commands": {
121
+ "description": "Allowed or denied commands when using this permission.",
122
+ "default": {
123
+ "allow": [],
124
+ "deny": []
125
+ },
126
+ "allOf": [
127
+ {
128
+ "$ref": "#/definitions/Commands"
129
+ }
130
+ ]
131
+ },
132
+ "scope": {
133
+ "description": "Allowed or denied scoped when using this permission.",
134
+ "allOf": [
135
+ {
136
+ "$ref": "#/definitions/Scopes"
137
+ }
138
+ ]
139
+ },
140
+ "platforms": {
141
+ "description": "Target platforms this permission applies. By default all platforms are affected by this permission.",
142
+ "type": [
143
+ "array",
144
+ "null"
145
+ ],
146
+ "items": {
147
+ "$ref": "#/definitions/Target"
148
+ }
149
+ }
150
+ }
151
+ },
152
+ "Commands": {
153
+ "description": "Allowed and denied commands inside a permission.\n\nIf two commands clash inside of `allow` and `deny`, it should be denied by default.",
154
+ "type": "object",
155
+ "properties": {
156
+ "allow": {
157
+ "description": "Allowed command.",
158
+ "default": [],
159
+ "type": "array",
160
+ "items": {
161
+ "type": "string"
162
+ }
163
+ },
164
+ "deny": {
165
+ "description": "Denied command, which takes priority.",
166
+ "default": [],
167
+ "type": "array",
168
+ "items": {
169
+ "type": "string"
170
+ }
171
+ }
172
+ }
173
+ },
174
+ "Scopes": {
175
+ "description": "An argument for fine grained behavior control of Tauri commands.\n\nIt can be of any serde serializable type and is used to allow or prevent certain actions inside a Tauri command. The configured scope is passed to the command and will be enforced by the command implementation.\n\n## Example\n\n```json { \"allow\": [{ \"path\": \"$HOME/**\" }], \"deny\": [{ \"path\": \"$HOME/secret.txt\" }] } ```",
176
+ "type": "object",
177
+ "properties": {
178
+ "allow": {
179
+ "description": "Data that defines what is allowed by the scope.",
180
+ "type": [
181
+ "array",
182
+ "null"
183
+ ],
184
+ "items": {
185
+ "$ref": "#/definitions/Value"
186
+ }
187
+ },
188
+ "deny": {
189
+ "description": "Data that defines what is denied by the scope. This should be prioritized by validation logic.",
190
+ "type": [
191
+ "array",
192
+ "null"
193
+ ],
194
+ "items": {
195
+ "$ref": "#/definitions/Value"
196
+ }
197
+ }
198
+ }
199
+ },
200
+ "Value": {
201
+ "description": "All supported ACL values.",
202
+ "anyOf": [
203
+ {
204
+ "description": "Represents a null JSON value.",
205
+ "type": "null"
206
+ },
207
+ {
208
+ "description": "Represents a [`bool`].",
209
+ "type": "boolean"
210
+ },
211
+ {
212
+ "description": "Represents a valid ACL [`Number`].",
213
+ "allOf": [
214
+ {
215
+ "$ref": "#/definitions/Number"
216
+ }
217
+ ]
218
+ },
219
+ {
220
+ "description": "Represents a [`String`].",
221
+ "type": "string"
222
+ },
223
+ {
224
+ "description": "Represents a list of other [`Value`]s.",
225
+ "type": "array",
226
+ "items": {
227
+ "$ref": "#/definitions/Value"
228
+ }
229
+ },
230
+ {
231
+ "description": "Represents a map of [`String`] keys to [`Value`]s.",
232
+ "type": "object",
233
+ "additionalProperties": {
234
+ "$ref": "#/definitions/Value"
235
+ }
236
+ }
237
+ ]
238
+ },
239
+ "Number": {
240
+ "description": "A valid ACL number.",
241
+ "anyOf": [
242
+ {
243
+ "description": "Represents an [`i64`].",
244
+ "type": "integer",
245
+ "format": "int64"
246
+ },
247
+ {
248
+ "description": "Represents a [`f64`].",
249
+ "type": "number",
250
+ "format": "double"
251
+ }
252
+ ]
253
+ },
254
+ "Target": {
255
+ "description": "Platform target.",
256
+ "oneOf": [
257
+ {
258
+ "description": "MacOS.",
259
+ "type": "string",
260
+ "enum": [
261
+ "macOS"
262
+ ]
263
+ },
264
+ {
265
+ "description": "Windows.",
266
+ "type": "string",
267
+ "enum": [
268
+ "windows"
269
+ ]
270
+ },
271
+ {
272
+ "description": "Linux.",
273
+ "type": "string",
274
+ "enum": [
275
+ "linux"
276
+ ]
277
+ },
278
+ {
279
+ "description": "Android.",
280
+ "type": "string",
281
+ "enum": [
282
+ "android"
283
+ ]
284
+ },
285
+ {
286
+ "description": "iOS.",
287
+ "type": "string",
288
+ "enum": [
289
+ "iOS"
290
+ ]
291
+ }
292
+ ]
293
+ },
294
+ "PermissionKind": {
295
+ "type": "string",
296
+ "oneOf": [
297
+ {
298
+ "description": "Enables the capabilities command without any pre-configured scope.",
299
+ "type": "string",
300
+ "const": "allow-capabilities",
301
+ "markdownDescription": "Enables the capabilities command without any pre-configured scope."
302
+ },
303
+ {
304
+ "description": "Denies the capabilities command without any pre-configured scope.",
305
+ "type": "string",
306
+ "const": "deny-capabilities",
307
+ "markdownDescription": "Denies the capabilities command without any pre-configured scope."
308
+ },
309
+ {
310
+ "description": "Enables the read_chunk command without any pre-configured scope.",
311
+ "type": "string",
312
+ "const": "allow-read-chunk",
313
+ "markdownDescription": "Enables the read_chunk command without any pre-configured scope."
314
+ },
315
+ {
316
+ "description": "Denies the read_chunk command without any pre-configured scope.",
317
+ "type": "string",
318
+ "const": "deny-read-chunk",
319
+ "markdownDescription": "Denies the read_chunk command without any pre-configured scope."
320
+ },
321
+ {
322
+ "description": "Enables the registerListener command without any pre-configured scope.",
323
+ "type": "string",
324
+ "const": "allow-registerListener",
325
+ "markdownDescription": "Enables the registerListener command without any pre-configured scope."
326
+ },
327
+ {
328
+ "description": "Denies the registerListener command without any pre-configured scope.",
329
+ "type": "string",
330
+ "const": "deny-registerListener",
331
+ "markdownDescription": "Denies the registerListener command without any pre-configured scope."
332
+ },
333
+ {
334
+ "description": "Enables the remove command without any pre-configured scope.",
335
+ "type": "string",
336
+ "const": "allow-remove",
337
+ "markdownDescription": "Enables the remove command without any pre-configured scope."
338
+ },
339
+ {
340
+ "description": "Denies the remove command without any pre-configured scope.",
341
+ "type": "string",
342
+ "const": "deny-remove",
343
+ "markdownDescription": "Denies the remove command without any pre-configured scope."
344
+ },
345
+ {
346
+ "description": "Enables the remove_listener command without any pre-configured scope.",
347
+ "type": "string",
348
+ "const": "allow-remove-listener",
349
+ "markdownDescription": "Enables the remove_listener command without any pre-configured scope."
350
+ },
351
+ {
352
+ "description": "Denies the remove_listener command without any pre-configured scope.",
353
+ "type": "string",
354
+ "const": "deny-remove-listener",
355
+ "markdownDescription": "Denies the remove_listener command without any pre-configured scope."
356
+ },
357
+ {
358
+ "description": "Enables the screenshot command without any pre-configured scope.",
359
+ "type": "string",
360
+ "const": "allow-screenshot",
361
+ "markdownDescription": "Enables the screenshot command without any pre-configured scope."
362
+ },
363
+ {
364
+ "description": "Denies the screenshot command without any pre-configured scope.",
365
+ "type": "string",
366
+ "const": "deny-screenshot",
367
+ "markdownDescription": "Denies the screenshot command without any pre-configured scope."
368
+ },
369
+ {
370
+ "description": "Enables the start_screen command without any pre-configured scope.",
371
+ "type": "string",
372
+ "const": "allow-start-screen",
373
+ "markdownDescription": "Enables the start_screen command without any pre-configured scope."
374
+ },
375
+ {
376
+ "description": "Denies the start_screen command without any pre-configured scope.",
377
+ "type": "string",
378
+ "const": "deny-start-screen",
379
+ "markdownDescription": "Denies the start_screen command without any pre-configured scope."
380
+ },
381
+ {
382
+ "description": "Enables the start_voice command without any pre-configured scope.",
383
+ "type": "string",
384
+ "const": "allow-start-voice",
385
+ "markdownDescription": "Enables the start_voice command without any pre-configured scope."
386
+ },
387
+ {
388
+ "description": "Denies the start_voice command without any pre-configured scope.",
389
+ "type": "string",
390
+ "const": "deny-start-voice",
391
+ "markdownDescription": "Denies the start_voice command without any pre-configured scope."
392
+ },
393
+ {
394
+ "description": "Enables the state command without any pre-configured scope.",
395
+ "type": "string",
396
+ "const": "allow-state",
397
+ "markdownDescription": "Enables the state command without any pre-configured scope."
398
+ },
399
+ {
400
+ "description": "Denies the state command without any pre-configured scope.",
401
+ "type": "string",
402
+ "const": "deny-state",
403
+ "markdownDescription": "Denies the state command without any pre-configured scope."
404
+ },
405
+ {
406
+ "description": "Enables the stop_screen command without any pre-configured scope.",
407
+ "type": "string",
408
+ "const": "allow-stop-screen",
409
+ "markdownDescription": "Enables the stop_screen command without any pre-configured scope."
410
+ },
411
+ {
412
+ "description": "Denies the stop_screen command without any pre-configured scope.",
413
+ "type": "string",
414
+ "const": "deny-stop-screen",
415
+ "markdownDescription": "Denies the stop_screen command without any pre-configured scope."
416
+ },
417
+ {
418
+ "description": "Enables the stop_voice command without any pre-configured scope.",
419
+ "type": "string",
420
+ "const": "allow-stop-voice",
421
+ "markdownDescription": "Enables the stop_voice command without any pre-configured scope."
422
+ },
423
+ {
424
+ "description": "Denies the stop_voice command without any pre-configured scope.",
425
+ "type": "string",
426
+ "const": "deny-stop-voice",
427
+ "markdownDescription": "Denies the stop_voice command without any pre-configured scope."
428
+ },
429
+ {
430
+ "description": "Enables the touch command without any pre-configured scope.",
431
+ "type": "string",
432
+ "const": "allow-touch",
433
+ "markdownDescription": "Enables the touch command without any pre-configured scope."
434
+ },
435
+ {
436
+ "description": "Denies the touch command without any pre-configured scope.",
437
+ "type": "string",
438
+ "const": "deny-touch",
439
+ "markdownDescription": "Denies the touch command without any pre-configured scope."
440
+ },
441
+ {
442
+ "description": "Enables the watch_touches command without any pre-configured scope.",
443
+ "type": "string",
444
+ "const": "allow-watch-touches",
445
+ "markdownDescription": "Enables the watch_touches command without any pre-configured scope."
446
+ },
447
+ {
448
+ "description": "Denies the watch_touches command without any pre-configured scope.",
449
+ "type": "string",
450
+ "const": "deny-watch-touches",
451
+ "markdownDescription": "Denies the watch_touches command without any pre-configured scope."
452
+ },
453
+ {
454
+ "description": "Every command of the tester mode: the recorders, the screenshot, the tester gesture (its event channel too), the remote touch and the plugin's own files.\n#### This default permission set includes:\n\n- `allow-capabilities`\n- `allow-state`\n- `allow-start-screen`\n- `allow-stop-screen`\n- `allow-start-voice`\n- `allow-stop-voice`\n- `allow-screenshot`\n- `allow-watch-touches`\n- `allow-touch`\n- `allow-read-chunk`\n- `allow-remove`\n- `allow-registerListener`\n- `allow-remove-listener`",
455
+ "type": "string",
456
+ "const": "default",
457
+ "markdownDescription": "Every command of the tester mode: the recorders, the screenshot, the tester gesture (its event channel too), the remote touch and the plugin's own files.\n#### This default permission set includes:\n\n- `allow-capabilities`\n- `allow-state`\n- `allow-start-screen`\n- `allow-stop-screen`\n- `allow-start-voice`\n- `allow-stop-voice`\n- `allow-screenshot`\n- `allow-watch-touches`\n- `allow-touch`\n- `allow-read-chunk`\n- `allow-remove`\n- `allow-registerListener`\n- `allow-remove-listener`"
458
+ }
459
+ ]
460
+ }
461
+ }
462
+ }
package/src/index.ts ADDED
@@ -0,0 +1,97 @@
1
+ // @g9tm/app-diagnostic-tauri — the tester mode of a Tauri v2 app (0.5.0): the JS side of tauri-plugin-g9-diagnostic.
2
+ // On Android and iOS the recorders are native (the real screen, a map's surface included; the gesture held away from the
3
+ // views); on a desktop the plugin answers «no native half» and the web recorders of @g9tm/app-diagnostic-web work
4
+ // (getDisplayMedia in WebView2, the page drawn into a canvas elsewhere).
5
+ //
6
+ // import { startTauriTester } from '@g9tm/app-diagnostic-tauri';
7
+ // const tester = await startTauriTester({ gateway, appId, productName, appVersion, environment });
8
+ // tester.engine.setEnabled(true);
9
+ // (= @g9tm/app-diagnostic-web's startTester with media: tauriMedia and the platform tauri-android, tauri-ios, tauri-windows…)
10
+ //
11
+ // Rust: .plugin(tauri_plugin_g9_diagnostic::init()); capability: "g9-diagnostic:default".
12
+ import { addPluginListener, invoke } from '@tauri-apps/api/core';
13
+ import type { MediaRecording, TesterMedia, TesterTouchEvent, Unsubscribe } from '@g9tm/app-diagnostic';
14
+ import { type ByteStore, inside, ROOT, startTester, type StartTesterOptions, type Tester } from '@g9tm/app-diagnostic-web';
15
+
16
+ const call = <T>(command: string, args: Record<string, unknown> = {}) => invoke<T>(`plugin:g9-diagnostic|${command}`, { args });
17
+
18
+ interface NativeRecording { path: string; bytes: number; durationMs: number; capped?: boolean }
19
+
20
+ const CHUNK = 512 * 1024;
21
+ const unb64 = (text: string): Uint8Array => Uint8Array.from(atob(text), (c) => c.charCodeAt(0));
22
+
23
+ async function adopt(store: ByteStore, nativePath: string, webPath: string): Promise<number> {
24
+ const target = inside(webPath);
25
+ let offset = 0;
26
+ await store.remove(target);
27
+ for (;;) {
28
+ const { data } = await call<{ data: string }>('read_chunk', { path: nativePath, offset, length: CHUNK });
29
+ if (!data) break;
30
+ const bytes = unb64(data);
31
+ await store.write(target, bytes, offset > 0);
32
+ offset += bytes.length;
33
+ if (bytes.length < CHUNK) break;
34
+ }
35
+ await call('remove', { path: nativePath }).catch(() => undefined);
36
+ return offset;
37
+ }
38
+
39
+ /**
40
+ * The TesterMedia over the plugin where it has a native half (Android, iOS), the browser's (`fallback`) where it has not
41
+ * (a desktop) — decided once, by the plugin's `capabilities`.
42
+ */
43
+ export function tauriMedia(fallback: TesterMedia, store: ByteStore): TesterMedia {
44
+ const native = call<{ native?: boolean; screen: boolean; voice: boolean }>('capabilities').then((c) => (c.native ? c : null), () => null);
45
+ const listeners = new Set<(e: TesterTouchEvent) => void>();
46
+ let listening = false;
47
+ let screenDir = `${ROOT}/drafts`, voiceDir = `${ROOT}/drafts`;
48
+ const done = async (r: NativeRecording | null, dir: string, kind: string): Promise<MediaRecording | null> => {
49
+ if (!r) return null;
50
+ const path = `${dir}/${kind}-${Date.now()}${r.path.slice(r.path.lastIndexOf('.'))}`;
51
+ const bytes = await adopt(store, r.path, path);
52
+ return bytes > 0 ? { path: inside(path), bytes, durationMs: r.durationMs, ...(r.capped ? { capped: true } : {}) } : null;
53
+ };
54
+ const either = async <T>(n: () => Promise<T>, f: () => Promise<T>): Promise<T> => ((await native) ? n() : f());
55
+ return {
56
+ support: () => either(async () => { const c = (await native)!; return { screen: c.screen, voice: c.voice }; }, () => fallback.support()),
57
+ state: () => either(() => call<{ screen: boolean; voice: boolean }>('state'), () => fallback.state()),
58
+ startScreen: (dir, o) => either(async () => { screenDir = dir; await call('start_screen', { maxFps: o.maxFps }); }, () => fallback.startScreen(dir, o)),
59
+ stopScreen: () => either(async () => done((await call<{ recording: NativeRecording | null }>('stop_screen')).recording, screenDir, 'screen'), () => fallback.stopScreen()),
60
+ startVoice: (dir) => either(async () => { voiceDir = dir; await call('start_voice'); }, () => fallback.startVoice(dir)),
61
+ stopVoice: () => either(async () => done((await call<{ recording: NativeRecording | null }>('stop_voice')).recording, voiceDir, 'voice'), () => fallback.stopVoice()),
62
+ screenshot: (maxEdge, quality) => either(async () => {
63
+ const shot = await call<{ path: string }>('screenshot', { maxEdge, quality });
64
+ const path = `${ROOT}/shots/shot-${Date.now()}.jpg`;
65
+ await adopt(store, shot.path, path);
66
+ return { path: inside(path) };
67
+ }, () => fallback.screenshot(maxEdge, quality)),
68
+ pick: (mimes) => fallback.pick(mimes),
69
+ watchTouches: (o) => either(async () => {
70
+ if (!listening) {
71
+ listening = true;
72
+ await addPluginListener('g9-diagnostic', 'touch', (p: { json: string }) => {
73
+ try {
74
+ const e = JSON.parse(p.json) as { type: string; fingers: number; x: number; y: number; cx?: number; cy?: number; excluded?: boolean };
75
+ if (e.type === 'tap' || e.type === 'down') listeners.forEach((l) => l({ type: e.type as 'tap' | 'down', fingers: e.fingers, x: e.cx ?? e.x, y: e.cy ?? e.y, excluded: !!e.excluded }));
76
+ } catch { /* not a touch */ }
77
+ });
78
+ }
79
+ await call('watch_touches', { taps: o.gesture, touches: o.touches, consume: !!o.consume, excludeSurfaces: !!o.excludeSurfaces });
80
+ }, () => fallback.watchTouches(o)),
81
+ onTouch(listener): Unsubscribe {
82
+ listeners.add(listener);
83
+ const off = fallback.onTouch(listener); // a desktop's pointer events and shortcut
84
+ return () => { listeners.delete(listener); off(); };
85
+ },
86
+ };
87
+ }
88
+
89
+ /** The operator's remote touch on the native half (Android: a real gesture; iOS: a logical tap; a desktop: refused). */
90
+ export const remoteTouch = (kind: 'tap' | 'longPress' | 'drag', x: number, y: number, toX = x, toY = y, durationMs = kind === 'longPress' ? 800 : kind === 'drag' ? 300 : 50) =>
91
+ call<{ handled: boolean }>('touch', { kind, x, y, toX, toY, durationMs }).then((r) => r.handled, () => false);
92
+
93
+ /** The tester mode of a Tauri app in one call: the web layer with the native recorders where there are some, the platform named. */
94
+ export async function startTauriTester(o: Omit<StartTesterOptions, 'media' | 'platform'>): Promise<Tester> {
95
+ const platform = await call<{ platform?: string }>('capabilities').then((c) => c.platform ?? 'desktop', () => 'desktop');
96
+ return startTester({ ...o, media: tauriMedia, platform: `tauri-${platform}` });
97
+ }
package/src/lib.rs ADDED
@@ -0,0 +1,119 @@
1
+ //! tauri-plugin-g9-diagnostic (0.5.0): the tester mode of a Tauri v2 app.
2
+ //!
3
+ //! On Android and iOS every command goes to the mobile half — the SAME recorders, window capture, gesture and remote touch
4
+ //! as @g9tm/app-diagnostic-lynx (copied, never edited, by scripts/sync-native.mjs). On a desktop the commands answer
5
+ //! «unavailable» and the web layer (@g9tm/app-diagnostic-web: getDisplayMedia in WebView2, the page drawn elsewhere) does
6
+ //! the work — the JS side (@g9tm/app-diagnostic-tauri) asks `capabilities` and falls back by itself.
7
+ //!
8
+ //! ```ignore
9
+ //! tauri::Builder::default().plugin(tauri_plugin_g9_diagnostic::init())
10
+ //! ```
11
+ //! and in the capability file: `"permissions": ["g9-diagnostic:default"]`.
12
+
13
+ use serde_json::Value;
14
+ use tauri::{
15
+ plugin::{Builder, TauriPlugin},
16
+ Manager, Runtime,
17
+ };
18
+
19
+ #[cfg(target_os = "ios")]
20
+ tauri::ios_plugin_binding!(init_plugin_g9_diagnostic);
21
+
22
+ /// A failure with the module's code (types/g9-app-diagnostic-module.d.ts of the Lynx package).
23
+ #[derive(Debug, thiserror::Error)]
24
+ pub enum Error {
25
+ #[error("{0}")]
26
+ Unavailable(String),
27
+ #[cfg(mobile)]
28
+ #[error(transparent)]
29
+ Mobile(#[from] tauri::plugin::mobile::PluginInvokeError),
30
+ }
31
+
32
+ impl serde::Serialize for Error {
33
+ fn serialize<S: serde::Serializer>(&self, s: S) -> std::result::Result<S::Ok, S::Error> {
34
+ use serde::ser::SerializeMap;
35
+ let mut m = s.serialize_map(Some(2))?;
36
+ match self {
37
+ Error::Unavailable(msg) => {
38
+ m.serialize_entry("code", "unavailable")?;
39
+ m.serialize_entry("message", msg)?;
40
+ }
41
+ #[cfg(mobile)]
42
+ Error::Mobile(e) => {
43
+ m.serialize_entry("code", "io")?;
44
+ m.serialize_entry("message", &e.to_string())?;
45
+ }
46
+ }
47
+ m.end()
48
+ }
49
+ }
50
+
51
+ type Result<T> = std::result::Result<T, Error>;
52
+
53
+ /// The mobile half (a handle to it), or the desktop's «no native half».
54
+ pub struct G9Diagnostic<R: Runtime> {
55
+ #[cfg(mobile)]
56
+ handle: tauri::plugin::PluginHandle<R>,
57
+ #[cfg(desktop)]
58
+ _r: std::marker::PhantomData<fn() -> R>,
59
+ }
60
+
61
+ impl<R: Runtime> G9Diagnostic<R> {
62
+ /// One command of the native half with its arguments (JSON), its answer as JSON.
63
+ pub fn call(&self, command: &str, args: Value) -> Result<Value> {
64
+ #[cfg(mobile)]
65
+ {
66
+ return self.handle.run_mobile_plugin::<Value>(command, args).map_err(Into::into);
67
+ }
68
+ #[cfg(desktop)]
69
+ {
70
+ let _ = args;
71
+ if command == "capabilities" {
72
+ return Ok(serde_json::json!({ "version": "0.5.0", "platform": std::env::consts::OS, "screen": false, "voice": false, "consume": false, "native": false }));
73
+ }
74
+ Err(Error::Unavailable(format!("«{command}» has no native half on a desktop: the web layer records")))
75
+ }
76
+ }
77
+ }
78
+
79
+ macro_rules! command {
80
+ ($name:ident, $native:literal) => {
81
+ #[tauri::command]
82
+ async fn $name<R: Runtime>(app: tauri::AppHandle<R>, args: Option<Value>) -> Result<Value> {
83
+ app.state::<G9Diagnostic<R>>().call($native, args.unwrap_or(Value::Object(Default::default())))
84
+ }
85
+ };
86
+ }
87
+
88
+ command!(capabilities, "capabilities");
89
+ command!(state, "state");
90
+ command!(start_screen, "startScreen");
91
+ command!(stop_screen, "stopScreen");
92
+ command!(start_voice, "startVoice");
93
+ command!(stop_voice, "stopVoice");
94
+ command!(screenshot, "screenshot");
95
+ command!(watch_touches, "watchTouches");
96
+ command!(touch, "touch");
97
+ command!(read_chunk, "readChunk");
98
+ command!(remove, "remove");
99
+
100
+ /// The plugin: `.plugin(tauri_plugin_g9_diagnostic::init())`.
101
+ pub fn init<R: Runtime>() -> TauriPlugin<R> {
102
+ Builder::new("g9-diagnostic")
103
+ .invoke_handler(tauri::generate_handler![capabilities, state, start_screen, stop_screen, start_voice, stop_voice, screenshot, watch_touches, touch, read_chunk, remove])
104
+ .setup(|app, api| {
105
+ #[cfg(target_os = "android")]
106
+ let handle = api.register_android_plugin("com.g9tm.appdiagnostic.tauri", "G9DiagnosticPlugin")?;
107
+ #[cfg(target_os = "ios")]
108
+ let handle = api.register_ios_plugin(init_plugin_g9_diagnostic)?;
109
+ #[cfg(mobile)]
110
+ app.manage(G9Diagnostic::<R> { handle });
111
+ #[cfg(desktop)]
112
+ {
113
+ let _ = api;
114
+ app.manage(G9Diagnostic::<R> { _r: std::marker::PhantomData });
115
+ }
116
+ Ok(())
117
+ })
118
+ .build()
119
+ }