Add a detach command to detach without terminating (#21376)
* Add a detach command to detach without terminating Fixes #21154. * Bump protocol version for app.detach * Tweak to detach/quit text * Change logPrefix to named param
This commit is contained in:
@@ -28,7 +28,7 @@ import '../runner/flutter_command.dart';
|
||||
import '../tester/flutter_tester.dart';
|
||||
import '../vmservice.dart';
|
||||
|
||||
const String protocolVersion = '0.4.1';
|
||||
const String protocolVersion = '0.4.2';
|
||||
|
||||
/// A server process command. This command will start up a long-lived server.
|
||||
/// It reads JSON-RPC based commands from stdin, executes them, and returns
|
||||
@@ -316,6 +316,7 @@ class AppDomain extends Domain {
|
||||
registerHandler('restart', restart);
|
||||
registerHandler('callServiceExtension', callServiceExtension);
|
||||
registerHandler('stop', stop);
|
||||
registerHandler('detach', detach);
|
||||
}
|
||||
|
||||
static final Uuid _uuidGenerator = new Uuid();
|
||||
@@ -516,6 +517,23 @@ class AppDomain extends Domain {
|
||||
});
|
||||
}
|
||||
|
||||
Future<bool> detach(Map<String, dynamic> args) async {
|
||||
final String appId = _getStringArg(args, 'appId', required: true);
|
||||
|
||||
final AppInstance app = _getApp(appId);
|
||||
if (app == null)
|
||||
throw "app '$appId' not found";
|
||||
|
||||
return app.detach().timeout(const Duration(seconds: 5)).then<bool>((_) {
|
||||
return true;
|
||||
}).catchError((dynamic error) {
|
||||
_sendAppEvent(app, 'log', <String, dynamic>{ 'log': '$error', 'error': true });
|
||||
app.closeLogger();
|
||||
_apps.remove(app);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
AppInstance _getApp(String id) {
|
||||
return _apps.firstWhere((AppInstance app) => app.id == id, orElse: () => null);
|
||||
}
|
||||
@@ -769,6 +787,7 @@ class AppInstance {
|
||||
}
|
||||
|
||||
Future<Null> stop() => runner.stop();
|
||||
Future<Null> detach() => runner.detach();
|
||||
|
||||
void closeLogger() {
|
||||
_logger.close();
|
||||
|
||||
@@ -66,6 +66,7 @@ class HotRunner extends ResidentRunner {
|
||||
final bool benchmarkMode;
|
||||
final File applicationBinary;
|
||||
final bool hostIsIde;
|
||||
bool _didAttach = false;
|
||||
Set<String> _dartDependencies;
|
||||
final String dillOutputPath;
|
||||
|
||||
@@ -152,6 +153,7 @@ class HotRunner extends ResidentRunner {
|
||||
Completer<void> appStartedCompleter,
|
||||
String viewFilter,
|
||||
}) async {
|
||||
_didAttach = true;
|
||||
try {
|
||||
await connectToServiceProtocol(viewFilter: viewFilter,
|
||||
reloadSources: _reloadSourcesService,
|
||||
@@ -751,18 +753,25 @@ class HotRunner extends ResidentRunner {
|
||||
for (Uri uri in device.observatoryUris)
|
||||
printStatus('An Observatory debugger and profiler on $dname is available at: $uri');
|
||||
}
|
||||
final String quitMessage = _didAttach
|
||||
? 'To detach, press "d"; to quit, press "q".'
|
||||
: 'To quit, press "q".';
|
||||
if (details) {
|
||||
printHelpDetails();
|
||||
printStatus('To repeat this help message, press "h". To quit, press "q".');
|
||||
printStatus('To repeat this help message, press "h". $quitMessage');
|
||||
} else {
|
||||
printStatus('For a more detailed help message, press "h". To quit, press "q".');
|
||||
printStatus('For a more detailed help message, press "h". $quitMessage');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Null> cleanupAfterSignal() async {
|
||||
await stopEchoingDeviceLog();
|
||||
await stopApp();
|
||||
if (_didAttach) {
|
||||
appFinished();
|
||||
} else {
|
||||
await stopApp();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user