@@ -3,8 +3,9 @@ use std::process::Command;
33
44use serde:: Serialize ;
55
6- use crate :: cli:: { human_log, json_print, CliError , JsonOk } ;
6+ use crate :: cli:: { human_log, json_print, CliError , DeviceStartPlatform , DevicesStartArgs , JsonOk } ;
77use crate :: config:: load_rmp_toml;
8+ use crate :: run:: { ensure_android_emulator, ensure_ios_simulator} ;
89use crate :: util:: { discover_xcode_dev_dir, run_capture} ;
910
1011#[ derive( Serialize ) ]
@@ -23,6 +24,15 @@ struct DeviceItem {
2324 connection_state : Option < String > , // connected|... (devices)
2425}
2526
27+ #[ derive( Serialize ) ]
28+ struct DeviceStartJson {
29+ platform : String ,
30+ kind : String ,
31+ id : String ,
32+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
33+ avd : Option < String > ,
34+ }
35+
2636#[ derive( Debug ) ]
2737struct IosDev {
2838 udid : String ,
@@ -320,3 +330,67 @@ pub fn devices_list(root: &Path, json: bool, verbose: bool) -> Result<(), CliErr
320330
321331 Ok ( ( ) )
322332}
333+
334+ pub fn devices_start (
335+ root : & Path ,
336+ json : bool ,
337+ verbose : bool ,
338+ args : DevicesStartArgs ,
339+ ) -> Result < ( ) , CliError > {
340+ let cfg = load_rmp_toml ( root) ?;
341+ match args. platform {
342+ DeviceStartPlatform :: Android => {
343+ let android = cfg
344+ . android
345+ . ok_or_else ( || CliError :: user ( "rmp.toml missing [android] section" ) ) ?;
346+ let avd = args
347+ . android
348+ . avd
349+ . or ( android. avd_name )
350+ . unwrap_or_else ( || "pika_api35" . into ( ) ) ;
351+ let serial =
352+ ensure_android_emulator ( root, & avd, args. android . serial . as_deref ( ) , verbose) ?;
353+
354+ if json {
355+ json_print ( & JsonOk {
356+ ok : true ,
357+ data : DeviceStartJson {
358+ platform : "android" . into ( ) ,
359+ kind : if serial. starts_with ( "emulator-" ) {
360+ "emulator" . into ( )
361+ } else {
362+ "device" . into ( )
363+ } ,
364+ id : serial,
365+ avd : Some ( avd) ,
366+ } ,
367+ } ) ;
368+ } else {
369+ eprintln ! ( "ok: android target ready" ) ;
370+ }
371+ }
372+ DeviceStartPlatform :: Ios => {
373+ let _ios = cfg
374+ . ios
375+ . ok_or_else ( || CliError :: user ( "rmp.toml missing [ios] section" ) ) ?;
376+ let dev_dir = discover_xcode_dev_dir ( ) ?;
377+ let udid = ensure_ios_simulator ( & dev_dir, args. ios . udid . as_deref ( ) , verbose) ?;
378+ let _ = Command :: new ( "open" ) . arg ( "-a" ) . arg ( "Simulator" ) . status ( ) ;
379+
380+ if json {
381+ json_print ( & JsonOk {
382+ ok : true ,
383+ data : DeviceStartJson {
384+ platform : "ios" . into ( ) ,
385+ kind : "simulator" . into ( ) ,
386+ id : udid,
387+ avd : None ,
388+ } ,
389+ } ) ;
390+ } else {
391+ eprintln ! ( "ok: ios simulator ready" ) ;
392+ }
393+ }
394+ }
395+ Ok ( ( ) )
396+ }
0 commit comments