Commit 30505aef authored by Devon Carew's avatar Devon Carew Committed by GitHub

support hot mode from the daemon protocol (#5271)

* support hot mode from the daemon protocol

* move method params to constructor
parent 0a79ffe7
......@@ -13,8 +13,10 @@ import '../build_info.dart';
import '../cache.dart';
import '../device.dart';
import '../globals.dart';
import '../hot.dart';
import '../ios/devices.dart';
import '../ios/simulators.dart';
import '../resident_runner.dart';
import '../run.dart';
import '../runner/flutter_command.dart';
......@@ -291,7 +293,7 @@ class AppDomain extends Domain {
String route = _getStringArg(args, 'route');
String mode = _getStringArg(args, 'mode');
String target = _getStringArg(args, 'target');
// TODO(johnmccutchan): Wire up support for hot mode.
bool hotMode = _getBoolArg(args, 'hot') ?? false;
Device device = daemon.deviceDomain._getDevice(deviceId);
if (device == null)
......@@ -319,19 +321,30 @@ class AppDomain extends Domain {
Directory cwd = Directory.current;
Directory.current = new Directory(projectDirectory);
RunAndStayResident runner = new RunAndStayResident(
device,
target: target,
debuggingOptions: options,
usesTerminalUI: false
);
ResidentRunner runner;
if (hotMode) {
runner = new HotRunner(
device,
target: target,
debuggingOptions: options,
usesTerminalUI: false
);
} else {
runner = new RunAndStayResident(
device,
target: target,
debuggingOptions: options,
usesTerminalUI: false
);
}
AppInstance app = new AppInstance(_getNextAppId(), runner);
_apps.add(app);
_sendAppEvent(app, 'start', <String, dynamic>{
'deviceId': deviceId,
'directory': projectDirectory,
'supportsRestart': device.supportsRestart
'supportsRestart': device.supportsRestart && hotMode
});
Completer<int> observatoryPortCompleter;
......@@ -567,7 +580,7 @@ class AppInstance {
AppInstance(this.id, [this.runner]);
final String id;
final RunAndStayResident runner;
final ResidentRunner runner;
_AppRunLogger _logger;
......
......@@ -129,25 +129,25 @@ class RunCommand extends RunCommandBase {
}
}
ResidentRunner runner;
if (argResults['hot']) {
HotRunner runner = new HotRunner(
runner = new HotRunner(
deviceForCommand,
target: targetFile,
debuggingOptions: options
);
return runner.run(route: route);
} else {
RunAndStayResident runner = new RunAndStayResident(
runner = new RunAndStayResident(
deviceForCommand,
target: targetFile,
debuggingOptions: options
);
return runner.run(
debuggingOptions: options,
traceStartup: traceStartup,
benchmark: argResults['benchmark'],
route: route
benchmark: argResults['benchmark']
);
}
return runner.run(route: route);
}
}
......
......@@ -47,11 +47,8 @@ class HotRunner extends ResidentRunner {
String _projectRootPath;
final AssetBundle bundle = new AssetBundle();
/// Start the app and keep the process running during its lifetime.
Future<int> run({
Completer<int> observatoryPortCompleter,
String route
}) {
@override
Future<int> run({ Completer<int> observatoryPortCompleter, String route }) {
// Don't let uncaught errors kill the process.
return runZoned(() {
return _run(
......@@ -323,6 +320,9 @@ class HotRunner extends ResidentRunner {
return true;
}
@override
Future<bool> restart() => _reloadSources();
Future<bool> _reloadSources() async {
if (serviceProtocol.firstIsolateId == null)
throw 'Application isolate not found';
......
......@@ -30,6 +30,11 @@ abstract class ResidentRunner {
Observatory serviceProtocol;
StreamSubscription<String> _loggingSubscription;
/// Start the app and keep the process running during its lifetime.
Future<int> run({ Completer<int> observatoryPortCompleter, String route });
Future<bool> restart();
Future<Null> stop() async {
await stopEchoingDeviceLog();
return stopApp();
......
......@@ -21,7 +21,9 @@ class RunAndStayResident extends ResidentRunner {
Device device, {
String target,
DebuggingOptions debuggingOptions,
bool usesTerminalUI: true
bool usesTerminalUI: true,
this.traceStartup: false,
this.benchmark: false
}) : super(device,
target: target,
debuggingOptions: debuggingOptions,
......@@ -30,14 +32,11 @@ class RunAndStayResident extends ResidentRunner {
ApplicationPackage _package;
String _mainPath;
LaunchResult _result;
bool traceStartup;
bool benchmark;
/// Start the app and keep the process running during its lifetime.
Future<int> run({
bool traceStartup: false,
bool benchmark: false,
Completer<int> observatoryPortCompleter,
String route
}) {
@override
Future<int> run({ Completer<int> observatoryPortCompleter, String route }) {
// Don't let uncaught errors kill the process.
return runZoned(() {
return _run(
......@@ -51,6 +50,7 @@ class RunAndStayResident extends ResidentRunner {
});
}
@override
Future<bool> restart() async {
if (serviceProtocol == null) {
printError('Debugging is not enabled.');
......
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