send the reload source command for ios simulators (#4731)
* send the reload source command for ios simulators * review changes * rewrite w/ a completer
This commit is contained in:
@@ -17,6 +17,7 @@ import '../ios/devices.dart';
|
||||
import '../ios/simulators.dart';
|
||||
import '../run.dart';
|
||||
import '../runner/flutter_command.dart';
|
||||
import 'run.dart' as run;
|
||||
|
||||
const String protocolVersion = '0.2.0';
|
||||
|
||||
@@ -291,6 +292,7 @@ class AppDomain extends Domain {
|
||||
String route = _getStringArg(args, 'route');
|
||||
String mode = _getStringArg(args, 'mode');
|
||||
String target = _getStringArg(args, 'target');
|
||||
bool reloadSources = _getBoolArg(args, 'reload-sources');
|
||||
|
||||
Device device = daemon.deviceDomain._getDevice(deviceId);
|
||||
if (device == null)
|
||||
@@ -299,6 +301,9 @@ class AppDomain extends Domain {
|
||||
if (!FileSystemEntity.isDirectorySync(projectDirectory))
|
||||
throw "'$projectDirectory' does not exist";
|
||||
|
||||
if (reloadSources != null)
|
||||
run.useReloadSources = reloadSources;
|
||||
|
||||
BuildMode buildMode = getBuildModeForName(mode) ?? BuildMode.debug;
|
||||
DebuggingOptions options;
|
||||
|
||||
|
||||
@@ -19,6 +19,9 @@ import 'build_apk.dart';
|
||||
import 'install.dart';
|
||||
import 'trace.dart';
|
||||
|
||||
/// Whether the user has passed the `--reload-sources` command-line option.
|
||||
bool useReloadSources = false;
|
||||
|
||||
abstract class RunCommandBase extends FlutterCommand {
|
||||
RunCommandBase() {
|
||||
addBuildModeFlags(defaultToRelease: false);
|
||||
@@ -63,6 +66,9 @@ class RunCommand extends RunCommandBase {
|
||||
// embedder via the DevFS observatory API.
|
||||
argParser.addFlag('devfs', negatable: false, hide: true);
|
||||
|
||||
// Send the _reloadSource command to the VM.
|
||||
argParser.addFlag('reload-sources', negatable: true, defaultsTo: false, hide: true);
|
||||
|
||||
// Hidden option to enable a benchmarking mode. This will run the given
|
||||
// application, measure the startup time and the app restart time, write the
|
||||
// results out to 'refresh_benchmark.json', and exit. This flag is intended
|
||||
@@ -116,6 +122,8 @@ class RunCommand extends RunCommandBase {
|
||||
|
||||
Cache.releaseLockEarly();
|
||||
|
||||
useReloadSources = argResults['reload-sources'];
|
||||
|
||||
if (argResults['resident']) {
|
||||
RunAndStayResident runner = new RunAndStayResident(
|
||||
deviceForCommand,
|
||||
|
||||
@@ -318,12 +318,7 @@ class IOSDevice extends Device {
|
||||
String mainPath,
|
||||
Observatory observatory
|
||||
}) async {
|
||||
return observatory.isolateReload(observatory.firstIsolateId).then((Response response) {
|
||||
return true;
|
||||
}).catchError((dynamic error) {
|
||||
printError('Error restarting app: $error');
|
||||
return false;
|
||||
});
|
||||
throw 'unsupported';
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -13,9 +13,11 @@ import '../application_package.dart';
|
||||
import '../base/context.dart';
|
||||
import '../base/process.dart';
|
||||
import '../build_info.dart';
|
||||
import '../commands/run.dart' as run;
|
||||
import '../device.dart';
|
||||
import '../flx.dart' as flx;
|
||||
import '../globals.dart';
|
||||
import '../observatory.dart';
|
||||
import '../protocol_discovery.dart';
|
||||
import 'mac.dart';
|
||||
|
||||
@@ -573,6 +575,21 @@ class IOSSimulator extends Device {
|
||||
return (await flx.build(precompiledSnapshot: true)) == 0;
|
||||
}
|
||||
|
||||
@override
|
||||
bool get supportsRestart => run.useReloadSources;
|
||||
|
||||
@override
|
||||
Future<bool> restartApp(
|
||||
ApplicationPackage package,
|
||||
LaunchResult result, {
|
||||
String mainPath,
|
||||
Observatory observatory
|
||||
}) async {
|
||||
if (observatory.firstIsolateId == null)
|
||||
throw 'Application isolate not found';
|
||||
return observatory.reloadSources(observatory.firstIsolateId);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> stopApp(ApplicationPackage app) async {
|
||||
// Currently we don't have a way to stop an app running on iOS.
|
||||
|
||||
@@ -9,6 +9,8 @@ import 'dart:io';
|
||||
import 'package:json_rpc_2/json_rpc_2.dart' as rpc;
|
||||
import 'package:web_socket_channel/io.dart';
|
||||
|
||||
import 'globals.dart';
|
||||
|
||||
class Observatory {
|
||||
Observatory._(this.peer, this.port) {
|
||||
peer.registerMethod('streamNotify', (rpc.Parameters event) {
|
||||
@@ -113,10 +115,22 @@ class Observatory {
|
||||
});
|
||||
}
|
||||
|
||||
Future<Response> isolateReload(String isolateId) {
|
||||
return sendRequest('isolateReload', <String, dynamic>{
|
||||
'isolateId': isolateId
|
||||
});
|
||||
Future<bool> reloadSources(String isolateId) async {
|
||||
Completer<Event> whenIsolateReloads = new Completer<Event>();
|
||||
StreamSubscription<Event> sub = onIsolateEvent
|
||||
.where((Event event) => event.kind == 'IsolateReload')
|
||||
.listen((Event event) => whenIsolateReloads.complete(event));
|
||||
|
||||
try {
|
||||
await sendRequest('_reloadSources', <String, dynamic>{ 'isolateId': isolateId });
|
||||
Event event = await whenIsolateReloads.future.timeout(new Duration(seconds: 20));
|
||||
dynamic error = event.response['reloadError'];
|
||||
if (error != null)
|
||||
printError('Error reloading application sources: $error');
|
||||
return error == null;
|
||||
} finally {
|
||||
await sub.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
Future<Response> clearVMTimeline() => sendRequest('_clearVMTimeline');
|
||||
|
||||
Reference in New Issue
Block a user