Change screenshot observatory port flag to a URI that can include the authentication code (#33666)

Fixes https://github.com/flutter/flutter/issues/32750
This commit is contained in:
Jason Simmons 2019-05-31 13:15:49 -07:00 committed by GitHub
parent f36a35d20a
commit b7bd5768c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -15,7 +15,7 @@ import '../vmservice.dart';
const String _kOut = 'out'; const String _kOut = 'out';
const String _kType = 'type'; const String _kType = 'type';
const String _kObservatoryPort = 'observatory-port'; const String _kObservatoryUri = 'observatory-uri';
const String _kDeviceType = 'device'; const String _kDeviceType = 'device';
const String _kSkiaType = 'skia'; const String _kSkiaType = 'skia';
const String _kRasterizerType = 'rasterizer'; const String _kRasterizerType = 'rasterizer';
@ -29,12 +29,12 @@ class ScreenshotCommand extends FlutterCommand {
help: 'Location to write the screenshot.', help: 'Location to write the screenshot.',
); );
argParser.addOption( argParser.addOption(
_kObservatoryPort, _kObservatoryUri,
valueHelp: 'port', valueHelp: 'URI',
help: 'The observatory port to connect to.\n' help: 'The observatory URI to connect to.\n'
'This is required when --$_kType is "$_kSkiaType" or "$_kRasterizerType".\n' 'This is required when --$_kType is "$_kSkiaType" or "$_kRasterizerType".\n'
'To find the observatory port number, use "flutter run --verbose" ' 'To find the observatory URI, use "flutter run" and look for'
'and look for "Forwarded host port ... for Observatory" in the output.', '"An Observatory ... is available at" in the output.',
); );
argParser.addOption( argParser.addOption(
_kType, _kType,
@ -45,8 +45,8 @@ class ScreenshotCommand extends FlutterCommand {
_kDeviceType: 'Delegate to the device\'s native screenshot capabilities. This ' _kDeviceType: 'Delegate to the device\'s native screenshot capabilities. This '
'screenshots the entire screen currently being displayed (including content ' 'screenshots the entire screen currently being displayed (including content '
'not rendered by Flutter, like the device status bar).', 'not rendered by Flutter, like the device status bar).',
_kSkiaType: 'Render the Flutter app as a Skia picture. Requires --$_kObservatoryPort', _kSkiaType: 'Render the Flutter app as a Skia picture. Requires --$_kObservatoryUri',
_kRasterizerType: 'Render the Flutter app using the rasterizer. Requires --$_kObservatoryPort', _kRasterizerType: 'Render the Flutter app using the rasterizer. Requires --$_kObservatoryUri',
}, },
defaultsTo: _kDeviceType, defaultsTo: _kDeviceType,
); );
@ -70,8 +70,8 @@ class ScreenshotCommand extends FlutterCommand {
throwToolExit('Must have a connected device'); throwToolExit('Must have a connected device');
if (argResults[_kType] == _kDeviceType && !device.supportsScreenshot) if (argResults[_kType] == _kDeviceType && !device.supportsScreenshot)
throwToolExit('Screenshot not supported for ${device.name}.'); throwToolExit('Screenshot not supported for ${device.name}.');
if (argResults[_kType] != _kDeviceType && argResults[_kObservatoryPort] == null) if (argResults[_kType] != _kDeviceType && argResults[_kObservatoryUri] == null)
throwToolExit('Observatory port must be specified for screenshot type ${argResults[_kType]}'); throwToolExit('Observatory URI must be specified for screenshot type ${argResults[_kType]}');
return super.verifyThenRunCommand(commandPath); return super.verifyThenRunCommand(commandPath);
} }
@ -127,8 +127,7 @@ class ScreenshotCommand extends FlutterCommand {
} }
Future<Map<String, dynamic>> _invokeVmServiceRpc(String method) async { Future<Map<String, dynamic>> _invokeVmServiceRpc(String method) async {
final Uri observatoryUri = Uri(scheme: 'http', host: '127.0.0.1', final Uri observatoryUri = Uri.parse(argResults[_kObservatoryUri]);
port: int.parse(argResults[_kObservatoryPort]));
final VMService vmService = await VMService.connect(observatoryUri); final VMService vmService = await VMService.connect(observatoryUri);
return await vmService.vm.invokeRpcRaw(method); return await vmService.vm.invokeRpcRaw(method);
} }