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