diff --git a/packages/flutter_tools/lib/src/base/logger.dart b/packages/flutter_tools/lib/src/base/logger.dart index 5a6460a475..1104cd7147 100644 --- a/packages/flutter_tools/lib/src/base/logger.dart +++ b/packages/flutter_tools/lib/src/base/logger.dart @@ -146,6 +146,14 @@ abstract class Logger { bool multilineOutput = false, int progressIndicatorPadding = kDefaultStatusPadding, }); + + /// Send a progress notification that is instant. + /// + /// Only surfaces a value in machine modes, Loggers may ignore this message in + /// non-machine modes. Like [startProgress] but with a single event. + void sendNotification(String message, { + String progressId, + }); } class StdoutLogger extends Logger { @@ -250,6 +258,9 @@ class StdoutLogger extends Logger { void _clearStatus() { _status = null; } + + @override + void sendNotification(String message, {String progressId}) { } } /// A [StdoutLogger] which replaces Unicode characters that cannot be printed to @@ -341,6 +352,9 @@ class BufferLogger extends Logger { _status.clear(); _trace.clear(); } + + @override + void sendNotification(String message, {String progressId}) { } } class VerboseLogger extends Logger { @@ -453,6 +467,9 @@ class VerboseLogger extends Logger { parent.printStatus(prefix + indentMessage); } } + + @override + void sendNotification(String message, {String progressId}) { } } enum _LogType { error, status, trace } diff --git a/packages/flutter_tools/lib/src/build_runner/resident_web_runner.dart b/packages/flutter_tools/lib/src/build_runner/resident_web_runner.dart index 6e4c146ef3..534df6d078 100644 --- a/packages/flutter_tools/lib/src/build_runner/resident_web_runner.dart +++ b/packages/flutter_tools/lib/src/build_runner/resident_web_runner.dart @@ -177,7 +177,7 @@ class ResidentWebRunner extends ResidentRunner { 'uri': _webFs.uri }); if (supportsServiceProtocol) { - _debugConnection = await _webFs.runAndDebug(); + _debugConnection = await _webFs.runAndDebug(debuggingOptions); unawaited(_debugConnection.onDone.whenComplete(exit)); } } catch (err, stackTrace) { diff --git a/packages/flutter_tools/lib/src/build_runner/web_fs.dart b/packages/flutter_tools/lib/src/build_runner/web_fs.dart index 8bf8318e3b..e8fb3ae9c7 100644 --- a/packages/flutter_tools/lib/src/build_runner/web_fs.dart +++ b/packages/flutter_tools/lib/src/build_runner/web_fs.dart @@ -30,6 +30,7 @@ import '../build_info.dart'; import '../bundle.dart'; import '../cache.dart'; import '../dart/package_map.dart'; +import '../device.dart'; import '../globals.dart'; import '../platform_plugins.dart'; import '../plugins.dart'; @@ -107,15 +108,19 @@ class WebFs { await _connectedApps?.cancel(); } + Future _cachedExtensionFuture; + /// Retrieve the [DebugConnection] for the current application - Future runAndDebug() { + Future runAndDebug(DebuggingOptions debuggingOptions) { final Completer firstConnection = Completer(); _connectedApps = _dwds.connectedApps.listen((AppConnection appConnection) async { - appConnection.runMain(); - final DebugConnection debugConnection = await _dwds.debugConnection(appConnection); + final DebugConnection debugConnection = debuggingOptions.browserLaunch + ? await _dwds.debugConnection(appConnection) + : await (_cachedExtensionFuture ??= _dwds.extensionDebugConnections.stream.first); if (!firstConnection.isCompleted) { firstConnection.complete(debugConnection); } + appConnection.runMain(); }); return firstConnection.future; } diff --git a/packages/flutter_tools/lib/src/commands/daemon.dart b/packages/flutter_tools/lib/src/commands/daemon.dart index 1dd4954bd7..56524783bc 100644 --- a/packages/flutter_tools/lib/src/commands/daemon.dart +++ b/packages/flutter_tools/lib/src/commands/daemon.dart @@ -895,6 +895,9 @@ class NotifyingLogger extends Logger { void dispose() { _messageController.close(); } + + @override + void sendNotification(String message, {String progressId}) { } } /// A running application, started by this daemon. @@ -1105,6 +1108,16 @@ class _AppRunLogger extends Logger { domain._sendAppEvent(app, 'progress', event); } } + + @override + void sendNotification(String message, {String progressId}) { + final int id = _nextProgressId++; + _sendProgressEvent({ + 'id': id.toString(), + 'progressId': progressId, + 'finished': true, + }); + } } class LogMessage { diff --git a/packages/flutter_tools/lib/src/commands/run.dart b/packages/flutter_tools/lib/src/commands/run.dart index e767a933a3..308c413b04 100644 --- a/packages/flutter_tools/lib/src/commands/run.dart +++ b/packages/flutter_tools/lib/src/commands/run.dart @@ -306,6 +306,7 @@ class RunCommand extends RunCommandBase { initializePlatform: argResults['web-initialize-platform'], hostname: featureFlags.isWebEnabled ? argResults['web-hostname'] : '', port: featureFlags.isWebEnabled ? argResults['web-port'] : '', + browserLaunch: featureFlags.isWebEnabled ? argResults['web-browser-launch'] : null, ); } } diff --git a/packages/flutter_tools/lib/src/device.dart b/packages/flutter_tools/lib/src/device.dart index 3bb8cd8593..1d18343f9d 100644 --- a/packages/flutter_tools/lib/src/device.dart +++ b/packages/flutter_tools/lib/src/device.dart @@ -492,6 +492,7 @@ class DebuggingOptions { this.initializePlatform = true, this.hostname, this.port, + this.browserLaunch = true, }) : debuggingEnabled = true; DebuggingOptions.disabled(this.buildInfo, { this.initializePlatform = true, this.port, this.hostname }) @@ -506,7 +507,8 @@ class DebuggingOptions { traceSystrace = false, dumpSkpOnShaderCompilation = false, verboseSystemLogs = false, - observatoryPort = null; + observatoryPort = null, + browserLaunch = true; final bool debuggingEnabled; @@ -526,6 +528,7 @@ class DebuggingOptions { final int observatoryPort; final String port; final String hostname; + final bool browserLaunch; bool get hasObservatoryPort => observatoryPort != null; } diff --git a/packages/flutter_tools/lib/src/runner/flutter_command.dart b/packages/flutter_tools/lib/src/runner/flutter_command.dart index 54d4cb5abd..ddd9113032 100644 --- a/packages/flutter_tools/lib/src/runner/flutter_command.dart +++ b/packages/flutter_tools/lib/src/runner/flutter_command.dart @@ -146,6 +146,14 @@ abstract class FlutterCommand extends Command { 'will select a random open port on the host.', hide: hide, ); + argParser.addFlag('web-browser-launch', + defaultsTo: true, + negatable: true, + help: 'Whether to automatically launch browsers for web devices ' + 'that do so. Setting this to true allows using the Dart debug extension ' + 'on Chrome and other browsers which support extensions.', + hide: hide, + ); } void usesTargetOption() { diff --git a/packages/flutter_tools/lib/src/web/web_device.dart b/packages/flutter_tools/lib/src/web/web_device.dart index 63c46f14e8..20368f4639 100644 --- a/packages/flutter_tools/lib/src/web/web_device.dart +++ b/packages/flutter_tools/lib/src/web/web_device.dart @@ -131,7 +131,13 @@ class ChromeDevice extends Device { }) async { // See [ResidentWebRunner.run] in flutter_tools/lib/src/resident_web_runner.dart // for the web initialization and server logic. - _chrome = await chromeLauncher.launch(platformArgs['uri']); + final String url = platformArgs['uri']; + if (debuggingOptions.browserLaunch) { + _chrome = await chromeLauncher.launch(url); + } else { + printStatus('Waiting for connection from Dart debug extension at $url', emphasis: true); + logger.sendNotification(url, progressId: 'debugExtension'); + } return LaunchResult.succeeded(observatoryUri: null); } @@ -240,6 +246,7 @@ class WebServerDevice extends Device { }) async { final String url = platformArgs['uri']; printStatus('$mainPath is being served at $url', emphasis: true); + logger.sendNotification(url, progressId: 'debugExtension'); return LaunchResult.succeeded(observatoryUri: null); } diff --git a/packages/flutter_tools/test/general.shard/commands/attach_test.dart b/packages/flutter_tools/test/general.shard/commands/attach_test.dart index 9e4175c7ad..c6d99983ca 100644 --- a/packages/flutter_tools/test/general.shard/commands/attach_test.dart +++ b/packages/flutter_tools/test/general.shard/commands/attach_test.dart @@ -539,6 +539,9 @@ class StreamLogger extends Logger { } Stream get stream => _controller.stream; + + @override + void sendNotification(String message, {String progressId}) { } } class LoggerInterrupted implements Exception { diff --git a/packages/flutter_tools/test/general.shard/resident_web_runner_cold_test.dart b/packages/flutter_tools/test/general.shard/resident_web_runner_cold_test.dart index e6291dea1d..0e8cd06055 100644 --- a/packages/flutter_tools/test/general.shard/resident_web_runner_cold_test.dart +++ b/packages/flutter_tools/test/general.shard/resident_web_runner_cold_test.dart @@ -56,7 +56,7 @@ void main() { fs.file('pubspec.yaml').createSync(); fs.file(fs.path.join('lib', 'main.dart')).createSync(recursive: true); fs.file(fs.path.join('web', 'index.html')).createSync(recursive: true); - when(mockWebFs.runAndDebug()).thenThrow(StateError('debugging not supported')); + when(mockWebFs.runAndDebug(any)).thenThrow(StateError('debugging not supported')); } test('Can successfully run and connect without vmservice', () => testbed.run(() async { diff --git a/packages/flutter_tools/test/general.shard/resident_web_runner_test.dart b/packages/flutter_tools/test/general.shard/resident_web_runner_test.dart index c70f48ae78..d6829e376f 100644 --- a/packages/flutter_tools/test/general.shard/resident_web_runner_test.dart +++ b/packages/flutter_tools/test/general.shard/resident_web_runner_test.dart @@ -65,7 +65,7 @@ void main() { fs.file('pubspec.yaml').createSync(); fs.file(fs.path.join('lib', 'main.dart')).createSync(recursive: true); fs.file(fs.path.join('web', 'index.html')).createSync(recursive: true); - when(mockWebFs.runAndDebug()).thenAnswer((Invocation _) async { + when(mockWebFs.runAndDebug(any)).thenAnswer((Invocation _) async { return mockDebugConnection; }); when(mockWebFs.recompile()).thenAnswer((Invocation _) {