Unverified Commit 7065e433 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Allow skipping chrome launch with --no-web-browser-launch (#40627)

parent 9bd02a17
...@@ -146,6 +146,14 @@ abstract class Logger { ...@@ -146,6 +146,14 @@ abstract class Logger {
bool multilineOutput = false, bool multilineOutput = false,
int progressIndicatorPadding = kDefaultStatusPadding, 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 { class StdoutLogger extends Logger {
...@@ -250,6 +258,9 @@ class StdoutLogger extends Logger { ...@@ -250,6 +258,9 @@ class StdoutLogger extends Logger {
void _clearStatus() { void _clearStatus() {
_status = null; _status = null;
} }
@override
void sendNotification(String message, {String progressId}) { }
} }
/// A [StdoutLogger] which replaces Unicode characters that cannot be printed to /// A [StdoutLogger] which replaces Unicode characters that cannot be printed to
...@@ -341,6 +352,9 @@ class BufferLogger extends Logger { ...@@ -341,6 +352,9 @@ class BufferLogger extends Logger {
_status.clear(); _status.clear();
_trace.clear(); _trace.clear();
} }
@override
void sendNotification(String message, {String progressId}) { }
} }
class VerboseLogger extends Logger { class VerboseLogger extends Logger {
...@@ -453,6 +467,9 @@ class VerboseLogger extends Logger { ...@@ -453,6 +467,9 @@ class VerboseLogger extends Logger {
parent.printStatus(prefix + indentMessage); parent.printStatus(prefix + indentMessage);
} }
} }
@override
void sendNotification(String message, {String progressId}) { }
} }
enum _LogType { error, status, trace } enum _LogType { error, status, trace }
......
...@@ -177,7 +177,7 @@ class ResidentWebRunner extends ResidentRunner { ...@@ -177,7 +177,7 @@ class ResidentWebRunner extends ResidentRunner {
'uri': _webFs.uri 'uri': _webFs.uri
}); });
if (supportsServiceProtocol) { if (supportsServiceProtocol) {
_debugConnection = await _webFs.runAndDebug(); _debugConnection = await _webFs.runAndDebug(debuggingOptions);
unawaited(_debugConnection.onDone.whenComplete(exit)); unawaited(_debugConnection.onDone.whenComplete(exit));
} }
} catch (err, stackTrace) { } catch (err, stackTrace) {
......
...@@ -30,6 +30,7 @@ import '../build_info.dart'; ...@@ -30,6 +30,7 @@ import '../build_info.dart';
import '../bundle.dart'; import '../bundle.dart';
import '../cache.dart'; import '../cache.dart';
import '../dart/package_map.dart'; import '../dart/package_map.dart';
import '../device.dart';
import '../globals.dart'; import '../globals.dart';
import '../platform_plugins.dart'; import '../platform_plugins.dart';
import '../plugins.dart'; import '../plugins.dart';
...@@ -107,15 +108,19 @@ class WebFs { ...@@ -107,15 +108,19 @@ class WebFs {
await _connectedApps?.cancel(); await _connectedApps?.cancel();
} }
Future<DebugConnection> _cachedExtensionFuture;
/// Retrieve the [DebugConnection] for the current application /// Retrieve the [DebugConnection] for the current application
Future<DebugConnection> runAndDebug() { Future<DebugConnection> runAndDebug(DebuggingOptions debuggingOptions) {
final Completer<DebugConnection> firstConnection = Completer<DebugConnection>(); final Completer<DebugConnection> firstConnection = Completer<DebugConnection>();
_connectedApps = _dwds.connectedApps.listen((AppConnection appConnection) async { _connectedApps = _dwds.connectedApps.listen((AppConnection appConnection) async {
appConnection.runMain(); final DebugConnection debugConnection = debuggingOptions.browserLaunch
final DebugConnection debugConnection = await _dwds.debugConnection(appConnection); ? await _dwds.debugConnection(appConnection)
: await (_cachedExtensionFuture ??= _dwds.extensionDebugConnections.stream.first);
if (!firstConnection.isCompleted) { if (!firstConnection.isCompleted) {
firstConnection.complete(debugConnection); firstConnection.complete(debugConnection);
} }
appConnection.runMain();
}); });
return firstConnection.future; return firstConnection.future;
} }
......
...@@ -895,6 +895,9 @@ class NotifyingLogger extends Logger { ...@@ -895,6 +895,9 @@ class NotifyingLogger extends Logger {
void dispose() { void dispose() {
_messageController.close(); _messageController.close();
} }
@override
void sendNotification(String message, {String progressId}) { }
} }
/// A running application, started by this daemon. /// A running application, started by this daemon.
...@@ -1105,6 +1108,16 @@ class _AppRunLogger extends Logger { ...@@ -1105,6 +1108,16 @@ class _AppRunLogger extends Logger {
domain._sendAppEvent(app, 'progress', event); domain._sendAppEvent(app, 'progress', event);
} }
} }
@override
void sendNotification(String message, {String progressId}) {
final int id = _nextProgressId++;
_sendProgressEvent(<String, dynamic>{
'id': id.toString(),
'progressId': progressId,
'finished': true,
});
}
} }
class LogMessage { class LogMessage {
......
...@@ -306,6 +306,7 @@ class RunCommand extends RunCommandBase { ...@@ -306,6 +306,7 @@ class RunCommand extends RunCommandBase {
initializePlatform: argResults['web-initialize-platform'], initializePlatform: argResults['web-initialize-platform'],
hostname: featureFlags.isWebEnabled ? argResults['web-hostname'] : '', hostname: featureFlags.isWebEnabled ? argResults['web-hostname'] : '',
port: featureFlags.isWebEnabled ? argResults['web-port'] : '', port: featureFlags.isWebEnabled ? argResults['web-port'] : '',
browserLaunch: featureFlags.isWebEnabled ? argResults['web-browser-launch'] : null,
); );
} }
} }
......
...@@ -492,6 +492,7 @@ class DebuggingOptions { ...@@ -492,6 +492,7 @@ class DebuggingOptions {
this.initializePlatform = true, this.initializePlatform = true,
this.hostname, this.hostname,
this.port, this.port,
this.browserLaunch = true,
}) : debuggingEnabled = true; }) : debuggingEnabled = true;
DebuggingOptions.disabled(this.buildInfo, { this.initializePlatform = true, this.port, this.hostname }) DebuggingOptions.disabled(this.buildInfo, { this.initializePlatform = true, this.port, this.hostname })
...@@ -506,7 +507,8 @@ class DebuggingOptions { ...@@ -506,7 +507,8 @@ class DebuggingOptions {
traceSystrace = false, traceSystrace = false,
dumpSkpOnShaderCompilation = false, dumpSkpOnShaderCompilation = false,
verboseSystemLogs = false, verboseSystemLogs = false,
observatoryPort = null; observatoryPort = null,
browserLaunch = true;
final bool debuggingEnabled; final bool debuggingEnabled;
...@@ -526,6 +528,7 @@ class DebuggingOptions { ...@@ -526,6 +528,7 @@ class DebuggingOptions {
final int observatoryPort; final int observatoryPort;
final String port; final String port;
final String hostname; final String hostname;
final bool browserLaunch;
bool get hasObservatoryPort => observatoryPort != null; bool get hasObservatoryPort => observatoryPort != null;
} }
......
...@@ -146,6 +146,14 @@ abstract class FlutterCommand extends Command<void> { ...@@ -146,6 +146,14 @@ abstract class FlutterCommand extends Command<void> {
'will select a random open port on the host.', 'will select a random open port on the host.',
hide: hide, 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() { void usesTargetOption() {
......
...@@ -131,7 +131,13 @@ class ChromeDevice extends Device { ...@@ -131,7 +131,13 @@ class ChromeDevice extends Device {
}) async { }) async {
// See [ResidentWebRunner.run] in flutter_tools/lib/src/resident_web_runner.dart // See [ResidentWebRunner.run] in flutter_tools/lib/src/resident_web_runner.dart
// for the web initialization and server logic. // 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); return LaunchResult.succeeded(observatoryUri: null);
} }
...@@ -240,6 +246,7 @@ class WebServerDevice extends Device { ...@@ -240,6 +246,7 @@ class WebServerDevice extends Device {
}) async { }) async {
final String url = platformArgs['uri']; final String url = platformArgs['uri'];
printStatus('$mainPath is being served at $url', emphasis: true); printStatus('$mainPath is being served at $url', emphasis: true);
logger.sendNotification(url, progressId: 'debugExtension');
return LaunchResult.succeeded(observatoryUri: null); return LaunchResult.succeeded(observatoryUri: null);
} }
......
...@@ -539,6 +539,9 @@ class StreamLogger extends Logger { ...@@ -539,6 +539,9 @@ class StreamLogger extends Logger {
} }
Stream<String> get stream => _controller.stream; Stream<String> get stream => _controller.stream;
@override
void sendNotification(String message, {String progressId}) { }
} }
class LoggerInterrupted implements Exception { class LoggerInterrupted implements Exception {
......
...@@ -56,7 +56,7 @@ void main() { ...@@ -56,7 +56,7 @@ void main() {
fs.file('pubspec.yaml').createSync(); fs.file('pubspec.yaml').createSync();
fs.file(fs.path.join('lib', 'main.dart')).createSync(recursive: true); fs.file(fs.path.join('lib', 'main.dart')).createSync(recursive: true);
fs.file(fs.path.join('web', 'index.html')).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 { test('Can successfully run and connect without vmservice', () => testbed.run(() async {
......
...@@ -65,7 +65,7 @@ void main() { ...@@ -65,7 +65,7 @@ void main() {
fs.file('pubspec.yaml').createSync(); fs.file('pubspec.yaml').createSync();
fs.file(fs.path.join('lib', 'main.dart')).createSync(recursive: true); fs.file(fs.path.join('lib', 'main.dart')).createSync(recursive: true);
fs.file(fs.path.join('web', 'index.html')).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; return mockDebugConnection;
}); });
when(mockWebFs.recompile()).thenAnswer((Invocation _) { when(mockWebFs.recompile()).thenAnswer((Invocation _) {
......
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