@@ -71,8 +71,8 @@ class IOSSimulatorUtils {
7171 return < IOSSimulator > [];
7272 }
7373
74- final List <SimDevice > connected = await _simControl.getConnectedDevices ();
75- return connected.map <IOSSimulator ?>((SimDevice device) {
74+ final List <BootedSimDevice > connected = await _simControl.getConnectedDevices ();
75+ return connected.map <IOSSimulator ?>((BootedSimDevice device) {
7676 final String ? udid = device.udid;
7777 final String ? name = device.name;
7878 if (udid == null ) {
@@ -109,30 +109,45 @@ class SimControl {
109109
110110 /// Runs `simctl list --json` and returns the JSON of the corresponding
111111 /// [section] .
112- Future <Map <String , Object ?>> _list ( SimControlListSection section ) async {
113- // Sample output from `simctl list --json`:
112+ Future <Map <String , Object ?>> _listBootedDevices ( ) async {
113+ // Sample output from `simctl list available booted --json`:
114114 //
115115 // {
116- // "devicetypes": { ... },
117- // "runtimes": { ... },
118116 // "devices" : {
119- // "com.apple.CoreSimulator.SimRuntime.iOS-8-2 " : [
117+ // "com.apple.CoreSimulator.SimRuntime.iOS-14-0 " : [
120118 // {
121- // "state" : "Shutdown",
122- // "availability" : " (unavailable, runtime profile not found)",
123- // "name" : "iPhone 4s",
124- // "udid" : "1913014C-6DCB-485D-AC6B-7CD76D322F5B"
125- // },
126- // ...
127- // },
128- // "pairs": { ... },
119+ // "lastBootedAt" : "2022-07-26T01:46:23Z",
120+ // "dataPath" : "\/Users\/magder\/Library\/Developer\/CoreSimulator\/Devices\/9EC90A99-6924-472D-8CDD-4D8234AB4779\/data",
121+ // "dataPathSize" : 1620578304,
122+ // "logPath" : "\/Users\/magder\/Library\/Logs\/CoreSimulator\/9EC90A99-6924-472D-8CDD-4D8234AB4779",
123+ // "udid" : "9EC90A99-6924-472D-8CDD-4D8234AB4779",
124+ // "isAvailable" : true,
125+ // "logPathSize" : 9740288,
126+ // "deviceTypeIdentifier" : "com.apple.CoreSimulator.SimDeviceType.iPhone-11",
127+ // "state" : "Booted",
128+ // "name" : "iPhone 11"
129+ // }
130+ // ],
131+ // "com.apple.CoreSimulator.SimRuntime.iOS-13-0" : [
132+ //
133+ // ],
134+ // "com.apple.CoreSimulator.SimRuntime.iOS-12-4" : [
135+ //
136+ // ],
137+ // "com.apple.CoreSimulator.SimRuntime.iOS-16-0" : [
138+ //
139+ // ]
140+ // }
141+ // }
129142
130143 final List <String > command = < String > [
131144 ..._xcode.xcrunCommand (),
132145 'simctl' ,
133146 'list' ,
147+ 'devices' ,
148+ 'booted' ,
149+ 'iOS' ,
134150 '--json' ,
135- section.name,
136151 ];
137152 _logger.printTrace (command.join (' ' ));
138153 final RunResult results = await _processUtils.run (command);
@@ -141,7 +156,7 @@ class SimControl {
141156 return < String , Map <String , Object ?>> {};
142157 }
143158 try {
144- final Object ? decodeResult = (json.decode (results.stdout) as Map <String , Object ?>)[section.name ];
159+ final Object ? decodeResult = (json.decode (results.stdout) as Map <String , Object ?>)['devices' ];
145160 if (decodeResult is Map <String , Object ?>) {
146161 return decodeResult;
147162 }
@@ -156,30 +171,24 @@ class SimControl {
156171 }
157172 }
158173
159- /// Returns a list of all available devices, both potential and connected .
160- Future <List <SimDevice >> getDevices () async {
161- final List <SimDevice > devices = < SimDevice > [];
174+ /// Returns all the connected simulator devices .
175+ Future <List <BootedSimDevice >> getConnectedDevices () async {
176+ final List <BootedSimDevice > devices = < BootedSimDevice > [];
162177
163- final Map <String , Object ?> devicesSection = await _list ( SimControlListSection .devices );
178+ final Map <String , Object ?> devicesSection = await _listBootedDevices ( );
164179
165180 for (final String deviceCategory in devicesSection.keys) {
166181 final Object ? devicesData = devicesSection[deviceCategory];
167182 if (devicesData != null && devicesData is List <Object ?>) {
168183 for (final Map <String , Object ?> data in devicesData.map <Map <String , Object ?>?>(castStringKeyedMap).whereType <Map <String , Object ?>>()) {
169- devices.add (SimDevice (deviceCategory, data));
184+ devices.add (BootedSimDevice (deviceCategory, data));
170185 }
171186 }
172187 }
173188
174189 return devices;
175190 }
176191
177- /// Returns all the connected simulator devices.
178- Future <List <SimDevice >> getConnectedDevices () async {
179- final List <SimDevice > simDevices = await getDevices ();
180- return simDevices.where ((SimDevice device) => device.isBooted).toList ();
181- }
182-
183192 Future <bool > isInstalled (String deviceId, String appId) {
184193 return _processUtils.exitsHappy (< String > [
185194 ..._xcode.xcrunCommand (),
@@ -267,54 +276,15 @@ class SimControl {
267276 }
268277}
269278
270- /// Enumerates all data sections of `xcrun simctl list --json` command.
271- class SimControlListSection {
272- const SimControlListSection ._(this .name);
273-
274- final String name;
275-
276- static const SimControlListSection devices = SimControlListSection ._('devices' );
277- static const SimControlListSection devicetypes = SimControlListSection ._('devicetypes' );
278- static const SimControlListSection runtimes = SimControlListSection ._('runtimes' );
279- static const SimControlListSection pairs = SimControlListSection ._('pairs' );
280- }
281-
282- /// A simulated device type.
283- ///
284- /// Simulated device types can be listed using the command
285- /// `xcrun simctl list devicetypes` .
286- class SimDeviceType {
287- SimDeviceType (this .name, this .identifier);
288-
289- /// The name of the device type.
290- ///
291- /// Examples:
292- ///
293- /// "iPhone 6s"
294- /// "iPhone 6 Plus"
295- final String name;
296-
297- /// The identifier of the device type.
298- ///
299- /// Examples:
300- ///
301- /// "com.apple.CoreSimulator.SimDeviceType.iPhone-6s"
302- /// "com.apple.CoreSimulator.SimDeviceType.iPhone-6-Plus"
303- final String identifier;
304- }
305279
306- class SimDevice {
307- SimDevice (this .category, this .data);
280+ class BootedSimDevice {
281+ BootedSimDevice (this .category, this .data);
308282
309283 final String category;
310284 final Map <String , Object ?> data;
311285
312- String ? get state => data['state' ]? .toString ();
313- String ? get availability => data['availability' ]? .toString ();
314286 String ? get name => data['name' ]? .toString ();
315287 String ? get udid => data['udid' ]? .toString ();
316-
317- bool get isBooted => state == 'Booted' ;
318288}
319289
320290class IOSSimulator extends Device {
0 commit comments