@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
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
#import "G9AppDiagnosticHost.h"
|
|
2
|
+
|
|
3
|
+
static NSURLSession * (^gSession)(void);
|
|
4
|
+
static NSArray<NSString *> * (^gRoots)(void);
|
|
5
|
+
static BOOL (^gExcluded)(UIView *);
|
|
6
|
+
|
|
7
|
+
@implementation G9AppDiagnosticHost
|
|
8
|
+
|
|
9
|
+
+ (NSURLSession * (^)(void))urlSession { return gSession; }
|
|
10
|
+
+ (void)setUrlSession:(NSURLSession * (^)(void))b { gSession = [b copy]; }
|
|
11
|
+
+ (NSArray<NSString *> * (^)(void))allowedRoots { return gRoots; }
|
|
12
|
+
+ (void)setAllowedRoots:(NSArray<NSString *> * (^)(void))b { gRoots = [b copy]; }
|
|
13
|
+
+ (BOOL (^)(UIView *))isExcludedView { return gExcluded; }
|
|
14
|
+
+ (void)setIsExcludedView:(BOOL (^)(UIView *))b { gExcluded = [b copy]; }
|
|
15
|
+
|
|
16
|
+
+ (NSArray<NSString *> *)roots {
|
|
17
|
+
NSArray<NSString *> *raw = gRoots ? gRoots() : @[
|
|
18
|
+
NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES).firstObject ?: NSTemporaryDirectory(),
|
|
19
|
+
NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).firstObject ?: NSTemporaryDirectory(),
|
|
20
|
+
NSTemporaryDirectory(),
|
|
21
|
+
];
|
|
22
|
+
NSMutableArray<NSString *> *out = [NSMutableArray array];
|
|
23
|
+
for (NSString *r in raw) {
|
|
24
|
+
NSString *p = r.stringByStandardizingPath.stringByResolvingSymlinksInPath;
|
|
25
|
+
while (p.length > 1 && [p hasSuffix:@"/"]) p = [p substringToIndex:p.length - 1];
|
|
26
|
+
if (p.length) [out addObject:p];
|
|
27
|
+
}
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
+ (NSString *)inside:(NSString *)path folder:(BOOL)folder {
|
|
32
|
+
if (path.length == 0) return nil;
|
|
33
|
+
NSString *p = path.stringByStandardizingPath.stringByResolvingSymlinksInPath;
|
|
34
|
+
while (p.length > 1 && [p hasSuffix:@"/"]) p = [p substringToIndex:p.length - 1];
|
|
35
|
+
for (NSString *root in [self roots]) {
|
|
36
|
+
if ([p hasPrefix:[root stringByAppendingString:@"/"]]) return p; // strictly inside: never «/rootX» for «/root»
|
|
37
|
+
if (folder && [p isEqualToString:root]) return p;
|
|
38
|
+
}
|
|
39
|
+
return nil;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
+ (UIWindow *)keyWindow {
|
|
43
|
+
UIWindow *any = nil;
|
|
44
|
+
for (UIScene *scene in UIApplication.sharedApplication.connectedScenes) {
|
|
45
|
+
if (![scene isKindOfClass:UIWindowScene.class]) continue;
|
|
46
|
+
for (UIWindow *w in ((UIWindowScene *)scene).windows) {
|
|
47
|
+
if (w.isKeyWindow) return w;
|
|
48
|
+
if (!any && !w.hidden) any = w;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return any;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
+ (CGSize)windowSize {
|
|
55
|
+
UIWindow *w = [self keyWindow];
|
|
56
|
+
return w ? w.bounds.size : CGSizeZero;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
+ (UIImage *)captureWindowAtScale:(CGFloat)scale {
|
|
60
|
+
UIWindow *window = [self keyWindow];
|
|
61
|
+
if (window == nil || CGRectIsEmpty(window.bounds)) return nil;
|
|
62
|
+
UIGraphicsImageRendererFormat *format = [UIGraphicsImageRendererFormat preferredFormat];
|
|
63
|
+
format.scale = scale;
|
|
64
|
+
format.opaque = YES;
|
|
65
|
+
// drawViewHierarchyInRect snapshots the composited screen, Metal layers included (a MapLibre map) — what PixelCopy
|
|
66
|
+
// and the SurfaceView composite give on Android.
|
|
67
|
+
return [[[UIGraphicsImageRenderer alloc] initWithSize:window.bounds.size format:format] imageWithActions:^(UIGraphicsImageRendererContext *ctx) {
|
|
68
|
+
[window drawViewHierarchyInRect:window.bounds afterScreenUpdates:NO];
|
|
69
|
+
}];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// G9AppDiagnosticModule on iOS (types/g9-app-diagnostic-module.d.ts; TWIN: android/…/G9AppDiagnosticModule.kt): the
|
|
2
|
+
// native half of the tester mode and the live channel — the app's own window as an MP4, a spoken note, the window
|
|
3
|
+
// screenshot, a file range sent natively, the tester gesture, and the operator's remote touch.
|
|
4
|
+
// Every reply is {ok: true, value} | {ok: false, error: {code, message}}; work runs off the JS thread.
|
|
5
|
+
//
|
|
6
|
+
// Register it once with the app's LynxConfig (before the first LynxView):
|
|
7
|
+
// #import <G9AppDiagnosticLynx/G9AppDiagnosticModule.h>
|
|
8
|
+
// G9AppDiagnosticRegister(config);
|
|
9
|
+
#import <Foundation/Foundation.h>
|
|
10
|
+
#import <Lynx/LynxContextModule.h>
|
|
11
|
+
#import <Lynx/LynxModule.h>
|
|
12
|
+
|
|
13
|
+
@class LynxConfig;
|
|
14
|
+
|
|
15
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
16
|
+
|
|
17
|
+
@interface G9AppDiagnosticModule : NSObject <LynxContextModule>
|
|
18
|
+
@end
|
|
19
|
+
|
|
20
|
+
/** Registers G9AppDiagnosticModule with a LynxConfig. */
|
|
21
|
+
FOUNDATION_EXPORT void G9AppDiagnosticRegister(LynxConfig *config);
|
|
22
|
+
|
|
23
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
#import "G9AppDiagnosticModule.h"
|
|
2
|
+
|
|
3
|
+
#import <AVFoundation/AVFoundation.h>
|
|
4
|
+
#import <Lynx/LynxConfig.h>
|
|
5
|
+
#import <Lynx/LynxContext.h>
|
|
6
|
+
#import <UIKit/UIKit.h>
|
|
7
|
+
|
|
8
|
+
#import "G9AppDiagnosticHost.h"
|
|
9
|
+
#import "G9DiagnosticRecorders.h"
|
|
10
|
+
|
|
11
|
+
static NSString *const kVersion = @"0.5.0";
|
|
12
|
+
static NSString *const kTouchEvent = @"g9:diagnostic-touch";
|
|
13
|
+
|
|
14
|
+
void G9AppDiagnosticRegister(LynxConfig *config) {
|
|
15
|
+
[config registerModule:G9AppDiagnosticModule.class];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** The live LynxContexts, for the touch event (weak: a torn-down view simply drops out). */
|
|
19
|
+
static NSHashTable<LynxContext *> *G9Contexts(void) {
|
|
20
|
+
static NSHashTable *t;
|
|
21
|
+
static dispatch_once_t once;
|
|
22
|
+
dispatch_once(&once, ^{ t = [NSHashTable weakObjectsHashTable]; });
|
|
23
|
+
return t;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static void G9Emit(NSString *json) {
|
|
27
|
+
NSArray<LynxContext *> *live;
|
|
28
|
+
@synchronized(G9Contexts()) { live = G9Contexts().allObjects; }
|
|
29
|
+
for (LynxContext *c in live) {
|
|
30
|
+
@try { [c sendGlobalEvent:kTouchEvent withParams:@[ json ?: @"{}" ]]; } @catch (NSException *ex) { /* a context going away */ }
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
typedef id _Nullable (^G9Work)(NSError **error);
|
|
35
|
+
|
|
36
|
+
@implementation G9AppDiagnosticModule {
|
|
37
|
+
__weak LynxContext *_context;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
+ (NSString *)name { return @"G9AppDiagnosticModule"; }
|
|
41
|
+
|
|
42
|
+
+ (NSDictionary<NSString *, NSString *> *)methodLookup {
|
|
43
|
+
return @{
|
|
44
|
+
@"capabilities" : NSStringFromSelector(@selector(capabilities:)),
|
|
45
|
+
@"state" : NSStringFromSelector(@selector(state:)),
|
|
46
|
+
@"startScreen" : NSStringFromSelector(@selector(startScreen:maxFps:callback:)),
|
|
47
|
+
@"stopScreen" : NSStringFromSelector(@selector(stopScreen:)),
|
|
48
|
+
@"startVoice" : NSStringFromSelector(@selector(startVoice:callback:)),
|
|
49
|
+
@"stopVoice" : NSStringFromSelector(@selector(stopVoice:)),
|
|
50
|
+
@"watchTouches" : NSStringFromSelector(@selector(watchTouches:touches:consume:excludeSurfaces:callback:)),
|
|
51
|
+
@"screenshot" : NSStringFromSelector(@selector(screenshot:maxEdge:quality:callback:)),
|
|
52
|
+
@"sendRange" : NSStringFromSelector(@selector(sendRange:callback:)),
|
|
53
|
+
@"touch" : NSStringFromSelector(@selector(touch:x:y:toX:toY:durationMs:callback:)),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
- (instancetype)initWithLynxContext:(LynxContext *)context {
|
|
58
|
+
if ((self = [super init])) {
|
|
59
|
+
_context = context;
|
|
60
|
+
if (context) @synchronized(G9Contexts()) { [G9Contexts() addObject:context]; }
|
|
61
|
+
}
|
|
62
|
+
return self;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
- (instancetype)init { return [super init]; }
|
|
66
|
+
|
|
67
|
+
- (void)destroy {
|
|
68
|
+
LynxContext *c = _context;
|
|
69
|
+
if (c) @synchronized(G9Contexts()) { [G9Contexts() removeObject:c]; }
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** The envelope: the same shape the Android module answers (a map; the JS face reads both a map and its JSON text). */
|
|
73
|
+
static NSDictionary *G9Reply(id value, NSError *error) {
|
|
74
|
+
if (error) {
|
|
75
|
+
NSString *code = [error isKindOfClass:G9DiagnosticError.class] ? ((G9DiagnosticError *)error).diagnosticCode : @"io";
|
|
76
|
+
return @{@"ok" : @NO, @"error" : @{@"code" : code ?: @"io", @"message" : error.localizedDescription ?: code ?: @"failed"}};
|
|
77
|
+
}
|
|
78
|
+
return @{@"ok" : @YES, @"value" : value ?: NSNull.null};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
static void G9Run(dispatch_queue_t queue, LynxCallbackBlock callback, G9Work work) {
|
|
82
|
+
dispatch_async(queue, ^{
|
|
83
|
+
NSError *error = nil;
|
|
84
|
+
id value = nil;
|
|
85
|
+
@try { value = work(&error); }
|
|
86
|
+
@catch (NSException *ex) { error = [G9DiagnosticError code:@"io" message:[NSString stringWithFormat:@"%@: %@", ex.name, ex.reason]]; }
|
|
87
|
+
if (callback) callback(G9Reply(value, error));
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
static dispatch_queue_t G9Background(void) { return dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0); }
|
|
92
|
+
|
|
93
|
+
/** A folder inside the host's roots, made when missing. */
|
|
94
|
+
static NSString *G9Folder(NSString *dir, NSError **error) {
|
|
95
|
+
NSString *p = [G9AppDiagnosticHost inside:dir folder:YES];
|
|
96
|
+
if (!p) { if (error) *error = [G9DiagnosticError code:@"invalid" message:[@"Folder outside the app's folders: " stringByAppendingString:dir ?: @""]]; return nil; }
|
|
97
|
+
[NSFileManager.defaultManager createDirectoryAtPath:p withIntermediateDirectories:YES attributes:nil error:nil];
|
|
98
|
+
return p;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
- (void)capabilities:(LynxCallbackBlock)callback {
|
|
102
|
+
G9Run(G9Background(), callback, ^id(NSError **error) {
|
|
103
|
+
return @{@"version" : kVersion, @"platform" : @"ios", @"screen" : @YES, @"voice" : @(AVAudioSession.sharedInstance.isInputAvailable), @"consume" : @YES};
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
- (void)state:(LynxCallbackBlock)callback {
|
|
108
|
+
G9Run(G9Background(), callback, ^id(NSError **error) {
|
|
109
|
+
return @{@"screen" : @(G9ScreenRecorder.shared.recording), @"voice" : @(G9VoiceRecorder.shared.recording)};
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
- (void)startScreen:(NSString *)dir maxFps:(double)maxFps callback:(LynxCallbackBlock)callback {
|
|
114
|
+
G9Run(G9Background(), callback, ^id(NSError **error) {
|
|
115
|
+
NSString *folder = G9Folder(dir, error);
|
|
116
|
+
if (folder) [G9ScreenRecorder.shared startIn:folder maxFps:(int)maxFps error:error];
|
|
117
|
+
return nil;
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
- (void)stopScreen:(LynxCallbackBlock)callback {
|
|
122
|
+
G9Run(G9Background(), callback, ^id(NSError **error) { return [G9ScreenRecorder.shared stop]; });
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
- (void)startVoice:(NSString *)dir callback:(LynxCallbackBlock)callback {
|
|
126
|
+
G9Run(G9Background(), callback, ^id(NSError **error) {
|
|
127
|
+
NSString *folder = G9Folder(dir, error);
|
|
128
|
+
if (folder) [G9VoiceRecorder.shared startIn:folder error:error];
|
|
129
|
+
return nil;
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
- (void)stopVoice:(LynxCallbackBlock)callback {
|
|
134
|
+
G9Run(G9Background(), callback, ^id(NSError **error) { return [G9VoiceRecorder.shared stop]; });
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
- (void)watchTouches:(BOOL)taps touches:(BOOL)touches consume:(BOOL)consume excludeSurfaces:(BOOL)exclude callback:(LynxCallbackBlock)callback {
|
|
138
|
+
G9Run(dispatch_get_main_queue(), callback, ^id(NSError **error) {
|
|
139
|
+
[G9TouchWatcher watchTaps:taps touches:touches consume:consume excludeSurfaces:exclude sink:^(NSString *json) { G9Emit(json); }];
|
|
140
|
+
return nil;
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** The window as the user sees it (Metal layers included), JPEG into `dir`: {path, width, height, bytes}. */
|
|
145
|
+
- (void)screenshot:(NSString *)dir maxEdge:(double)maxEdge quality:(double)quality callback:(LynxCallbackBlock)callback {
|
|
146
|
+
G9Run(dispatch_get_main_queue(), callback, ^id(NSError **error) {
|
|
147
|
+
NSString *folder = G9Folder(dir, error);
|
|
148
|
+
if (!folder) return nil;
|
|
149
|
+
UIWindow *window = G9AppDiagnosticHost.keyWindow;
|
|
150
|
+
if (window == nil || CGRectIsEmpty(window.bounds)) { if (error) *error = [G9DiagnosticError code:@"unavailable" message:@"No window to capture"]; return nil; }
|
|
151
|
+
CGSize size = window.bounds.size;
|
|
152
|
+
CGFloat edge = MIN(MAX(maxEdge, 64.0), 4096.0);
|
|
153
|
+
CGFloat scale = MIN(window.screen.scale, edge / MAX(size.width, size.height));
|
|
154
|
+
UIImage *image = [G9AppDiagnosticHost captureWindowAtScale:scale];
|
|
155
|
+
NSData *jpeg = image ? UIImageJPEGRepresentation(image, MIN(MAX(quality, 10.0), 100.0) / 100.0) : nil;
|
|
156
|
+
NSString *path = [folder stringByAppendingPathComponent:[NSString stringWithFormat:@"shot-%lld.jpg", (long long)(NSDate.date.timeIntervalSince1970 * 1000)]];
|
|
157
|
+
if (!jpeg || ![jpeg writeToFile:path atomically:YES]) { if (error) *error = [G9DiagnosticError code:@"io" message:@"The screenshot could not be written"]; return nil; }
|
|
158
|
+
return @{@"path" : path, @"width" : @((int)lround(size.width * scale)), @"height" : @((int)lround(size.height * scale)), @"bytes" : @(jpeg.length)};
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* One HTTP request whose body is a byte range of a file (the tester report's resumable PUT), read here so a chunk never
|
|
164
|
+
* crosses the bridge as base64; over the host's session (its trust). Any HTTP status resolves; only a transport failure
|
|
165
|
+
* rejects (network | timeout).
|
|
166
|
+
*/
|
|
167
|
+
- (void)sendRange:(NSString *)requestJson callback:(LynxCallbackBlock)callback {
|
|
168
|
+
G9Run(G9Background(), callback, ^id(NSError **error) {
|
|
169
|
+
NSDictionary *r = requestJson.length ? [NSJSONSerialization JSONObjectWithData:[requestJson dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil] : nil;
|
|
170
|
+
if (![r isKindOfClass:NSDictionary.class] || ![r[@"url"] isKindOfClass:NSString.class] || ![r[@"path"] isKindOfClass:NSString.class]) {
|
|
171
|
+
if (error) *error = [G9DiagnosticError code:@"invalid" message:@"sendRange needs {url, path}"];
|
|
172
|
+
return nil;
|
|
173
|
+
}
|
|
174
|
+
NSString *p = [G9AppDiagnosticHost inside:r[@"path"] folder:NO];
|
|
175
|
+
if (!p) { if (error) *error = [G9DiagnosticError code:@"invalid" message:[@"Path outside the app's folders: " stringByAppendingString:r[@"path"]]]; return nil; }
|
|
176
|
+
NSFileHandle *h = [NSFileHandle fileHandleForReadingAtPath:p];
|
|
177
|
+
if (!h) { if (error) *error = [G9DiagnosticError code:@"not-found" message:[@"No such file: " stringByAppendingString:p]]; return nil; }
|
|
178
|
+
unsigned long long size = [[NSFileManager.defaultManager attributesOfItemAtPath:p error:nil] fileSize];
|
|
179
|
+
unsigned long long offset = MIN((unsigned long long)MAX([r[@"offset"] doubleValue], 0.0), size);
|
|
180
|
+
unsigned long long length = r[@"length"] ? (unsigned long long)MAX([r[@"length"] doubleValue], 0.0) : size - offset;
|
|
181
|
+
length = MIN(length, size - offset);
|
|
182
|
+
[h seekToFileOffset:offset];
|
|
183
|
+
NSData *body = [h readDataOfLength:(NSUInteger)length];
|
|
184
|
+
[h closeFile];
|
|
185
|
+
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:r[@"url"]]];
|
|
186
|
+
request.HTTPMethod = [r[@"method"] isKindOfClass:NSString.class] ? r[@"method"] : @"PUT";
|
|
187
|
+
double timeoutMs = [r[@"timeoutMs"] doubleValue] > 0 ? [r[@"timeoutMs"] doubleValue] : 180000.0;
|
|
188
|
+
request.timeoutInterval = MIN(MAX(timeoutMs, 1000.0), 900000.0) / 1000.0;
|
|
189
|
+
NSString *type = [r[@"contentType"] isKindOfClass:NSString.class] && [r[@"contentType"] length] ? r[@"contentType"] : @"application/octet-stream";
|
|
190
|
+
[request setValue:type forHTTPHeaderField:@"Content-Type"];
|
|
191
|
+
NSDictionary *headers = [r[@"headers"] isKindOfClass:NSDictionary.class] ? r[@"headers"] : @{};
|
|
192
|
+
[headers enumerateKeysAndObjectsUsingBlock:^(NSString *key, id value, BOOL *stop) { [request setValue:[value description] forHTTPHeaderField:key]; }];
|
|
193
|
+
NSURLSession *session = G9AppDiagnosticHost.urlSession ? G9AppDiagnosticHost.urlSession() : NSURLSession.sharedSession;
|
|
194
|
+
dispatch_semaphore_t done = dispatch_semaphore_create(0);
|
|
195
|
+
__block NSData *answer = nil;
|
|
196
|
+
__block NSHTTPURLResponse *response = nil;
|
|
197
|
+
__block NSError *failure = nil;
|
|
198
|
+
[[session uploadTaskWithRequest:request fromData:body completionHandler:^(NSData *data, NSURLResponse *res, NSError *err) {
|
|
199
|
+
answer = data;
|
|
200
|
+
response = [res isKindOfClass:NSHTTPURLResponse.class] ? (NSHTTPURLResponse *)res : nil;
|
|
201
|
+
failure = err;
|
|
202
|
+
dispatch_semaphore_signal(done);
|
|
203
|
+
}] resume];
|
|
204
|
+
dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);
|
|
205
|
+
if (failure || !response) {
|
|
206
|
+
if (error) *error = [G9DiagnosticError code:failure.code == NSURLErrorTimedOut ? @"timeout" : @"network" message:failure.localizedDescription ?: @"No response"];
|
|
207
|
+
return nil;
|
|
208
|
+
}
|
|
209
|
+
NSMutableDictionary *out = [NSMutableDictionary dictionary];
|
|
210
|
+
[response.allHeaderFields enumerateKeysAndObjectsUsingBlock:^(id key, id value, BOOL *stop) { out[[[key description] lowercaseString]] = [value description]; }];
|
|
211
|
+
return @{@"status" : @(response.statusCode), @"body" : answer ? ([[NSString alloc] initWithData:answer encoding:NSUTF8StringEncoding] ?: @"") : @"", @"headers" : out};
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* The operator's remote touch (E-13). iOS has no public way to inject a finger, so this is the store-safe LOGICAL touch
|
|
217
|
+
* (.agents/skills/g9-app-diagnostic/references/remote-control.md): the view under the point is hit-tested and, for a tap, a
|
|
218
|
+
* control's touch-up-inside action or the element's accessibility activation runs. A long press or a drag is refused
|
|
219
|
+
* (`handled: false`) — the console says so. Points from the window's top-left.
|
|
220
|
+
*/
|
|
221
|
+
- (void)touch:(NSString *)kind x:(double)x y:(double)y toX:(double)toX toY:(double)toY durationMs:(double)durationMs callback:(LynxCallbackBlock)callback {
|
|
222
|
+
G9Run(dispatch_get_main_queue(), callback, ^id(NSError **error) {
|
|
223
|
+
UIWindow *window = G9AppDiagnosticHost.keyWindow;
|
|
224
|
+
if (!window) { if (error) *error = [G9DiagnosticError code:@"unavailable" message:@"No window"]; return nil; }
|
|
225
|
+
if (![kind isEqualToString:@"tap"]) return @{@"handled" : @NO, @"reason" : @"ios-logical-tap-only"};
|
|
226
|
+
UIView *hit = [window hitTest:CGPointMake(x, y) withEvent:nil];
|
|
227
|
+
for (UIView *v = hit; v; v = v.superview) {
|
|
228
|
+
if ([v isKindOfClass:UIControl.class] && ((UIControl *)v).enabled) {
|
|
229
|
+
[(UIControl *)v sendActionsForControlEvents:UIControlEventTouchUpInside];
|
|
230
|
+
return @{@"handled" : @YES};
|
|
231
|
+
}
|
|
232
|
+
if (v.isAccessibilityElement && [v accessibilityActivate]) return @{@"handled" : @YES};
|
|
233
|
+
}
|
|
234
|
+
return @{@"handled" : @NO};
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
@end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// The iOS recorders and the tester gesture of G9AppDiagnosticModule (TWIN: android/…/ScreenRecorder.kt, VoiceRecorder.kt,
|
|
2
|
+
// TouchWatcher.kt + core/TouchCore.kt). Moved here from the first Lynx app's own ios/Platform/AGMedia.mm (2026-11-20) so
|
|
3
|
+
// every Lynx app gets them; no product name, the excluded surface is the host's (G9AppDiagnosticHost.isExcludedView).
|
|
4
|
+
#import <Foundation/Foundation.h>
|
|
5
|
+
#import <UIKit/UIKit.h>
|
|
6
|
+
|
|
7
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
8
|
+
|
|
9
|
+
/** A failure the JS side reads as DiagnosticNativeError(code, message) — the codes of types/g9-app-diagnostic-module.d.ts. */
|
|
10
|
+
@interface G9DiagnosticError : NSError
|
|
11
|
+
+ (instancetype)code:(NSString *)code message:(NSString *)message;
|
|
12
|
+
@property(nonatomic, readonly) NSString *diagnosticCode;
|
|
13
|
+
@end
|
|
14
|
+
|
|
15
|
+
@interface G9ScreenRecorder : NSObject
|
|
16
|
+
@property(nonatomic, readonly) BOOL recording;
|
|
17
|
+
+ (instancetype)shared;
|
|
18
|
+
- (BOOL)startIn:(NSString *)dir maxFps:(int)maxFps error:(NSError **)error;
|
|
19
|
+
/** Blocks until the file is finalised (call off the main thread). {path, bytes, durationMs, width, height, capped} or nil. */
|
|
20
|
+
- (nullable NSDictionary *)stop;
|
|
21
|
+
@end
|
|
22
|
+
|
|
23
|
+
@interface G9VoiceRecorder : NSObject
|
|
24
|
+
+ (instancetype)shared;
|
|
25
|
+
@property(nonatomic, readonly) BOOL recording;
|
|
26
|
+
- (BOOL)startIn:(NSString *)dir error:(NSError **)error;
|
|
27
|
+
/** {path, bytes, durationMs} or nil. */
|
|
28
|
+
- (nullable NSDictionary *)stop;
|
|
29
|
+
@end
|
|
30
|
+
|
|
31
|
+
/** The tester gesture's watcher on the key window; events go to [sink] as JSON text («g9:diagnostic-touch»). */
|
|
32
|
+
@interface G9TouchWatcher : NSObject
|
|
33
|
+
+ (void)watchTaps:(BOOL)taps touches:(BOOL)touches consume:(BOOL)consume excludeSurfaces:(BOOL)exclude sink:(void (^)(NSString *json))sink;
|
|
34
|
+
@end
|
|
35
|
+
|
|
36
|
+
NS_ASSUME_NONNULL_END
|