Skip to content

Commit e070ce1

Browse files
gabebearshazron
authored andcommitted
feat: Add JSON output for copying, installing, and launching the debug server (#397)
1 parent 2306cc4 commit e070ce1

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

src/ios-deploy/ios-deploy.m

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ void on_error(NSString* format, ...)
133133
NSString* str = [[[NSString alloc] initWithFormat:format arguments:valist] autorelease];
134134
va_end(valist);
135135

136-
NSLog(@"[ !! ] %@", str);
136+
if (!_json_output) {
137+
NSLog(@"[ !! ] %@", str);
138+
}
137139

138140
exit(exitcode_error);
139141
}
@@ -556,6 +558,12 @@ void mount_developer_image(AMDeviceRef device) {
556558
} else if (result == 0xe8000076 /* already mounted */) {
557559
NSLogOut(@"[ 95%%] Developer disk image already mounted");
558560
} else {
561+
if (result == 0xe80000e2 /* device locked */) {
562+
NSLogOut(@"The device is locked.");
563+
NSLogJSON(@{@"Event": @"Error",
564+
@"Status": @"DeviceLocked"
565+
});
566+
}
559567
on_error(@"Unable to mount developer disk image. (%x)", result);
560568
}
561569

@@ -572,7 +580,13 @@ mach_error_t transfer_callback(CFDictionaryRef dict, int arg) {
572580
CFStringRef path = CFDictionaryGetValue(dict, CFSTR("Path"));
573581

574582
if ((last_path == NULL || !CFEqual(path, last_path)) && !CFStringHasSuffix(path, CFSTR(".ipa"))) {
575-
NSLogOut(@"[%3d%%] Copying %@ to device", percent / 2, path);
583+
int overall_percent = percent / 2;
584+
NSLogOut(@"[%3d%%] Copying %@ to device", overall_percent, path);
585+
NSLogJSON(@{@"Event": @"BundleCopy",
586+
@"OverallPercent": @(overall_percent),
587+
@"Percent": @(percent),
588+
@"Path": (__bridge NSString *)path
589+
});
576590
}
577591

578592
if (last_path != NULL) {
@@ -589,7 +603,13 @@ mach_error_t install_callback(CFDictionaryRef dict, int arg) {
589603
CFStringRef status = CFDictionaryGetValue(dict, CFSTR("Status"));
590604
CFNumberGetValue(CFDictionaryGetValue(dict, CFSTR("PercentComplete")), kCFNumberSInt32Type, &percent);
591605

592-
NSLogOut(@"[%3d%%] %@", (percent / 2) + 50, status);
606+
int overall_percent = (percent / 2) + 50;
607+
NSLogOut(@"[%3d%%] %@", overall_percent, status);
608+
NSLogJSON(@{@"Event": @"BundleInstall",
609+
@"OverallPercent": @(overall_percent),
610+
@"Percent": @(percent),
611+
@"Status": (__bridge NSString *)status
612+
});
593613
return 0;
594614
}
595615

@@ -1113,6 +1133,10 @@ void launch_debugserver_only(AMDeviceRef device, CFURLRef url)
11131133

11141134
NSLogOut(@"debugserver port: %d", port);
11151135
NSLogOut(@"App path: %@", device_app_path);
1136+
NSLogJSON(@{@"Event": @"DebugServerLaunched",
1137+
@"Port": @(port),
1138+
@"Path": (__bridge NSString *)device_app_path
1139+
});
11161140
}
11171141

11181142
CFStringRef get_bundle_id(CFURLRef app_url)
@@ -1717,6 +1741,11 @@ void handle_device(AMDeviceRef device) {
17171741
CFRelease(options);
17181742

17191743
NSLogOut(@"[100%%] Installed package %@", [NSString stringWithUTF8String:app_path]);
1744+
NSLogJSON(@{@"Event": @"BundleInstall",
1745+
@"OverallPercent": @(100),
1746+
@"Percent": @(100),
1747+
@"Status": @"Complete"
1748+
});
17201749
}
17211750

17221751
if (!debug)
@@ -1755,7 +1784,7 @@ void timeout_callback(CFRunLoopTimerRef timer, void *info) {
17551784
return;
17561785

17571786
// App running for too long
1758-
NSLog(@"[ !! ] App is running for too long");
1787+
NSLogOut(@"[ !! ] App is running for too long");
17591788
exit(exitcode_timeout);
17601789
return;
17611790
} else if ((!found_device) && (!detect_only)) {

0 commit comments

Comments
 (0)