Unverified Commit 1a6a20cd authored by Danny Tuppeny's avatar Danny Tuppeny Committed by GitHub

[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
parent 9235eb64
...@@ -136,7 +136,7 @@ The `stop()` command takes one parameter, `appId`. It returns a `bool` to indica ...@@ -136,7 +136,7 @@ The `stop()` command takes one parameter, `appId`. It returns a `bool` to indica
#### app.start #### 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 #### app.debugPort
......
...@@ -613,6 +613,7 @@ class AppDomain extends Domain { ...@@ -613,6 +613,7 @@ class AppDomain extends Domain {
'directory': projectDirectory, 'directory': projectDirectory,
'supportsRestart': isRestartSupported(enableHotReload, device), 'supportsRestart': isRestartSupported(enableHotReload, device),
'launchMode': launchMode.toString(), 'launchMode': launchMode.toString(),
'mode': runner.debuggingOptions.buildInfo.modeName,
}); });
Completer<DebugConnectionInfo>? connectionInfoCompleter; Completer<DebugConnectionInfo>? connectionInfoCompleter;
......
...@@ -393,6 +393,16 @@ class FlutterDebugAdapter extends FlutterBaseDebugAdapter { ...@@ -393,6 +393,16 @@ class FlutterDebugAdapter extends FlutterBaseDebugAdapter {
// session (which is much slower, but required for profile/release mode). // session (which is much slower, but required for profile/release mode).
final bool supportsRestart = (params['supportsRestart'] as bool?) ?? false; final bool supportsRestart = (params['supportsRestart'] as bool?) ?? false;
sendEvent(CapabilitiesEventBody(capabilities: Capabilities(supportsRestartRequest: supportsRestart))); 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. /// Handles the app.started event from Flutter.
......
...@@ -107,16 +107,18 @@ class MockFlutterDebugAdapter extends FlutterDebugAdapter { ...@@ -107,16 +107,18 @@ class MockFlutterDebugAdapter extends FlutterDebugAdapter {
// Simulate the app starting by triggering handling of events that Flutter // Simulate the app starting by triggering handling of events that Flutter
// would usually write to stdout. // would usually write to stdout.
if (simulateAppStarted) { if (simulateAppStarted) {
simulateStdoutMessage(<String, Object?>{
'event': 'app.started',
});
simulateStdoutMessage(<String, Object?>{ simulateStdoutMessage(<String, Object?>{
'event': 'app.start', 'event': 'app.start',
'params': <String, Object?>{ 'params': <String, Object?>{
'appId': 'TEST', 'appId': 'TEST',
'supportsRestart': supportsRestart, 'supportsRestart': supportsRestart,
'deviceId': 'flutter-tester',
'mode': 'debug',
} }
}); });
simulateStdoutMessage(<String, Object?>{
'event': 'app.started',
});
} }
} }
......
...@@ -452,6 +452,30 @@ void main() { ...@@ -452,6 +452,30 @@ void main() {
await dap.client.terminate(); 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 { testWithoutContext('provides appStarted events to the client', () async {
final BasicProject project = BasicProject(); final BasicProject project = BasicProject();
await project.setUpIn(tempDir); await project.setUpIn(tempDir);
......
...@@ -68,4 +68,10 @@ void main() { ...@@ -68,4 +68,10 @@ void main() {
matches: isNotEmpty, 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 { ...@@ -496,6 +496,11 @@ class FlutterRunTestDriver extends FlutterTestDriver {
}); });
String? _currentRunningAppId; String? _currentRunningAppId;
String? _currentRunningDeviceId;
String? _currentRunningMode;
String? get currentRunningDeviceId => _currentRunningDeviceId;
String? get currentRunningMode => _currentRunningMode;
Future<void> run({ Future<void> run({
bool withDebugger = false, bool withDebugger = false,
...@@ -611,6 +616,7 @@ class FlutterRunTestDriver extends FlutterTestDriver { ...@@ -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 // 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. // 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); final Future<Map<String, Object?>> started = _waitFor(event: 'app.started', timeout: appStartTimeout);
if (withDebugger) { if (withDebugger) {
...@@ -630,9 +636,13 @@ class FlutterRunTestDriver extends FlutterTestDriver { ...@@ -630,9 +636,13 @@ class FlutterRunTestDriver extends FlutterTestDriver {
_attachPort = attachPort; _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. // 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(); prematureExitGuard.complete();
} on Exception catch (error, stackTrace) { } on Exception catch (error, stackTrace) {
prematureExitGuard.completeError(Exception(error.toString()), stackTrace); prematureExitGuard.completeError(Exception(error.toString()), stackTrace);
......
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