Unverified Commit e2181a6a authored by Danny Tuppeny's avatar Danny Tuppeny Committed by GitHub

First run simulator with -n to ensure it always opens a device (#17460)

parent 4beb57c3
...@@ -41,20 +41,22 @@ class AndroidEmulator extends Emulator { ...@@ -41,20 +41,22 @@ class AndroidEmulator extends Emulator {
String get label => _properties['avd.ini.displayname']; String get label => _properties['avd.ini.displayname'];
@override @override
Future<void> launch() async { Future<bool> launch() async {
final Future<void> launchResult = final Future<bool> launchResult =
runAsync(<String>[getEmulatorPath(), '-avd', id]) runAsync(<String>[getEmulatorPath(), '-avd', id])
.then((RunResult runResult) { .then((RunResult runResult) {
if (runResult.exitCode != 0) { if (runResult.exitCode != 0) {
printError('$runResult'); printError('$runResult');
return false;
} }
return true;
}); });
// emulator continues running on a successful launch so if we // emulator continues running on a successful launch so if we
// haven't quit within 3 seconds we assume that's a success and just // haven't quit within 3 seconds we assume that's a success and just
// return. // return.
await Future.any<void>(<Future<void>>[ return Future.any<bool>(<Future<bool>>[
launchResult, launchResult,
new Future<void>.delayed(const Duration(seconds: 3)) new Future<void>.delayed(const Duration(seconds: 3)).then((_) => true)
]); ]);
} }
} }
......
...@@ -95,7 +95,7 @@ abstract class Emulator { ...@@ -95,7 +95,7 @@ abstract class Emulator {
return id == other.id; return id == other.id;
} }
Future<void> launch(); Future<bool> launch();
@override @override
String toString() => name; String toString() => name;
......
...@@ -36,12 +36,27 @@ class IOSEmulator extends Emulator { ...@@ -36,12 +36,27 @@ class IOSEmulator extends Emulator {
String get label => null; String get label => null;
@override @override
Future<void> launch() async { Future<bool> launch() async {
final RunResult launchResult = Future<bool> launchSimulator(List<String> additionalArgs) async {
await runAsync(<String>['open', '-a', getSimulatorPath()]); final List<String> args = <String>['open']
if (launchResult.exitCode != 0) { .followedBy(additionalArgs)
printError('$launchResult'); .followedBy(<String>['-a', getSimulatorPath()]);
final RunResult launchResult = await runAsync(args);
if (launchResult.exitCode != 0) {
printError('$launchResult');
return false;
}
return true;
} }
// First run with `-n` to force a device to boot if there isn't already one
if (!await launchSimulator(<String>['-n']))
return false;
// Run again to force it to Foreground (using -n doesn't force existing
// devices to the foreground)
return launchSimulator(<String>[]);
} }
} }
......
...@@ -62,7 +62,7 @@ class _MockEmulator extends Emulator { ...@@ -62,7 +62,7 @@ class _MockEmulator extends Emulator {
final String label; final String label;
@override @override
Future<void> launch() { Future<bool> launch() {
throw new UnimplementedError('Not implemented in Mock'); throw new UnimplementedError('Not implemented in Mock');
} }
} }
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