@g9tm/app-diagnostic-tauri 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.toml +1 -1
- package/README.md +2 -0
- package/android/build.gradle.kts +29 -29
- package/android/proguard-rules.pro +2 -2
- package/android/settings.gradle +2 -2
- package/android/src/main/AndroidManifest.xml +5 -5
- package/android/src/main/java/com/g9tm/appdiagnostic/tauri/G9DiagnosticPlugin.kt +1 -1
- package/build.rs +13 -13
- package/ios/Package.swift +20 -20
- package/ios/Sources/G9AppDiagnosticCore/G9AppDiagnosticHost.m +72 -72
- package/ios/Sources/G9AppDiagnosticCore/G9DiagnosticRecorders.m +514 -514
- package/ios/Sources/G9AppDiagnosticCore/include/G9AppDiagnosticHost.h +32 -32
- package/ios/Sources/G9AppDiagnosticCore/include/G9DiagnosticRecorders.h +36 -36
- package/ios/Sources/G9DiagnosticPlugin/G9DiagnosticPlugin.swift +135 -135
- package/package.json +3 -3
- package/permissions/autogenerated/commands/capabilities.toml +13 -13
- package/permissions/autogenerated/commands/read_chunk.toml +13 -13
- package/permissions/autogenerated/commands/registerListener.toml +13 -13
- package/permissions/autogenerated/commands/remove.toml +13 -13
- package/permissions/autogenerated/commands/remove_listener.toml +13 -13
- package/permissions/autogenerated/commands/screenshot.toml +13 -13
- package/permissions/autogenerated/commands/start_screen.toml +13 -13
- package/permissions/autogenerated/commands/start_voice.toml +13 -13
- package/permissions/autogenerated/commands/state.toml +13 -13
- package/permissions/autogenerated/commands/stop_screen.toml +13 -13
- package/permissions/autogenerated/commands/stop_voice.toml +13 -13
- package/permissions/autogenerated/commands/touch.toml +13 -13
- package/permissions/autogenerated/commands/watch_touches.toml +13 -13
- package/permissions/autogenerated/reference.md +367 -367
- package/permissions/default.toml +9 -9
- package/permissions/schemas/schema.json +461 -461
- package/src/index.ts +97 -97
- package/src/lib.rs +119 -119
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
// The host's hooks for G9AppDiagnosticModule on iOS (TWIN: android/…/G9AppDiagnosticHost.kt). Set them before the first
|
|
2
|
-
// call, typically in application:didFinishLaunchingWithOptions:. Every hook has a default; none names a product.
|
|
3
|
-
//
|
|
4
|
-
// G9AppDiagnosticHost.urlSession = ^{ return myTrustedSession; }; // its trust rules for the range PUT
|
|
5
|
-
// G9AppDiagnosticHost.allowedRoots = ^{ return @[ supportDir, cachesDir ]; }; // the folders a path may be inside
|
|
6
|
-
// G9AppDiagnosticHost.isExcludedView = ^BOOL(UIView *v) { return [v isKindOfClass:MyMapHost.class]; }; // «except the map»
|
|
7
|
-
#import <Foundation/Foundation.h>
|
|
8
|
-
#import <UIKit/UIKit.h>
|
|
9
|
-
|
|
10
|
-
NS_ASSUME_NONNULL_BEGIN
|
|
11
|
-
|
|
12
|
-
@interface G9AppDiagnosticHost : NSObject
|
|
13
|
-
/** The session sendRange uses (the host's trust, proxy and certificates). Default: NSURLSession.sharedSession. */
|
|
14
|
-
@property(class, nonatomic, copy, nullable) NSURLSession *_Nonnull (^urlSession)(void);
|
|
15
|
-
/** The folders a recording, a screenshot or a sent file may live in. Default: Application Support, Caches, tmp. */
|
|
16
|
-
@property(class, nonatomic, copy, nullable) NSArray<NSString *> *_Nonnull (^allowedRoots)(void);
|
|
17
|
-
/** A view the tester gesture never holds a touch over (a map's own pinch and pan). Default: none. */
|
|
18
|
-
@property(class, nonatomic, copy, nullable) BOOL (^isExcludedView)(UIView *view);
|
|
19
|
-
|
|
20
|
-
/** The folders a path may be inside, resolved (symlinks, «..»). */
|
|
21
|
-
+ (NSArray<NSString *> *)roots;
|
|
22
|
-
/** The path resolved, when strictly inside one of the roots (or a root itself, for a folder); else nil. */
|
|
23
|
-
+ (nullable NSString *)inside:(nullable NSString *)path folder:(BOOL)folder;
|
|
24
|
-
/** The key window of the foreground scene. */
|
|
25
|
-
+ (nullable UIWindow *)keyWindow;
|
|
26
|
-
/** The window as the user sees it (Metal and GL layers included), at a scale (1 = points). */
|
|
27
|
-
+ (nullable UIImage *)captureWindowAtScale:(CGFloat)scale;
|
|
28
|
-
/** The window's size in points (zero when there is none). */
|
|
29
|
-
+ (CGSize)windowSize;
|
|
30
|
-
@end
|
|
31
|
-
|
|
32
|
-
NS_ASSUME_NONNULL_END
|
|
1
|
+
// The host's hooks for G9AppDiagnosticModule on iOS (TWIN: android/…/G9AppDiagnosticHost.kt). Set them before the first
|
|
2
|
+
// call, typically in application:didFinishLaunchingWithOptions:. Every hook has a default; none names a product.
|
|
3
|
+
//
|
|
4
|
+
// G9AppDiagnosticHost.urlSession = ^{ return myTrustedSession; }; // its trust rules for the range PUT
|
|
5
|
+
// G9AppDiagnosticHost.allowedRoots = ^{ return @[ supportDir, cachesDir ]; }; // the folders a path may be inside
|
|
6
|
+
// G9AppDiagnosticHost.isExcludedView = ^BOOL(UIView *v) { return [v isKindOfClass:MyMapHost.class]; }; // «except the map»
|
|
7
|
+
#import <Foundation/Foundation.h>
|
|
8
|
+
#import <UIKit/UIKit.h>
|
|
9
|
+
|
|
10
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
11
|
+
|
|
12
|
+
@interface G9AppDiagnosticHost : NSObject
|
|
13
|
+
/** The session sendRange uses (the host's trust, proxy and certificates). Default: NSURLSession.sharedSession. */
|
|
14
|
+
@property(class, nonatomic, copy, nullable) NSURLSession *_Nonnull (^urlSession)(void);
|
|
15
|
+
/** The folders a recording, a screenshot or a sent file may live in. Default: Application Support, Caches, tmp. */
|
|
16
|
+
@property(class, nonatomic, copy, nullable) NSArray<NSString *> *_Nonnull (^allowedRoots)(void);
|
|
17
|
+
/** A view the tester gesture never holds a touch over (a map's own pinch and pan). Default: none. */
|
|
18
|
+
@property(class, nonatomic, copy, nullable) BOOL (^isExcludedView)(UIView *view);
|
|
19
|
+
|
|
20
|
+
/** The folders a path may be inside, resolved (symlinks, «..»). */
|
|
21
|
+
+ (NSArray<NSString *> *)roots;
|
|
22
|
+
/** The path resolved, when strictly inside one of the roots (or a root itself, for a folder); else nil. */
|
|
23
|
+
+ (nullable NSString *)inside:(nullable NSString *)path folder:(BOOL)folder;
|
|
24
|
+
/** The key window of the foreground scene. */
|
|
25
|
+
+ (nullable UIWindow *)keyWindow;
|
|
26
|
+
/** The window as the user sees it (Metal and GL layers included), at a scale (1 = points). */
|
|
27
|
+
+ (nullable UIImage *)captureWindowAtScale:(CGFloat)scale;
|
|
28
|
+
/** The window's size in points (zero when there is none). */
|
|
29
|
+
+ (CGSize)windowSize;
|
|
30
|
+
@end
|
|
31
|
+
|
|
32
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -1,36 +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
|
|
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
|
|
@@ -1,135 +1,135 @@
|
|
|
1
|
-
import AVFoundation
|
|
2
|
-
import G9AppDiagnosticCore
|
|
3
|
-
import SwiftRs
|
|
4
|
-
import Tauri
|
|
5
|
-
import UIKit
|
|
6
|
-
import WebKit
|
|
7
|
-
|
|
8
|
-
class ScreenArgs: Decodable { let maxFps: Int? }
|
|
9
|
-
class ShotArgs: Decodable { let maxEdge: Double?; let quality: Double? }
|
|
10
|
-
class WatchArgs: Decodable { let taps: Bool?; let touches: Bool?; let consume: Bool?; let excludeSurfaces: Bool? }
|
|
11
|
-
class TouchArgs: Decodable { let kind: String?; let x: Double?; let y: Double? }
|
|
12
|
-
class ChunkArgs: Decodable { let path: String; let offset: Double?; let length: Int? }
|
|
13
|
-
class PathArgs: Decodable { let path: String }
|
|
14
|
-
|
|
15
|
-
/// G9AppDiagnostic for a Tauri v2 app on iOS (0.5.0): the SAME recorders, window capture and gesture as
|
|
16
|
-
/// @g9tm/app-diagnostic-lynx's iOS half. Files go to Caches/g9diag-native; the JS side moves them into the WebView's files.
|
|
17
|
-
class G9DiagnosticPlugin: Plugin {
|
|
18
|
-
private lazy var folder: String = {
|
|
19
|
-
let caches = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true).first ?? NSTemporaryDirectory()
|
|
20
|
-
let dir = (caches as NSString).appendingPathComponent("g9diag-native")
|
|
21
|
-
try? FileManager.default.createDirectory(atPath: dir, withIntermediateDirectories: true)
|
|
22
|
-
return dir
|
|
23
|
-
}()
|
|
24
|
-
|
|
25
|
-
private func fail(_ invoke: Invoke, _ error: Error) {
|
|
26
|
-
invoke.reject(error.localizedDescription, code: (error as? G9DiagnosticError)?.diagnosticCode ?? "io")
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
private func background(_ invoke: Invoke, _ work: @escaping () throws -> JsonObject) {
|
|
30
|
-
DispatchQueue.global(qos: .userInitiated).async {
|
|
31
|
-
do { invoke.resolve(try work()) } catch { self.fail(invoke, error) }
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
@objc public func capabilities(_ invoke: Invoke) {
|
|
36
|
-
invoke.resolve(["version": "0.5.0", "platform": "ios", "screen": true, "voice": AVAudioSession.sharedInstance().isInputAvailable, "consume": true, "native": true])
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
@objc public func state(_ invoke: Invoke) {
|
|
40
|
-
background(invoke) { ["screen": G9ScreenRecorder.shared().recording, "voice": G9VoiceRecorder.shared().recording] }
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
@objc public func startScreen(_ invoke: Invoke) {
|
|
44
|
-
let fps = Int32((try? invoke.parseArgs(ScreenArgs.self))?.maxFps ?? 10)
|
|
45
|
-
background(invoke) { try G9ScreenRecorder.shared().start(in: self.folder, maxFps: fps); return [:] }
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
@objc public func stopScreen(_ invoke: Invoke) {
|
|
49
|
-
background(invoke) { ["recording": G9ScreenRecorder.shared().stop() as Any? ?? NSNull()] }
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
@objc public func startVoice(_ invoke: Invoke) {
|
|
53
|
-
background(invoke) { try G9VoiceRecorder.shared().start(in: self.folder); return [:] }
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
@objc public func stopVoice(_ invoke: Invoke) {
|
|
57
|
-
background(invoke) { ["recording": G9VoiceRecorder.shared().stop() as Any? ?? NSNull()] }
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
@objc public func screenshot(_ invoke: Invoke) {
|
|
61
|
-
let a = try? invoke.parseArgs(ShotArgs.self)
|
|
62
|
-
DispatchQueue.main.async {
|
|
63
|
-
guard let window = G9AppDiagnosticHost.keyWindow(), !window.bounds.isEmpty else {
|
|
64
|
-
invoke.reject("No window to capture", code: "unavailable")
|
|
65
|
-
return
|
|
66
|
-
}
|
|
67
|
-
let size = window.bounds.size
|
|
68
|
-
let scale = min(window.screen.scale, min(max(CGFloat(a?.maxEdge ?? 1600), 64), 4096) / max(size.width, size.height))
|
|
69
|
-
guard let image = G9AppDiagnosticHost.captureWindow(atScale: scale),
|
|
70
|
-
let jpeg = image.jpegData(compressionQuality: min(max(CGFloat(a?.quality ?? 80), 10), 100) / 100) else {
|
|
71
|
-
invoke.reject("The window could not be drawn", code: "io")
|
|
72
|
-
return
|
|
73
|
-
}
|
|
74
|
-
let path = (self.folder as NSString).appendingPathComponent("shot-\(Int64(Date().timeIntervalSince1970 * 1000)).jpg")
|
|
75
|
-
do {
|
|
76
|
-
try jpeg.write(to: URL(fileURLWithPath: path))
|
|
77
|
-
invoke.resolve(["path": path, "width": Int(size.width * scale), "height": Int(size.height * scale), "bytes": jpeg.count])
|
|
78
|
-
} catch { invoke.reject("The screenshot could not be written", code: "io") }
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
@objc public func watchTouches(_ invoke: Invoke) {
|
|
83
|
-
let a = try? invoke.parseArgs(WatchArgs.self)
|
|
84
|
-
DispatchQueue.main.async {
|
|
85
|
-
G9TouchWatcher.watchTaps(a?.taps ?? false, touches: a?.touches ?? false, consume: a?.consume ?? false, excludeSurfaces: a?.excludeSurfaces ?? false) { [weak self] json in
|
|
86
|
-
try? self?.trigger("touch", data: ["json": json])
|
|
87
|
-
}
|
|
88
|
-
invoke.resolve()
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/// iOS has no public way to inject a finger: a LOGICAL tap (remote-control.md); a long press or a drag is refused.
|
|
93
|
-
@objc public func touch(_ invoke: Invoke) {
|
|
94
|
-
let a = try? invoke.parseArgs(TouchArgs.self)
|
|
95
|
-
DispatchQueue.main.async {
|
|
96
|
-
guard (a?.kind ?? "tap") == "tap", let window = G9AppDiagnosticHost.keyWindow() else {
|
|
97
|
-
invoke.resolve(["handled": false])
|
|
98
|
-
return
|
|
99
|
-
}
|
|
100
|
-
var view = window.hitTest(CGPoint(x: a?.x ?? 0, y: a?.y ?? 0), with: nil)
|
|
101
|
-
while let v = view {
|
|
102
|
-
if let control = v as? UIControl, control.isEnabled { control.sendActions(for: .touchUpInside); invoke.resolve(["handled": true]); return }
|
|
103
|
-
if v.isAccessibilityElement && v.accessibilityActivate() { invoke.resolve(["handled": true]); return }
|
|
104
|
-
view = v.superview
|
|
105
|
-
}
|
|
106
|
-
invoke.resolve(["handled": false])
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
@objc public func readChunk(_ invoke: Invoke) {
|
|
111
|
-
background(invoke) {
|
|
112
|
-
let a = try invoke.parseArgs(ChunkArgs.self)
|
|
113
|
-
let path = try self.own(a.path)
|
|
114
|
-
guard let h = FileHandle(forReadingAtPath: path) else { throw G9DiagnosticError.code("not-found", message: "No such file: \(path)") }
|
|
115
|
-
defer { h.closeFile() }
|
|
116
|
-
h.seek(toFileOffset: UInt64(max(0, a.offset ?? 0)))
|
|
117
|
-
return ["data": h.readData(ofLength: min(4 * 1024 * 1024, max(0, a.length ?? 0))).base64EncodedString()]
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
@objc public func remove(_ invoke: Invoke) {
|
|
122
|
-
background(invoke) { try FileManager.default.removeItem(atPath: try self.own(try invoke.parseArgs(PathArgs.self).path)); return [:] }
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
private func own(_ path: String) throws -> String {
|
|
126
|
-
let p = (path as NSString).standardizingPath
|
|
127
|
-
guard p.hasPrefix(folder + "/") else { throw G9DiagnosticError.code("invalid", message: "Not a file of this plugin: \(path)") }
|
|
128
|
-
return p
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
@_cdecl("init_plugin_g9_diagnostic")
|
|
133
|
-
func initPlugin() -> Plugin {
|
|
134
|
-
return G9DiagnosticPlugin()
|
|
135
|
-
}
|
|
1
|
+
import AVFoundation
|
|
2
|
+
import G9AppDiagnosticCore
|
|
3
|
+
import SwiftRs
|
|
4
|
+
import Tauri
|
|
5
|
+
import UIKit
|
|
6
|
+
import WebKit
|
|
7
|
+
|
|
8
|
+
class ScreenArgs: Decodable { let maxFps: Int? }
|
|
9
|
+
class ShotArgs: Decodable { let maxEdge: Double?; let quality: Double? }
|
|
10
|
+
class WatchArgs: Decodable { let taps: Bool?; let touches: Bool?; let consume: Bool?; let excludeSurfaces: Bool? }
|
|
11
|
+
class TouchArgs: Decodable { let kind: String?; let x: Double?; let y: Double? }
|
|
12
|
+
class ChunkArgs: Decodable { let path: String; let offset: Double?; let length: Int? }
|
|
13
|
+
class PathArgs: Decodable { let path: String }
|
|
14
|
+
|
|
15
|
+
/// G9AppDiagnostic for a Tauri v2 app on iOS (0.5.0): the SAME recorders, window capture and gesture as
|
|
16
|
+
/// @g9tm/app-diagnostic-lynx's iOS half. Files go to Caches/g9diag-native; the JS side moves them into the WebView's files.
|
|
17
|
+
class G9DiagnosticPlugin: Plugin {
|
|
18
|
+
private lazy var folder: String = {
|
|
19
|
+
let caches = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true).first ?? NSTemporaryDirectory()
|
|
20
|
+
let dir = (caches as NSString).appendingPathComponent("g9diag-native")
|
|
21
|
+
try? FileManager.default.createDirectory(atPath: dir, withIntermediateDirectories: true)
|
|
22
|
+
return dir
|
|
23
|
+
}()
|
|
24
|
+
|
|
25
|
+
private func fail(_ invoke: Invoke, _ error: Error) {
|
|
26
|
+
invoke.reject(error.localizedDescription, code: (error as? G9DiagnosticError)?.diagnosticCode ?? "io")
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
private func background(_ invoke: Invoke, _ work: @escaping () throws -> JsonObject) {
|
|
30
|
+
DispatchQueue.global(qos: .userInitiated).async {
|
|
31
|
+
do { invoke.resolve(try work()) } catch { self.fail(invoke, error) }
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@objc public func capabilities(_ invoke: Invoke) {
|
|
36
|
+
invoke.resolve(["version": "0.5.0", "platform": "ios", "screen": true, "voice": AVAudioSession.sharedInstance().isInputAvailable, "consume": true, "native": true])
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@objc public func state(_ invoke: Invoke) {
|
|
40
|
+
background(invoke) { ["screen": G9ScreenRecorder.shared().recording, "voice": G9VoiceRecorder.shared().recording] }
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@objc public func startScreen(_ invoke: Invoke) {
|
|
44
|
+
let fps = Int32((try? invoke.parseArgs(ScreenArgs.self))?.maxFps ?? 10)
|
|
45
|
+
background(invoke) { try G9ScreenRecorder.shared().start(in: self.folder, maxFps: fps); return [:] }
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@objc public func stopScreen(_ invoke: Invoke) {
|
|
49
|
+
background(invoke) { ["recording": G9ScreenRecorder.shared().stop() as Any? ?? NSNull()] }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@objc public func startVoice(_ invoke: Invoke) {
|
|
53
|
+
background(invoke) { try G9VoiceRecorder.shared().start(in: self.folder); return [:] }
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@objc public func stopVoice(_ invoke: Invoke) {
|
|
57
|
+
background(invoke) { ["recording": G9VoiceRecorder.shared().stop() as Any? ?? NSNull()] }
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
@objc public func screenshot(_ invoke: Invoke) {
|
|
61
|
+
let a = try? invoke.parseArgs(ShotArgs.self)
|
|
62
|
+
DispatchQueue.main.async {
|
|
63
|
+
guard let window = G9AppDiagnosticHost.keyWindow(), !window.bounds.isEmpty else {
|
|
64
|
+
invoke.reject("No window to capture", code: "unavailable")
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
let size = window.bounds.size
|
|
68
|
+
let scale = min(window.screen.scale, min(max(CGFloat(a?.maxEdge ?? 1600), 64), 4096) / max(size.width, size.height))
|
|
69
|
+
guard let image = G9AppDiagnosticHost.captureWindow(atScale: scale),
|
|
70
|
+
let jpeg = image.jpegData(compressionQuality: min(max(CGFloat(a?.quality ?? 80), 10), 100) / 100) else {
|
|
71
|
+
invoke.reject("The window could not be drawn", code: "io")
|
|
72
|
+
return
|
|
73
|
+
}
|
|
74
|
+
let path = (self.folder as NSString).appendingPathComponent("shot-\(Int64(Date().timeIntervalSince1970 * 1000)).jpg")
|
|
75
|
+
do {
|
|
76
|
+
try jpeg.write(to: URL(fileURLWithPath: path))
|
|
77
|
+
invoke.resolve(["path": path, "width": Int(size.width * scale), "height": Int(size.height * scale), "bytes": jpeg.count])
|
|
78
|
+
} catch { invoke.reject("The screenshot could not be written", code: "io") }
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
@objc public func watchTouches(_ invoke: Invoke) {
|
|
83
|
+
let a = try? invoke.parseArgs(WatchArgs.self)
|
|
84
|
+
DispatchQueue.main.async {
|
|
85
|
+
G9TouchWatcher.watchTaps(a?.taps ?? false, touches: a?.touches ?? false, consume: a?.consume ?? false, excludeSurfaces: a?.excludeSurfaces ?? false) { [weak self] json in
|
|
86
|
+
try? self?.trigger("touch", data: ["json": json])
|
|
87
|
+
}
|
|
88
|
+
invoke.resolve()
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/// iOS has no public way to inject a finger: a LOGICAL tap (remote-control.md); a long press or a drag is refused.
|
|
93
|
+
@objc public func touch(_ invoke: Invoke) {
|
|
94
|
+
let a = try? invoke.parseArgs(TouchArgs.self)
|
|
95
|
+
DispatchQueue.main.async {
|
|
96
|
+
guard (a?.kind ?? "tap") == "tap", let window = G9AppDiagnosticHost.keyWindow() else {
|
|
97
|
+
invoke.resolve(["handled": false])
|
|
98
|
+
return
|
|
99
|
+
}
|
|
100
|
+
var view = window.hitTest(CGPoint(x: a?.x ?? 0, y: a?.y ?? 0), with: nil)
|
|
101
|
+
while let v = view {
|
|
102
|
+
if let control = v as? UIControl, control.isEnabled { control.sendActions(for: .touchUpInside); invoke.resolve(["handled": true]); return }
|
|
103
|
+
if v.isAccessibilityElement && v.accessibilityActivate() { invoke.resolve(["handled": true]); return }
|
|
104
|
+
view = v.superview
|
|
105
|
+
}
|
|
106
|
+
invoke.resolve(["handled": false])
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
@objc public func readChunk(_ invoke: Invoke) {
|
|
111
|
+
background(invoke) {
|
|
112
|
+
let a = try invoke.parseArgs(ChunkArgs.self)
|
|
113
|
+
let path = try self.own(a.path)
|
|
114
|
+
guard let h = FileHandle(forReadingAtPath: path) else { throw G9DiagnosticError.code("not-found", message: "No such file: \(path)") }
|
|
115
|
+
defer { h.closeFile() }
|
|
116
|
+
h.seek(toFileOffset: UInt64(max(0, a.offset ?? 0)))
|
|
117
|
+
return ["data": h.readData(ofLength: min(4 * 1024 * 1024, max(0, a.length ?? 0))).base64EncodedString()]
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
@objc public func remove(_ invoke: Invoke) {
|
|
122
|
+
background(invoke) { try FileManager.default.removeItem(atPath: try self.own(try invoke.parseArgs(PathArgs.self).path)); return [:] }
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
private func own(_ path: String) throws -> String {
|
|
126
|
+
let p = (path as NSString).standardizingPath
|
|
127
|
+
guard p.hasPrefix(folder + "/") else { throw G9DiagnosticError.code("invalid", message: "Not a file of this plugin: \(path)") }
|
|
128
|
+
return p
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
@_cdecl("init_plugin_g9_diagnostic")
|
|
133
|
+
func initPlugin() -> Plugin {
|
|
134
|
+
return G9DiagnosticPlugin()
|
|
135
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@g9tm/app-diagnostic-tauri",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "The tester mode for a Tauri v2 app: the JS side of tauri-plugin-g9-diagnostic (the native screen, voice, screenshot, gesture and remote touch on Android and iOS) under @g9tm/app-diagnostic-web's <g9-tester>; the web recorders on a desktop.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"@tauri-apps/api": ">=2.0.0",
|
|
36
|
-
"@g9tm/app-diagnostic": "^0.
|
|
37
|
-
"@g9tm/app-diagnostic-web": "^0.
|
|
36
|
+
"@g9tm/app-diagnostic": "^0.6.0",
|
|
37
|
+
"@g9tm/app-diagnostic-web": "^0.6.0"
|
|
38
38
|
},
|
|
39
39
|
"license": "MIT",
|
|
40
40
|
"engines": {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
# Automatically generated - DO NOT EDIT!
|
|
2
|
-
|
|
3
|
-
"$schema" = "../../schemas/schema.json"
|
|
4
|
-
|
|
5
|
-
[[permission]]
|
|
6
|
-
identifier = "allow-capabilities"
|
|
7
|
-
description = "Enables the capabilities command without any pre-configured scope."
|
|
8
|
-
commands.allow = ["capabilities"]
|
|
9
|
-
|
|
10
|
-
[[permission]]
|
|
11
|
-
identifier = "deny-capabilities"
|
|
12
|
-
description = "Denies the capabilities command without any pre-configured scope."
|
|
13
|
-
commands.deny = ["capabilities"]
|
|
1
|
+
# Automatically generated - DO NOT EDIT!
|
|
2
|
+
|
|
3
|
+
"$schema" = "../../schemas/schema.json"
|
|
4
|
+
|
|
5
|
+
[[permission]]
|
|
6
|
+
identifier = "allow-capabilities"
|
|
7
|
+
description = "Enables the capabilities command without any pre-configured scope."
|
|
8
|
+
commands.allow = ["capabilities"]
|
|
9
|
+
|
|
10
|
+
[[permission]]
|
|
11
|
+
identifier = "deny-capabilities"
|
|
12
|
+
description = "Denies the capabilities command without any pre-configured scope."
|
|
13
|
+
commands.deny = ["capabilities"]
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
# Automatically generated - DO NOT EDIT!
|
|
2
|
-
|
|
3
|
-
"$schema" = "../../schemas/schema.json"
|
|
4
|
-
|
|
5
|
-
[[permission]]
|
|
6
|
-
identifier = "allow-read-chunk"
|
|
7
|
-
description = "Enables the read_chunk command without any pre-configured scope."
|
|
8
|
-
commands.allow = ["read_chunk"]
|
|
9
|
-
|
|
10
|
-
[[permission]]
|
|
11
|
-
identifier = "deny-read-chunk"
|
|
12
|
-
description = "Denies the read_chunk command without any pre-configured scope."
|
|
13
|
-
commands.deny = ["read_chunk"]
|
|
1
|
+
# Automatically generated - DO NOT EDIT!
|
|
2
|
+
|
|
3
|
+
"$schema" = "../../schemas/schema.json"
|
|
4
|
+
|
|
5
|
+
[[permission]]
|
|
6
|
+
identifier = "allow-read-chunk"
|
|
7
|
+
description = "Enables the read_chunk command without any pre-configured scope."
|
|
8
|
+
commands.allow = ["read_chunk"]
|
|
9
|
+
|
|
10
|
+
[[permission]]
|
|
11
|
+
identifier = "deny-read-chunk"
|
|
12
|
+
description = "Denies the read_chunk command without any pre-configured scope."
|
|
13
|
+
commands.deny = ["read_chunk"]
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
# Automatically generated - DO NOT EDIT!
|
|
2
|
-
|
|
3
|
-
"$schema" = "../../schemas/schema.json"
|
|
4
|
-
|
|
5
|
-
[[permission]]
|
|
6
|
-
identifier = "allow-registerListener"
|
|
7
|
-
description = "Enables the registerListener command without any pre-configured scope."
|
|
8
|
-
commands.allow = ["registerListener"]
|
|
9
|
-
|
|
10
|
-
[[permission]]
|
|
11
|
-
identifier = "deny-registerListener"
|
|
12
|
-
description = "Denies the registerListener command without any pre-configured scope."
|
|
13
|
-
commands.deny = ["registerListener"]
|
|
1
|
+
# Automatically generated - DO NOT EDIT!
|
|
2
|
+
|
|
3
|
+
"$schema" = "../../schemas/schema.json"
|
|
4
|
+
|
|
5
|
+
[[permission]]
|
|
6
|
+
identifier = "allow-registerListener"
|
|
7
|
+
description = "Enables the registerListener command without any pre-configured scope."
|
|
8
|
+
commands.allow = ["registerListener"]
|
|
9
|
+
|
|
10
|
+
[[permission]]
|
|
11
|
+
identifier = "deny-registerListener"
|
|
12
|
+
description = "Denies the registerListener command without any pre-configured scope."
|
|
13
|
+
commands.deny = ["registerListener"]
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
# Automatically generated - DO NOT EDIT!
|
|
2
|
-
|
|
3
|
-
"$schema" = "../../schemas/schema.json"
|
|
4
|
-
|
|
5
|
-
[[permission]]
|
|
6
|
-
identifier = "allow-remove"
|
|
7
|
-
description = "Enables the remove command without any pre-configured scope."
|
|
8
|
-
commands.allow = ["remove"]
|
|
9
|
-
|
|
10
|
-
[[permission]]
|
|
11
|
-
identifier = "deny-remove"
|
|
12
|
-
description = "Denies the remove command without any pre-configured scope."
|
|
13
|
-
commands.deny = ["remove"]
|
|
1
|
+
# Automatically generated - DO NOT EDIT!
|
|
2
|
+
|
|
3
|
+
"$schema" = "../../schemas/schema.json"
|
|
4
|
+
|
|
5
|
+
[[permission]]
|
|
6
|
+
identifier = "allow-remove"
|
|
7
|
+
description = "Enables the remove command without any pre-configured scope."
|
|
8
|
+
commands.allow = ["remove"]
|
|
9
|
+
|
|
10
|
+
[[permission]]
|
|
11
|
+
identifier = "deny-remove"
|
|
12
|
+
description = "Denies the remove command without any pre-configured scope."
|
|
13
|
+
commands.deny = ["remove"]
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
# Automatically generated - DO NOT EDIT!
|
|
2
|
-
|
|
3
|
-
"$schema" = "../../schemas/schema.json"
|
|
4
|
-
|
|
5
|
-
[[permission]]
|
|
6
|
-
identifier = "allow-remove-listener"
|
|
7
|
-
description = "Enables the remove_listener command without any pre-configured scope."
|
|
8
|
-
commands.allow = ["remove_listener"]
|
|
9
|
-
|
|
10
|
-
[[permission]]
|
|
11
|
-
identifier = "deny-remove-listener"
|
|
12
|
-
description = "Denies the remove_listener command without any pre-configured scope."
|
|
13
|
-
commands.deny = ["remove_listener"]
|
|
1
|
+
# Automatically generated - DO NOT EDIT!
|
|
2
|
+
|
|
3
|
+
"$schema" = "../../schemas/schema.json"
|
|
4
|
+
|
|
5
|
+
[[permission]]
|
|
6
|
+
identifier = "allow-remove-listener"
|
|
7
|
+
description = "Enables the remove_listener command without any pre-configured scope."
|
|
8
|
+
commands.allow = ["remove_listener"]
|
|
9
|
+
|
|
10
|
+
[[permission]]
|
|
11
|
+
identifier = "deny-remove-listener"
|
|
12
|
+
description = "Denies the remove_listener command without any pre-configured scope."
|
|
13
|
+
commands.deny = ["remove_listener"]
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
# Automatically generated - DO NOT EDIT!
|
|
2
|
-
|
|
3
|
-
"$schema" = "../../schemas/schema.json"
|
|
4
|
-
|
|
5
|
-
[[permission]]
|
|
6
|
-
identifier = "allow-screenshot"
|
|
7
|
-
description = "Enables the screenshot command without any pre-configured scope."
|
|
8
|
-
commands.allow = ["screenshot"]
|
|
9
|
-
|
|
10
|
-
[[permission]]
|
|
11
|
-
identifier = "deny-screenshot"
|
|
12
|
-
description = "Denies the screenshot command without any pre-configured scope."
|
|
13
|
-
commands.deny = ["screenshot"]
|
|
1
|
+
# Automatically generated - DO NOT EDIT!
|
|
2
|
+
|
|
3
|
+
"$schema" = "../../schemas/schema.json"
|
|
4
|
+
|
|
5
|
+
[[permission]]
|
|
6
|
+
identifier = "allow-screenshot"
|
|
7
|
+
description = "Enables the screenshot command without any pre-configured scope."
|
|
8
|
+
commands.allow = ["screenshot"]
|
|
9
|
+
|
|
10
|
+
[[permission]]
|
|
11
|
+
identifier = "deny-screenshot"
|
|
12
|
+
description = "Denies the screenshot command without any pre-configured scope."
|
|
13
|
+
commands.deny = ["screenshot"]
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
# Automatically generated - DO NOT EDIT!
|
|
2
|
-
|
|
3
|
-
"$schema" = "../../schemas/schema.json"
|
|
4
|
-
|
|
5
|
-
[[permission]]
|
|
6
|
-
identifier = "allow-start-screen"
|
|
7
|
-
description = "Enables the start_screen command without any pre-configured scope."
|
|
8
|
-
commands.allow = ["start_screen"]
|
|
9
|
-
|
|
10
|
-
[[permission]]
|
|
11
|
-
identifier = "deny-start-screen"
|
|
12
|
-
description = "Denies the start_screen command without any pre-configured scope."
|
|
13
|
-
commands.deny = ["start_screen"]
|
|
1
|
+
# Automatically generated - DO NOT EDIT!
|
|
2
|
+
|
|
3
|
+
"$schema" = "../../schemas/schema.json"
|
|
4
|
+
|
|
5
|
+
[[permission]]
|
|
6
|
+
identifier = "allow-start-screen"
|
|
7
|
+
description = "Enables the start_screen command without any pre-configured scope."
|
|
8
|
+
commands.allow = ["start_screen"]
|
|
9
|
+
|
|
10
|
+
[[permission]]
|
|
11
|
+
identifier = "deny-start-screen"
|
|
12
|
+
description = "Denies the start_screen command without any pre-configured scope."
|
|
13
|
+
commands.deny = ["start_screen"]
|