adb-screenshot-cli 2.0.0 → 2.1.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 (83) hide show
  1. package/README.md +95 -57
  2. package/dist/adapters/android.d.ts +8 -1
  3. package/dist/adapters/android.d.ts.map +1 -1
  4. package/dist/adapters/android.js +286 -9
  5. package/dist/adapters/android.js.map +1 -1
  6. package/dist/adapters/base.d.ts +5 -3
  7. package/dist/adapters/base.d.ts.map +1 -1
  8. package/dist/adapters/harmony.d.ts +8 -1
  9. package/dist/adapters/harmony.d.ts.map +1 -1
  10. package/dist/adapters/harmony.js +274 -12
  11. package/dist/adapters/harmony.js.map +1 -1
  12. package/dist/adapters/index.d.ts +5 -1
  13. package/dist/adapters/index.d.ts.map +1 -1
  14. package/dist/adapters/index.js +28 -4
  15. package/dist/adapters/index.js.map +1 -1
  16. package/dist/adapters/ios.d.ts +13 -2
  17. package/dist/adapters/ios.d.ts.map +1 -1
  18. package/dist/adapters/ios.js +479 -24
  19. package/dist/adapters/ios.js.map +1 -1
  20. package/dist/cli.js +216 -17
  21. package/dist/cli.js.map +1 -1
  22. package/dist/commands/devices.d.ts +8 -0
  23. package/dist/commands/devices.d.ts.map +1 -0
  24. package/dist/commands/devices.js +33 -0
  25. package/dist/commands/devices.js.map +1 -0
  26. package/dist/commands/doctor.d.ts +9 -0
  27. package/dist/commands/doctor.d.ts.map +1 -0
  28. package/dist/commands/doctor.js +177 -0
  29. package/dist/commands/doctor.js.map +1 -0
  30. package/dist/commands/record.d.ts +3 -0
  31. package/dist/commands/record.d.ts.map +1 -0
  32. package/dist/commands/record.js +155 -0
  33. package/dist/commands/record.js.map +1 -0
  34. package/dist/commands/screenshot.d.ts +2 -2
  35. package/dist/commands/screenshot.d.ts.map +1 -1
  36. package/dist/commands/screenshot.js +65 -93
  37. package/dist/commands/screenshot.js.map +1 -1
  38. package/dist/index.d.ts +11 -3
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +8 -2
  41. package/dist/index.js.map +1 -1
  42. package/dist/types.d.ts +84 -0
  43. package/dist/types.d.ts.map +1 -1
  44. package/dist/utils/binary.d.ts +8 -0
  45. package/dist/utils/binary.d.ts.map +1 -0
  46. package/dist/utils/binary.js +100 -0
  47. package/dist/utils/binary.js.map +1 -0
  48. package/dist/utils/clipboard.d.ts +5 -0
  49. package/dist/utils/clipboard.d.ts.map +1 -1
  50. package/dist/utils/clipboard.js +57 -4
  51. package/dist/utils/clipboard.js.map +1 -1
  52. package/dist/utils/config.d.ts.map +1 -1
  53. package/dist/utils/config.js +13 -0
  54. package/dist/utils/config.js.map +1 -1
  55. package/dist/utils/device.d.ts +26 -0
  56. package/dist/utils/device.d.ts.map +1 -0
  57. package/dist/utils/device.js +165 -0
  58. package/dist/utils/device.js.map +1 -0
  59. package/dist/utils/doctor-fix.d.ts +25 -0
  60. package/dist/utils/doctor-fix.d.ts.map +1 -0
  61. package/dist/utils/doctor-fix.js +319 -0
  62. package/dist/utils/doctor-fix.js.map +1 -0
  63. package/dist/utils/errors.d.ts +15 -0
  64. package/dist/utils/errors.d.ts.map +1 -0
  65. package/dist/utils/errors.js +20 -0
  66. package/dist/utils/errors.js.map +1 -0
  67. package/dist/utils/ios-avf-recorder.d.ts +10 -0
  68. package/dist/utils/ios-avf-recorder.d.ts.map +1 -0
  69. package/dist/utils/ios-avf-recorder.js +499 -0
  70. package/dist/utils/ios-avf-recorder.js.map +1 -0
  71. package/dist/utils/logger.d.ts +63 -0
  72. package/dist/utils/logger.d.ts.map +1 -1
  73. package/dist/utils/logger.js +344 -11
  74. package/dist/utils/logger.js.map +1 -1
  75. package/dist/utils/terminal-image.d.ts +13 -0
  76. package/dist/utils/terminal-image.d.ts.map +1 -0
  77. package/dist/utils/terminal-image.js +129 -0
  78. package/dist/utils/terminal-image.js.map +1 -0
  79. package/package.json +14 -6
  80. package/dist/utils/adb.d.ts +0 -7
  81. package/dist/utils/adb.d.ts.map +0 -1
  82. package/dist/utils/adb.js +0 -41
  83. package/dist/utils/adb.js.map +0 -1
@@ -0,0 +1,499 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { existsSync, mkdirSync, rmSync, statSync, writeFileSync } from 'node:fs';
3
+ import { homedir } from 'node:os';
4
+ import { join } from 'node:path';
5
+ import { execa } from 'execa';
6
+ import { CliError } from './errors.js';
7
+ const SWIFT_RECORDER_SOURCE = String.raw `import Foundation
8
+ import AVFoundation
9
+ import CoreMediaIO
10
+
11
+ struct Options {
12
+ var outputPath: String = ""
13
+ var deviceName: String?
14
+ var udid: String?
15
+ var duration: Double?
16
+ }
17
+
18
+ func parseArgs() -> Options {
19
+ var opts = Options()
20
+ let args = CommandLine.arguments
21
+ var i = 1
22
+ while i < args.count {
23
+ switch args[i] {
24
+ case "--output":
25
+ if i + 1 < args.count { opts.outputPath = args[i + 1]; i += 1 }
26
+ case "--name":
27
+ if i + 1 < args.count { opts.deviceName = args[i + 1]; i += 1 }
28
+ case "--udid":
29
+ if i + 1 < args.count { opts.udid = args[i + 1]; i += 1 }
30
+ case "--duration":
31
+ if i + 1 < args.count { opts.duration = Double(args[i + 1]); i += 1 }
32
+ default:
33
+ break
34
+ }
35
+ i += 1
36
+ }
37
+ return opts
38
+ }
39
+
40
+ func fail(_ code: String, _ message: String) -> Never {
41
+ fputs("\(code): \(message)\n", stderr)
42
+ fflush(stderr)
43
+ exit(1)
44
+ }
45
+
46
+ func enableScreenCaptureDevices() {
47
+ var prop = CMIOObjectPropertyAddress(
48
+ mSelector: CMIOObjectPropertySelector(kCMIOHardwarePropertyAllowScreenCaptureDevices),
49
+ mScope: CMIOObjectPropertyScope(kCMIOObjectPropertyScopeGlobal),
50
+ mElement: CMIOObjectPropertyElement(kCMIOObjectPropertyElementMain)
51
+ )
52
+ var allow: UInt32 = 1
53
+ CMIOObjectSetPropertyData(
54
+ CMIOObjectID(kCMIOObjectSystemObject),
55
+ &prop,
56
+ 0,
57
+ nil,
58
+ UInt32(MemoryLayout<UInt32>.size),
59
+ &allow
60
+ )
61
+ }
62
+
63
+ func ensureCameraPermission() {
64
+ let status = AVCaptureDevice.authorizationStatus(for: .video)
65
+ switch status {
66
+ case .authorized:
67
+ return
68
+ case .notDetermined:
69
+ let sem = DispatchSemaphore(value: 0)
70
+ var granted = false
71
+ AVCaptureDevice.requestAccess(for: .video) { ok in
72
+ granted = ok
73
+ sem.signal()
74
+ }
75
+ _ = sem.wait(timeout: .now() + 30)
76
+ if !granted {
77
+ fail("PERMISSION_DENIED", "macOS camera permission denied for iOS screen capture.")
78
+ }
79
+ case .denied, .restricted:
80
+ fail("PERMISSION_DENIED", "macOS camera permission denied for terminal app.")
81
+ @unknown default:
82
+ return
83
+ }
84
+ }
85
+
86
+ func normalizeId(_ s: String) -> String {
87
+ return s.replacingOccurrences(of: "-", with: "").lowercased()
88
+ }
89
+
90
+ func findTargetDevice(opts: Options) -> AVCaptureDevice? {
91
+ for _ in 0..<18 {
92
+ let discovery = AVCaptureDevice.DiscoverySession(
93
+ deviceTypes: [.external, .continuityCamera],
94
+ mediaType: .muxed,
95
+ position: .unspecified
96
+ )
97
+ let iosDevices = discovery.devices.filter {
98
+ $0.modelID.lowercased().contains("ios") || $0.manufacturer.lowercased().contains("apple")
99
+ }
100
+ let candidates = iosDevices.isEmpty ? discovery.devices : iosDevices
101
+
102
+ if !candidates.isEmpty {
103
+ if let udid = opts.udid, !udid.isEmpty {
104
+ let targetNorm = normalizeId(udid)
105
+ if let matched = candidates.first(where: { normalizeId($0.uniqueID) == targetNorm || normalizeId($0.uniqueID).contains(targetNorm) }) {
106
+ return matched
107
+ }
108
+ }
109
+ if let name = opts.deviceName, !name.isEmpty {
110
+ if let exact = candidates.first(where: { $0.localizedName == name }) {
111
+ return exact
112
+ }
113
+ let lower = name.lowercased()
114
+ if let partial = candidates.first(where: {
115
+ $0.localizedName.lowercased().contains(lower) || lower.contains($0.localizedName.lowercased())
116
+ }) {
117
+ return partial
118
+ }
119
+ }
120
+ let hasExplicitTarget = (opts.udid != nil && !opts.udid!.isEmpty) || (opts.deviceName != nil && !opts.deviceName!.isEmpty)
121
+ if !hasExplicitTarget && candidates.count == 1 {
122
+ return candidates[0]
123
+ }
124
+ }
125
+ RunLoop.current.run(until: Date(timeIntervalSinceNow: 0.2))
126
+ }
127
+ return nil
128
+ }
129
+
130
+ final class RecorderDelegate: NSObject, AVCaptureFileOutputRecordingDelegate {
131
+ let session: AVCaptureSession
132
+ let output: AVCaptureMovieFileOutput
133
+ let tempMovURL: URL
134
+ let finalMP4URL: URL
135
+ let duration: Double?
136
+ private var stopTriggered = false
137
+
138
+ init(
139
+ session: AVCaptureSession,
140
+ output: AVCaptureMovieFileOutput,
141
+ tempMovURL: URL,
142
+ finalMP4URL: URL,
143
+ duration: Double?
144
+ ) {
145
+ self.session = session
146
+ self.output = output
147
+ self.tempMovURL = tempMovURL
148
+ self.finalMP4URL = finalMP4URL
149
+ self.duration = duration
150
+ }
151
+
152
+ func requestStop() {
153
+ DispatchQueue.main.async {
154
+ if !self.stopTriggered {
155
+ self.stopTriggered = true
156
+ if self.output.isRecording {
157
+ self.output.stopRecording()
158
+ } else {
159
+ self.session.stopRunning()
160
+ try? FileManager.default.removeItem(at: self.tempMovURL)
161
+ fail("NO_VIDEO_DATA", "Recording stopped before any video frames were captured.")
162
+ }
163
+ }
164
+ }
165
+ }
166
+
167
+ func fileOutput(
168
+ _ output: AVCaptureFileOutput,
169
+ didStartRecordingTo fileURL: URL,
170
+ from connections: [AVCaptureConnection]
171
+ ) {
172
+ print("RECORDING_STARTED")
173
+ fflush(stdout)
174
+ if let dur = duration, dur > 0 {
175
+ DispatchQueue.main.asyncAfter(deadline: .now() + dur) {
176
+ self.requestStop()
177
+ }
178
+ }
179
+ }
180
+
181
+ func fileOutput(
182
+ _ output: AVCaptureFileOutput,
183
+ didFinishRecordingTo outputFileURL: URL,
184
+ from connections: [AVCaptureConnection],
185
+ error: Error?
186
+ ) {
187
+ session.stopRunning()
188
+
189
+ if let err = error as NSError? {
190
+ let finishedFlag = err.userInfo[AVErrorRecordingSuccessfullyFinishedKey] as? Bool ?? false
191
+ if !finishedFlag {
192
+ try? FileManager.default.removeItem(at: tempMovURL)
193
+ fail("RECORD_ERROR", err.localizedDescription)
194
+ }
195
+ }
196
+
197
+ exportToMP4(sourceURL: tempMovURL, destURL: finalMP4URL)
198
+ }
199
+
200
+ private func exportToMP4(sourceURL: URL, destURL: URL) {
201
+ let fm = FileManager.default
202
+ let tempMP4URL = URL(fileURLWithPath: destURL.path + ".export.\(ProcessInfo.processInfo.processIdentifier).mp4")
203
+ try? fm.removeItem(at: tempMP4URL)
204
+
205
+ let asset = AVURLAsset(url: sourceURL)
206
+ let composition = AVMutableComposition()
207
+
208
+ let videoTracks = asset.tracks(withMediaType: .video)
209
+ guard let srcVideo = videoTracks.first,
210
+ let compVideo = composition.addMutableTrack(withMediaType: .video, preferredTrackID: kCMPersistentTrackID_Invalid) else {
211
+ try? fm.removeItem(at: sourceURL)
212
+ fail("EXPORT_ERROR", "No video track found in recorded stream.")
213
+ }
214
+
215
+ do {
216
+ try compVideo.insertTimeRange(CMTimeRange(start: .zero, duration: asset.duration), of: srcVideo, at: .zero)
217
+ compVideo.preferredTransform = srcVideo.preferredTransform
218
+ } catch {
219
+ try? fm.removeItem(at: sourceURL)
220
+ fail("EXPORT_ERROR", "Failed to build MP4 video track: \(error.localizedDescription)")
221
+ }
222
+
223
+ guard let exporter = AVAssetExportSession(asset: composition, presetName: AVAssetExportPresetPassthrough) else {
224
+ try? fm.removeItem(at: sourceURL)
225
+ fail("EXPORT_ERROR", "Failed to initialize AVAssetExportSession.")
226
+ }
227
+ exporter.outputURL = tempMP4URL
228
+ exporter.outputFileType = .mp4
229
+ exporter.shouldOptimizeForNetworkUse = true
230
+
231
+ let promoteAndExit: () -> Void = {
232
+ try? fm.removeItem(at: sourceURL)
233
+ do {
234
+ try? fm.removeItem(at: destURL)
235
+ try fm.moveItem(at: tempMP4URL, to: destURL)
236
+ exit(0)
237
+ } catch {
238
+ try? fm.removeItem(at: tempMP4URL)
239
+ fail("EXPORT_ERROR", "Failed to write final MP4: \(error.localizedDescription)")
240
+ }
241
+ }
242
+
243
+ exporter.exportAsynchronously {
244
+ if exporter.status == .completed {
245
+ promoteAndExit()
246
+ return
247
+ }
248
+
249
+ // Fallback to HighestQuality if passthrough fails for this stream format
250
+ try? fm.removeItem(at: tempMP4URL)
251
+ guard let fallback = AVAssetExportSession(asset: asset, presetName: AVAssetExportPresetHighestQuality) else {
252
+ try? fm.removeItem(at: sourceURL)
253
+ fail("EXPORT_ERROR", exporter.error?.localizedDescription ?? "MP4 export failed.")
254
+ }
255
+ fallback.outputURL = tempMP4URL
256
+ fallback.outputFileType = .mp4
257
+ fallback.shouldOptimizeForNetworkUse = true
258
+ fallback.exportAsynchronously {
259
+ if fallback.status == .completed {
260
+ promoteAndExit()
261
+ return
262
+ }
263
+ try? fm.removeItem(at: sourceURL)
264
+ try? fm.removeItem(at: tempMP4URL)
265
+ fail("EXPORT_ERROR", fallback.error?.localizedDescription ?? "MP4 export failed.")
266
+ }
267
+ }
268
+ }
269
+ }
270
+
271
+ let opts = parseArgs()
272
+ if opts.outputPath.isEmpty {
273
+ fail("INVALID_ARGS", "Missing --output path.")
274
+ }
275
+
276
+ enableScreenCaptureDevices()
277
+ ensureCameraPermission()
278
+
279
+ guard let device = findTargetDevice(opts: opts) else {
280
+ fail("DEVICE_NOT_FOUND", "Unable to discover physical iOS device in CoreMediaIO / AVFoundation. Unlock the iPhone and trust this Mac.")
281
+ }
282
+
283
+ let session = AVCaptureSession()
284
+ let input: AVCaptureDeviceInput
285
+ do {
286
+ input = try AVCaptureDeviceInput(device: device)
287
+ } catch {
288
+ fail("CAPTURE_INIT_ERROR", "Failed to open iOS capture input: \(error.localizedDescription)")
289
+ }
290
+
291
+ guard session.canAddInput(input) else {
292
+ fail("CAPTURE_INIT_ERROR", "Cannot add iOS device capture input to session.")
293
+ }
294
+ session.addInput(input)
295
+
296
+ let movieOutput = AVCaptureMovieFileOutput()
297
+ guard session.canAddOutput(movieOutput) else {
298
+ fail("CAPTURE_INIT_ERROR", "Cannot add movie output to session.")
299
+ }
300
+ session.addOutput(movieOutput)
301
+
302
+ let finalURL = URL(fileURLWithPath: opts.outputPath)
303
+ let tempMovURL = URL(fileURLWithPath: opts.outputPath + ".tmp.\(ProcessInfo.processInfo.processIdentifier).mov")
304
+ try? FileManager.default.removeItem(at: tempMovURL)
305
+
306
+ let delegate = RecorderDelegate(
307
+ session: session,
308
+ output: movieOutput,
309
+ tempMovURL: tempMovURL,
310
+ finalMP4URL: finalURL,
311
+ duration: opts.duration
312
+ )
313
+
314
+ signal(SIGINT, SIG_IGN)
315
+ signal(SIGTERM, SIG_IGN)
316
+
317
+ let sigintSrc = DispatchSource.makeSignalSource(signal: SIGINT, queue: .main)
318
+ sigintSrc.setEventHandler { delegate.requestStop() }
319
+ sigintSrc.resume()
320
+
321
+ let sigtermSrc = DispatchSource.makeSignalSource(signal: SIGTERM, queue: .main)
322
+ sigtermSrc.setEventHandler { delegate.requestStop() }
323
+ sigtermSrc.resume()
324
+
325
+ session.startRunning()
326
+ movieOutput.startRecording(to: tempMovURL, recordingDelegate: delegate)
327
+
328
+ RunLoop.main.run()
329
+ `;
330
+ const CACHE_DIR = join(homedir(), '.cache', 'adb-screenshot-cli');
331
+ function getBinaryPath() {
332
+ const hash = createHash('sha256').update(SWIFT_RECORDER_SOURCE).digest('hex').slice(0, 12);
333
+ return join(CACHE_DIR, `ios-avf-recorder-${hash}`);
334
+ }
335
+ export async function isAvfRecorderAvailable() {
336
+ if (process.platform !== 'darwin')
337
+ return false;
338
+ try {
339
+ await execa('xcrun', ['--find', 'swiftc']);
340
+ return true;
341
+ }
342
+ catch {
343
+ return false;
344
+ }
345
+ }
346
+ export async function ensureAvfRecorderBinary() {
347
+ const binPath = getBinaryPath();
348
+ if (existsSync(binPath)) {
349
+ return binPath;
350
+ }
351
+ mkdirSync(CACHE_DIR, { recursive: true });
352
+ const tempSwift = join(CACHE_DIR, `ios-avf-recorder-${process.pid}-${Date.now()}.swift`);
353
+ writeFileSync(tempSwift, SWIFT_RECORDER_SOURCE, 'utf-8');
354
+ try {
355
+ await execa('xcrun', [
356
+ 'swiftc',
357
+ '-swift-version',
358
+ '5',
359
+ '-O',
360
+ '-framework',
361
+ 'AVFoundation',
362
+ '-framework',
363
+ 'CoreMediaIO',
364
+ tempSwift,
365
+ '-o',
366
+ binPath,
367
+ ]);
368
+ }
369
+ catch (err) {
370
+ const msg = err instanceof Error ? err.message : String(err);
371
+ throw new CliError('CAPTURE_FAILED', `编译 macOS 原生 iOS 录屏组件失败: ${msg}`, {
372
+ hints: ['请确认已安装 Xcode 或 Command Line Tools(`xcode-select --install`)。'],
373
+ cause: err,
374
+ });
375
+ }
376
+ finally {
377
+ rmSync(tempSwift, { force: true });
378
+ }
379
+ return binPath;
380
+ }
381
+ function buildAvfHints(stderr) {
382
+ if (stderr.includes('PERMISSION_DENIED')) {
383
+ return [
384
+ '请在「系统设置 > 隐私与安全性 > 相机」中允许当前终端应用访问相机。',
385
+ '若使用其他终端或首次授权,请在终端中执行 `ads rec` 后确认弹出的权限提示。',
386
+ ];
387
+ }
388
+ return [
389
+ '请确认 iPhone 已通过 USB 线连接、屏幕已解锁并已「信任此电脑」。',
390
+ '若 QuickTime Player 也无法看到设备,请重新插拔数据线后再试。',
391
+ ];
392
+ }
393
+ export async function startAvfRecording(options) {
394
+ const binPath = await ensureAvfRecorderBinary();
395
+ const args = ['--output', options.outputPath];
396
+ if (options.deviceName) {
397
+ args.push('--name', options.deviceName);
398
+ }
399
+ if (options.udid) {
400
+ args.push('--udid', options.udid);
401
+ }
402
+ if (options.duration !== undefined) {
403
+ args.push('--duration', String(options.duration));
404
+ }
405
+ const child = execa(binPath, args, {
406
+ reject: false,
407
+ detached: true,
408
+ });
409
+ // Wait for RECORDING_STARTED on stdout, early exit, or cancellation signal
410
+ await new Promise((resolve, reject) => {
411
+ let settled = false;
412
+ let stdoutBuf = '';
413
+ let stderrBuf = '';
414
+ const cleanup = () => {
415
+ clearTimeout(timer);
416
+ child.stdout?.removeListener('data', onStdout);
417
+ child.stderr?.removeListener('data', onStderr);
418
+ process.removeListener('SIGINT', onAbortSignal);
419
+ process.removeListener('SIGTERM', onAbortSignal);
420
+ };
421
+ const onAbortSignal = () => {
422
+ if (settled)
423
+ return;
424
+ settled = true;
425
+ cleanup();
426
+ try {
427
+ child.kill('SIGTERM');
428
+ }
429
+ catch {
430
+ // ignore
431
+ }
432
+ reject(new CliError('CAPTURE_FAILED', '已取消 iOS 录屏启动。'));
433
+ };
434
+ const onStdout = (chunk) => {
435
+ stdoutBuf += chunk.toString();
436
+ if (!settled && stdoutBuf.includes('RECORDING_STARTED')) {
437
+ settled = true;
438
+ cleanup();
439
+ resolve();
440
+ }
441
+ };
442
+ const onStderr = (chunk) => {
443
+ stderrBuf += chunk.toString();
444
+ };
445
+ const timer = setTimeout(() => {
446
+ if (settled)
447
+ return;
448
+ settled = true;
449
+ cleanup();
450
+ resolve();
451
+ }, 35000);
452
+ process.on('SIGINT', onAbortSignal);
453
+ process.on('SIGTERM', onAbortSignal);
454
+ child.stdout?.on('data', onStdout);
455
+ child.stderr?.on('data', onStderr);
456
+ void child.then((res) => {
457
+ if (settled)
458
+ return;
459
+ settled = true;
460
+ cleanup();
461
+ const errText = (typeof res.stderr === 'string' && res.stderr.trim()) ||
462
+ stderrBuf.trim() ||
463
+ `进程提前退出 (code ${res.exitCode ?? 'unknown'})`;
464
+ reject(new CliError('CAPTURE_FAILED', `iOS 真机录屏启动失败: ${errText}`, {
465
+ hints: buildAvfHints(errText),
466
+ }));
467
+ });
468
+ });
469
+ let stopPromise;
470
+ const finalize = async () => {
471
+ const res = await child;
472
+ const hasFile = existsSync(options.outputPath) && statSync(options.outputPath).size > 0;
473
+ if (res.exitCode !== 0 || !hasFile) {
474
+ const stderr = typeof res.stderr === 'string' ? res.stderr.trim() : '';
475
+ const detail = stderr || `进程退出码: ${res.exitCode ?? 'unknown'}`;
476
+ throw new CliError('CAPTURE_FAILED', `iOS 真机录屏失败: ${detail}`, {
477
+ hints: buildAvfHints(detail),
478
+ });
479
+ }
480
+ };
481
+ const stop = () => {
482
+ if (!stopPromise) {
483
+ try {
484
+ child.kill('SIGINT');
485
+ }
486
+ catch {
487
+ // Process may already be exiting
488
+ }
489
+ stopPromise = finalize();
490
+ }
491
+ return stopPromise;
492
+ };
493
+ const done = (async () => {
494
+ await child;
495
+ await finalize();
496
+ })();
497
+ return { stop, done };
498
+ }
499
+ //# sourceMappingURL=ios-avf-recorder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ios-avf-recorder.js","sourceRoot":"","sources":["../../src/utils/ios-avf-recorder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACjF,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAGvC,MAAM,qBAAqB,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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I,EAAE,CAAC;AACxB,CAAC"}
@@ -1,8 +1,71 @@
1
+ import type { DeviceKind, IconTheme, Platform } from '../types.js';
2
+ export interface LoggerMode {
3
+ json: boolean;
4
+ quiet: boolean;
5
+ }
6
+ export interface IconSet {
7
+ screenshot: string;
8
+ record: string;
9
+ device: string;
10
+ capture: string;
11
+ launch: string;
12
+ recording: string;
13
+ wait: string;
14
+ ok: string;
15
+ warn: string;
16
+ error: string;
17
+ folder: string;
18
+ info: string;
19
+ clipboard: string;
20
+ preview: string;
21
+ done: string;
22
+ search: string;
23
+ doctor: string;
24
+ host: string;
25
+ globe: string;
26
+ pkg: string;
27
+ message: string;
28
+ hint: string;
29
+ }
30
+ export declare function setIconTheme(theme: IconTheme): void;
31
+ export declare function getIconTheme(): IconTheme;
32
+ export declare function getIcons(): IconSet;
33
+ export declare function setLoggerMode(next: Partial<LoggerMode>): void;
34
+ export declare function getLoggerMode(): LoggerMode;
35
+ export declare function isColorEnabled(): boolean;
36
+ export declare function platformIcon(platform: Platform): string;
37
+ export declare function platformName(platform: Platform): string;
38
+ export declare function deviceKindLabel(kind?: DeviceKind): string | undefined;
39
+ export declare const style: {
40
+ bold: (s: string) => string;
41
+ dim: (s: string) => string;
42
+ red: (s: string) => string;
43
+ green: (s: string) => string;
44
+ yellow: (s: string) => string;
45
+ blue: (s: string) => string;
46
+ magenta: (s: string) => string;
47
+ cyan: (s: string) => string;
48
+ badge: (platform: Platform, kind?: DeviceKind) => string;
49
+ };
50
+ export declare function formatBanner(icon: string, title: string, subtitle?: string): string;
51
+ export declare function formatBytes(bytes: number): string;
52
+ export declare function formatDuration(ms: number): string;
1
53
  export declare const logger: {
2
54
  info: (msg: string) => void;
3
55
  success: (msg: string) => void;
4
56
  error: (msg: string) => void;
5
57
  warn: (msg: string) => void;
6
58
  step: (msg: string) => void;
59
+ plain: (msg: string) => void;
60
+ blank: () => void;
61
+ heading: (title: string) => void;
62
+ banner: (icon: string, title: string, subtitle?: string) => void;
63
+ cardStart: (icon: string, title: string) => void;
64
+ cardLine: (text: string) => void;
65
+ cardDivider: (text: string) => void;
66
+ cardEnd: (text: string) => void;
67
+ treeItems: (items: string[], indent?: string) => void;
7
68
  };
69
+ export declare function printJson(payload: unknown): void;
70
+ export declare function printError(command: string, err: unknown, json: boolean): void;
8
71
  //# sourceMappingURL=logger.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,MAAM;gBACL,MAAM;mBACH,MAAM;iBACR,MAAM;gBACP,MAAM;gBACN,MAAM;CACnB,CAAC"}
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEnE,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,OAAO;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,E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