Commit e69f6562 authored by Yegor Jbanov's avatar Yegor Jbanov

[ios] use xcrun to launch simulator instead of hardcoded path

parent df73b481
...@@ -21,9 +21,6 @@ import 'mac.dart'; ...@@ -21,9 +21,6 @@ import 'mac.dart';
const String _xcrunPath = '/usr/bin/xcrun'; const String _xcrunPath = '/usr/bin/xcrun';
const String _simulatorPath =
'/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/Contents/MacOS/Simulator';
class IOSSimulators extends PollingDeviceDiscovery { class IOSSimulators extends PollingDeviceDiscovery {
IOSSimulators() : super('IOSSimulators'); IOSSimulators() : super('IOSSimulators');
...@@ -56,35 +53,36 @@ class SimControl { ...@@ -56,35 +53,36 @@ class SimControl {
if (_isAnyConnected()) if (_isAnyConnected())
return true; return true;
if (deviceId == null) { if (deviceId == null)
runDetached([_simulatorPath]); deviceId = 'iPhone 6 (9.2)';
Future<bool> checkConnection([int attempts = 20]) async {
if (attempts == 0) { // `xcrun instruments` requires a template (-t). @yjbanov has no idea what
printStatus('Timed out waiting for iOS Simulator to boot.'); // "template" is but the built-in 'Blank' seems to work.
return false; List<String> args = [_xcrunPath, 'instruments', '-w', deviceId, '-t', 'Blank'];
} printTrace(args.join(' '));
if (!_isAnyConnected()) { runDetached(args);
printStatus('Waiting for iOS Simulator to boot...'); printStatus('Waiting for iOS Simulator to boot...');
return await new Future.delayed(new Duration(milliseconds: 500),
() => checkConnection(attempts - 1) bool connected = false;
); int attempted = 0;
while (!connected && attempted < 20) {
connected = await _isAnyConnected();
if (!connected) {
printStatus('Still waiting for iOS Simulator to boot...');
await new Future.delayed(new Duration(seconds: 1));
} }
return true; attempted++;
} }
return await checkConnection();
} else { if (connected) {
try { printStatus('Connected to iOS Simulator.');
runCheckedSync([_xcrunPath, 'simctl', 'boot', deviceId]);
return true; return true;
} catch (e) { } else {
printError('Unable to boot iOS Simulator $deviceId: ', e); printStatus('Timed out waiting for iOS Simulator to boot.');
return false; return false;
} }
} }
return false;
}
/// Returns a list of all available devices, both potential and connected. /// Returns a list of all available devices, both potential and connected.
List<SimDevice> getDevices() { List<SimDevice> getDevices() {
// { // {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment