Commit 6cdfd86a authored by Devon Carew's avatar Devon Carew Committed by GitHub

send the reload source command for ios simulators (#4731)

* send the reload source command for ios simulators

* review changes

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