Commit e880d51f authored by Devon Carew's avatar Devon Carew Committed by GitHub

fix an issue where --hot would not exit (#5421)

* fix an issue where --hot would not exit

* add type annotations
parent 7ab48f4e
...@@ -264,9 +264,9 @@ class DevFS { ...@@ -264,9 +264,9 @@ class DevFS {
return _baseUri; return _baseUri;
} }
Future<dynamic> destroy() async { Future<dynamic> destroy() {
printTrace('DevFS: Deleted filesystem on the device ($_baseUri)'); printTrace('DevFS: Deleted filesystem on the device ($_baseUri)');
return await _operations.destroy(fsName); return _operations.destroy(fsName);
} }
void _reset() { void _reset() {
......
...@@ -295,7 +295,7 @@ class HotRunner extends ResidentRunner { ...@@ -295,7 +295,7 @@ class HotRunner extends ResidentRunner {
} }
await viewManager.refresh(); await viewManager.refresh();
printStatus('Connected to view: ${viewManager.mainView}'); printStatus('Connected to view \'${viewManager.mainView}\'.');
printStatus('Running ${getDisplayPath(_mainPath)} on ${device.name}...'); printStatus('Running ${getDisplayPath(_mainPath)} on ${device.name}...');
_loaderShowMessage('Launching...'); _loaderShowMessage('Launching...');
...@@ -313,7 +313,7 @@ class HotRunner extends ResidentRunner { ...@@ -313,7 +313,7 @@ class HotRunner extends ResidentRunner {
// Finish the file sync now. // Finish the file sync now.
await _updateDevFS(); await _updateDevFS();
return await waitForAppToFinish(); return waitForAppToFinish();
} }
@override @override
...@@ -375,9 +375,8 @@ class HotRunner extends ResidentRunner { ...@@ -375,9 +375,8 @@ class HotRunner extends ResidentRunner {
} }
Future<Null> _evictDirtyAssets() async { Future<Null> _evictDirtyAssets() async {
if (_devFS.dirtyAssetEntries.length == 0) { if (_devFS.dirtyAssetEntries.length == 0)
return; return;
}
if (serviceProtocol.firstIsolateId == null) if (serviceProtocol.firstIsolateId == null)
throw 'Application isolate not found'; throw 'Application isolate not found';
for (DevFSEntry entry in _devFS.dirtyAssetEntries) { for (DevFSEntry entry in _devFS.dirtyAssetEntries) {
...@@ -388,8 +387,12 @@ class HotRunner extends ResidentRunner { ...@@ -388,8 +387,12 @@ class HotRunner extends ResidentRunner {
Future<Null> _cleanupDevFS() async { Future<Null> _cleanupDevFS() async {
if (_devFS != null) { if (_devFS != null) {
// Cleanup the devFS. // Cleanup the devFS; don't wait indefinitely, and ignore any errors.
await _devFS.destroy(); await _devFS.destroy()
.timeout(new Duration(milliseconds: 250))
.catchError((dynamic error) {
printTrace('$error');
});
} }
_devFS = null; _devFS = null;
} }
...@@ -499,9 +502,8 @@ class HotRunner extends ResidentRunner { ...@@ -499,9 +502,8 @@ class HotRunner extends ResidentRunner {
@override @override
void printHelp() { void printHelp() {
printStatus('Type "h" or F1 for this help message. Type "q", F10, or ctrl-c to quit.', emphasis: true); printStatus('Type "h" or F1 for this help message; type "q", F10, or ctrl-c to quit.', emphasis: true);
printStatus('Type "r" or F5 to perform a hot reload of the app.', emphasis: true); printStatus('Type "r" or F5 to perform a hot reload of the app, and "R" to restart the app.', emphasis: true);
printStatus('Type "R" to restart the app', emphasis: true);
printStatus('Type "w" to print the widget hierarchy of the app, and "t" for the render tree.', emphasis: true); printStatus('Type "w" to print the widget hierarchy of the app, and "t" for the render tree.', emphasis: true);
} }
...@@ -511,6 +513,9 @@ class HotRunner extends ResidentRunner { ...@@ -511,6 +513,9 @@ class HotRunner extends ResidentRunner {
await stopApp(); await stopApp();
} }
@override
Future<Null> preStop() => _cleanupDevFS();
@override @override
Future<Null> cleanupAtFinish() async { Future<Null> cleanupAtFinish() async {
await _cleanupDevFS(); await _cleanupDevFS();
......
...@@ -43,6 +43,7 @@ abstract class ResidentRunner { ...@@ -43,6 +43,7 @@ abstract class ResidentRunner {
Future<Null> stop() async { Future<Null> stop() async {
await stopEchoingDeviceLog(); await stopEchoingDeviceLog();
await preStop();
return stopApp(); return stopApp();
} }
...@@ -127,7 +128,7 @@ abstract class ResidentRunner { ...@@ -127,7 +128,7 @@ abstract class ResidentRunner {
return true; return true;
} else if (lower == 'q' || character == AnsiTerminal.KEY_F10) { } else if (lower == 'q' || character == AnsiTerminal.KEY_F10) {
// F10, exit // F10, exit
await stopApp(); await stop();
return true; return true;
} }
...@@ -171,15 +172,16 @@ abstract class ResidentRunner { ...@@ -171,15 +172,16 @@ abstract class ResidentRunner {
return exitCode; return exitCode;
} }
Future<Null> stopApp() { Future<Null> preStop() async { }
Future<Null> stopApp() async {
if (serviceProtocol != null && !serviceProtocol.isClosed) { if (serviceProtocol != null && !serviceProtocol.isClosed) {
if (serviceProtocol.isolates.isNotEmpty) { if (serviceProtocol.isolates.isNotEmpty) {
serviceProtocol.flutterExit(serviceProtocol.firstIsolateId); serviceProtocol.flutterExit(serviceProtocol.firstIsolateId);
return new Future<Null>.delayed(new Duration(milliseconds: 100)); await new Future<Null>.delayed(new Duration(milliseconds: 100));
} }
} }
appFinished(); appFinished();
return new Future<Null>.value();
} }
/// Called when a signal has requested we exit. /// Called when a signal has requested we exit.
......
...@@ -213,7 +213,7 @@ class RunAndStayResident extends ResidentRunner { ...@@ -213,7 +213,7 @@ class RunAndStayResident extends ResidentRunner {
stop(); stop();
} }
return await waitForAppToFinish(); return waitForAppToFinish();
} }
@override @override
......
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