mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
First run simulator with -n to ensure it always opens a device (#17460)
This commit is contained in:
parent
4beb57c324
commit
e2181a6ad9
@ -41,20 +41,22 @@ class AndroidEmulator extends Emulator {
|
||||
String get label => _properties['avd.ini.displayname'];
|
||||
|
||||
@override
|
||||
Future<void> launch() async {
|
||||
final Future<void> launchResult =
|
||||
Future<bool> launch() async {
|
||||
final Future<bool> launchResult =
|
||||
runAsync(<String>[getEmulatorPath(), '-avd', id])
|
||||
.then((RunResult runResult) {
|
||||
if (runResult.exitCode != 0) {
|
||||
printError('$runResult');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
// emulator continues running on a successful launch so if we
|
||||
// haven't quit within 3 seconds we assume that's a success and just
|
||||
// return.
|
||||
await Future.any<void>(<Future<void>>[
|
||||
return Future.any<bool>(<Future<bool>>[
|
||||
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 {
|
||||
return id == other.id;
|
||||
}
|
||||
|
||||
Future<void> launch();
|
||||
Future<bool> launch();
|
||||
|
||||
@override
|
||||
String toString() => name;
|
||||
|
||||
@ -36,12 +36,27 @@ class IOSEmulator extends Emulator {
|
||||
String get label => null;
|
||||
|
||||
@override
|
||||
Future<void> launch() async {
|
||||
final RunResult launchResult =
|
||||
await runAsync(<String>['open', '-a', getSimulatorPath()]);
|
||||
if (launchResult.exitCode != 0) {
|
||||
printError('$launchResult');
|
||||
Future<bool> launch() async {
|
||||
Future<bool> launchSimulator(List<String> additionalArgs) async {
|
||||
final List<String> args = <String>['open']
|
||||
.followedBy(additionalArgs)
|
||||
.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 {
|
||||
final String label;
|
||||
|
||||
@override
|
||||
Future<void> launch() {
|
||||
Future<bool> launch() {
|
||||
throw new UnimplementedError('Not implemented in Mock');
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user