Allow skipping chrome launch with --no-web-browser-launch (#40627)
This commit is contained in:
@@ -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 }
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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<DebugConnection> _cachedExtensionFuture;
|
||||
|
||||
/// Retrieve the [DebugConnection] for the current application
|
||||
Future<DebugConnection> runAndDebug() {
|
||||
Future<DebugConnection> runAndDebug(DebuggingOptions debuggingOptions) {
|
||||
final Completer<DebugConnection> firstConnection = Completer<DebugConnection>();
|
||||
_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;
|
||||
}
|
||||
|
||||
@@ -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(<String, dynamic>{
|
||||
'id': id.toString(),
|
||||
'progressId': progressId,
|
||||
'finished': true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class LogMessage {
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -146,6 +146,14 @@ abstract class FlutterCommand extends Command<void> {
|
||||
'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() {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -539,6 +539,9 @@ class StreamLogger extends Logger {
|
||||
}
|
||||
|
||||
Stream<String> get stream => _controller.stream;
|
||||
|
||||
@override
|
||||
void sendNotification(String message, {String progressId}) { }
|
||||
}
|
||||
|
||||
class LoggerInterrupted implements Exception {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 _) {
|
||||
|
||||
Reference in New Issue
Block a user