Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DevTools Server] Listen for URIs and register launchDevTools service. #555

Merged
merged 6 commits into from
Apr 19, 2019

Conversation

kenzieschmoll
Copy link
Member

  • Listens for URIs over stdin
  • Connects to vm service port provided in URI and registers launchDevTools service / method
  • Adds code to launch chrome (this will be moved to dart-lang/browser_launcher when I create that package)
  • Fixes a bug with callMulticastService - delete method as it is not needed

vmServicePort =
vmServicePort.substring(0, vmServicePort.indexOf('/'));

final url = '$devtoolsUrl/?port=$vmServicePort#';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will need to be something like uri=${encodeURIComponent(uri)}, we can't use raw ports numbers once the VM tokens land.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussed offline. changing to final url = '$devtoolsUrl/url=${Uri.encodeComponent(uri.toString())}#';

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

packages/devtools_server/lib/src/chrome.dart Outdated Show resolved Hide resolved
return json.decode(line) as Map<String, dynamic>;
});

// Example json input: [{"url":"ws://localhost:8888/ws"}]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this JSON should match the format of our other protocols and the output we send, with a method param, something like:

{
  "method": "vm.register",
  "params": { "url": "blah://blah" }
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should also check machineMode? If we're not running in machine mode, maybe we don't need to parse this (or, we might want the interface to be simpler to paste a URL than to make it into JSON).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed out the ID from the example above. To work the same as our other machine modes (which is essentially JSON-RPC), the dialog would look like this:

Editor sends the request (which includes an ID):

{
  "id": 1,
  "method": "vm.register",
  "params": { "url": "blah://blah" }
}

Then the server should respond with either a result (which can be empty or null in this case, we don't really have any data to return):

{
  "id": 1,
  "result": {}
}

or an error:

{
  "id": 1,
  "error": "Unable to connect to VM service"
}

The code that handles this kind of thing for Flutter is here. The error message should be formatted such that it's reasonable for the editor to show the user to tell them something has gone wrong.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on keeping the protocol consistent with other daemon style tools.
For now we only need to support the daemon version as this is for IDE users. Command line users are responsible for opening their own browser.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed this to expect json in the above format.

packages/devtools_server/lib/src/server.dart Outdated Show resolved Hide resolved
packages/devtools_server/lib/src/server.dart Outdated Show resolved Hide resolved
Copy link
Member Author

@kenzieschmoll kenzieschmoll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed most of this with Danny offline. Addressed comments.

packages/devtools_server/lib/src/chrome.dart Outdated Show resolved Hide resolved
packages/devtools_server/lib/src/chrome.dart Outdated Show resolved Hide resolved
packages/devtools_server/lib/src/chrome.dart Outdated Show resolved Hide resolved
packages/devtools_server/lib/src/server.dart Outdated Show resolved Hide resolved
packages/devtools_server/lib/src/server.dart Outdated Show resolved Hide resolved
vmServicePort =
vmServicePort.substring(0, vmServicePort.indexOf('/'));

final url = '$devtoolsUrl/?port=$vmServicePort#';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussed offline. changing to final url = '$devtoolsUrl/url=${Uri.encodeComponent(uri.toString())}#';

return json.decode(line) as Map<String, dynamic>;
});

// Example json input: [{"url":"ws://localhost:8888/ws"}]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed this to expect json in the above format.

packages/devtools_server/lib/src/server.dart Outdated Show resolved Hide resolved
int port,
}) async {
final dataDir = Directory.systemTemp.createTempSync();
args ??= [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use Dart default arguments instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oddly enough, changing this to List<String> args = const [], breaks everything 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can't add elements to a const list. Create a new list with the args to pass to Process.start.
In general, it is bad practice to modify arguments passed in to a method when you don't need to so that way of writing the code is cleaner in general.

@@ -92,8 +91,8 @@ class Chrome {
.firstWhere((line) => line.startsWith('DevTools listening'));

return _connect(Chrome._(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't make sense without the --remoteDebuggingPort option. Remove this code. Someone who wants to connect to the debug port can do that separately in a wrapper method.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually never mind. we can keep this but we should handle a null debugPort better.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed parts of this code we don't need. I will add them back when I create the browser_launcher package.

@@ -55,35 +54,35 @@ class Chrome {

/// Connects to an instance of Chrome with an open debug port.
static Future<Chrome> fromExisting(int port) async =>
_connect(Chrome._(port, ChromeConnection('localhost', port)));
_connect(Chrome._(ChromeConnection('localhost', port), debugPort: port));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shouldn't create a ChromeConnection when there isn't a chrome remote debugging port.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed this code.

args.addAll(urls);

await Process.start(_executable, args);
final processArgs = List.from(urls)..addAll(args);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you switched the order of the urls and the args.
I would write
args.toList()..addAll(urls)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

final url = '$devToolsUrl/url=${Uri.encodeComponent(uri.toString())}#';
// TODO(kenzie): modify this to append arguments (i.e. theme=dark). This
// likely will require passing in args.
final url = '$devToolsUrl/?url=${Uri.encodeComponent(uri.toString())}#';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: why are we adding a '#' at the end of the url?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

@kenzieschmoll kenzieschmoll merged commit 5473bed into flutter:master Apr 19, 2019
@kenzieschmoll kenzieschmoll deleted the launchDevtoolsService branch April 19, 2019 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants