mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
[flutter_tools] Include mode in app.start event, and forward app.start to DAP clients (#121239)
[flutter_tools] Include mode in app.start event, and forward app.start to DAP clients
This commit is contained in:
parent
9235eb64e2
commit
1a6a20cdc6
@ -136,7 +136,7 @@ The `stop()` command takes one parameter, `appId`. It returns a `bool` to indica
|
||||
|
||||
#### app.start
|
||||
|
||||
This is sent when an app is starting. The `params` field will be a map with the fields `appId`, `directory`, `deviceId`, and `launchMode`.
|
||||
This is sent when an app is starting. The `params` field will be a map with the fields `appId`, `directory`, `deviceId`, `launchMode` (`run`/`attach`) and `mode` (`debug`, `profile`, `release`, `jit_release`).
|
||||
|
||||
#### app.debugPort
|
||||
|
||||
|
@ -613,6 +613,7 @@ class AppDomain extends Domain {
|
||||
'directory': projectDirectory,
|
||||
'supportsRestart': isRestartSupported(enableHotReload, device),
|
||||
'launchMode': launchMode.toString(),
|
||||
'mode': runner.debuggingOptions.buildInfo.modeName,
|
||||
});
|
||||
|
||||
Completer<DebugConnectionInfo>? connectionInfoCompleter;
|
||||
|
@ -393,6 +393,16 @@ class FlutterDebugAdapter extends FlutterBaseDebugAdapter {
|
||||
// session (which is much slower, but required for profile/release mode).
|
||||
final bool supportsRestart = (params['supportsRestart'] as bool?) ?? false;
|
||||
sendEvent(CapabilitiesEventBody(capabilities: Capabilities(supportsRestartRequest: supportsRestart)));
|
||||
|
||||
// Send a custom event so the editor has info about the app starting.
|
||||
//
|
||||
// This message contains things like the `deviceId` and `mode` that the
|
||||
// client might not know about if they were inferred or set by users custom
|
||||
// args.
|
||||
sendEvent(
|
||||
RawEventBody(params),
|
||||
eventType: 'flutter.appStart',
|
||||
);
|
||||
}
|
||||
|
||||
/// Handles the app.started event from Flutter.
|
||||
|
@ -107,16 +107,18 @@ class MockFlutterDebugAdapter extends FlutterDebugAdapter {
|
||||
// Simulate the app starting by triggering handling of events that Flutter
|
||||
// would usually write to stdout.
|
||||
if (simulateAppStarted) {
|
||||
simulateStdoutMessage(<String, Object?>{
|
||||
'event': 'app.started',
|
||||
});
|
||||
simulateStdoutMessage(<String, Object?>{
|
||||
'event': 'app.start',
|
||||
'params': <String, Object?>{
|
||||
'appId': 'TEST',
|
||||
'supportsRestart': supportsRestart,
|
||||
'deviceId': 'flutter-tester',
|
||||
'mode': 'debug',
|
||||
}
|
||||
});
|
||||
simulateStdoutMessage(<String, Object?>{
|
||||
'event': 'app.started',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -452,6 +452,30 @@ void main() {
|
||||
await dap.client.terminate();
|
||||
});
|
||||
|
||||
testWithoutContext('provides appStarted events to the client', () async {
|
||||
final BasicProject project = BasicProject();
|
||||
await project.setUpIn(tempDir);
|
||||
|
||||
// Launch the app and wait for it to send a 'flutter.appStart' event.
|
||||
final Future<Event> appStartFuture = dap.client.event('flutter.appStart');
|
||||
await Future.wait(<Future<void>>[
|
||||
appStartFuture,
|
||||
dap.client.start(
|
||||
launch: () => dap.client.launch(
|
||||
cwd: project.dir.path,
|
||||
toolArgs: <String>['-d', 'flutter-tester'],
|
||||
),
|
||||
),
|
||||
], eagerError: true);
|
||||
|
||||
await dap.client.terminate();
|
||||
|
||||
final Event appStart = await appStartFuture;
|
||||
final Map<String, Object?> params = appStart.body! as Map<String, Object?>;
|
||||
expect(params['deviceId'], 'flutter-tester');
|
||||
expect(params['mode'], 'debug');
|
||||
});
|
||||
|
||||
testWithoutContext('provides appStarted events to the client', () async {
|
||||
final BasicProject project = BasicProject();
|
||||
await project.setUpIn(tempDir);
|
||||
|
@ -68,4 +68,10 @@ void main() {
|
||||
matches: isNotEmpty,
|
||||
);
|
||||
});
|
||||
|
||||
testWithoutContext('reports deviceId and mode in app.start event', () async {
|
||||
await flutter.run();
|
||||
expect(flutter.currentRunningDeviceId, 'flutter-tester');
|
||||
expect(flutter.currentRunningMode, 'debug');
|
||||
});
|
||||
}
|
||||
|
@ -496,6 +496,11 @@ class FlutterRunTestDriver extends FlutterTestDriver {
|
||||
});
|
||||
|
||||
String? _currentRunningAppId;
|
||||
String? _currentRunningDeviceId;
|
||||
String? _currentRunningMode;
|
||||
|
||||
String? get currentRunningDeviceId => _currentRunningDeviceId;
|
||||
String? get currentRunningMode => _currentRunningMode;
|
||||
|
||||
Future<void> run({
|
||||
bool withDebugger = false,
|
||||
@ -611,6 +616,7 @@ class FlutterRunTestDriver extends FlutterTestDriver {
|
||||
|
||||
// Set this up now, but we don't wait it yet. We want to make sure we don't
|
||||
// miss it while waiting for debugPort below.
|
||||
final Future<Map<String, Object?>> start = _waitFor(event: 'app.start', timeout: appStartTimeout);
|
||||
final Future<Map<String, Object?>> started = _waitFor(event: 'app.started', timeout: appStartTimeout);
|
||||
|
||||
if (withDebugger) {
|
||||
@ -630,9 +636,13 @@ class FlutterRunTestDriver extends FlutterTestDriver {
|
||||
_attachPort = attachPort;
|
||||
}
|
||||
|
||||
// Now await the started event; if it had already happened the future will
|
||||
// Now await the start/started events; if it had already happened the future will
|
||||
// have already completed.
|
||||
_currentRunningAppId = ((await started)['params'] as Map<String, Object?>?)?['appId'] as String?;
|
||||
final Map<String, Object?>? startParams = (await start)['params'] as Map<String, Object?>?;
|
||||
final Map<String, Object?>? startedParams = (await started)['params'] as Map<String, Object?>?;
|
||||
_currentRunningAppId = startedParams?['appId'] as String?;
|
||||
_currentRunningDeviceId = startParams?['deviceId'] as String?;
|
||||
_currentRunningMode = startParams?['mode'] as String?;
|
||||
prematureExitGuard.complete();
|
||||
} on Exception catch (error, stackTrace) {
|
||||
prematureExitGuard.completeError(Exception(error.toString()), stackTrace);
|
||||
|
Loading…
Reference in New Issue
Block a user