Fix bug with debugging support code not getting injected on edge devices (#168073)

This PR addresses
[flutter/flutter#167102](https://github.com/flutter/flutter/issues/167102),
where debugging support code was not being properly injected when
running on Edge `flutter run -d edge`. The issue was due to missing
conditions in the injection logic that prevented the debugger service
from initializing correctly in this environment.

This change ensures that debugging support is consistently injected when
connected devices are present and the user has selected one of them.

fix https://github.com/flutter/flutter/issues/167102.
This commit is contained in:
Jessy Yameogo 2025-05-16 11:33:31 -07:00 committed by GitHub
parent 3c6f74c799
commit b41c8e022b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -374,6 +374,15 @@ class WebAssetServer implements AssetReader {
logging.Logger.root.level = logging.Level.ALL;
logging.Logger.root.onRecord.listen(log);
// Retrieve connected web devices.
final List<Device>? devices = await globals.deviceManager?.getAllDevices();
final Set<String> connectedWebDeviceIds =
devices
?.where((Device d) => d.platformType == PlatformType.web && d.isConnected)
.map((Device d) => d.id)
.toSet() ??
<String>{};
// In debug builds, spin up DWDS and the full asset server.
final Dwds dwds = await dwdsLauncher(
assetReader: server,
@ -424,10 +433,12 @@ class WebAssetServer implements AssetReader {
),
appMetadata: AppMetadata(hostname: hostname),
),
// Defaults to 'chrome' if deviceManager or specifiedDeviceId is null,
// ensuring the condition is true by default.
// Inject the debugging support code if connected web devices are present,
// and user specified a device id that matches a connected web device.
// If the user did not specify a device id, we use chrome as the default.
injectDebuggingSupportCode:
(globals.deviceManager?.specifiedDeviceId ?? 'chrome') == 'chrome',
connectedWebDeviceIds.isNotEmpty &&
connectedWebDeviceIds.contains(globals.deviceManager?.specifiedDeviceId ?? 'chrome'),
);
shelf.Pipeline pipeline = const shelf.Pipeline();
if (enableDwds) {