-
Notifications
You must be signed in to change notification settings - Fork 324
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
[DevTools Server] Listen for URIs and register launchDevTools service. #555
Conversation
kenzieschmoll
commented
Apr 17, 2019
- 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#'; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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())}#';
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
return json.decode(line) as Map<String, dynamic>; | ||
}); | ||
|
||
// Example json input: [{"url":"ws://localhost:8888/ws"}] |
There was a problem hiding this comment.
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" }
}
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
vmServicePort = | ||
vmServicePort.substring(0, vmServicePort.indexOf('/')); | ||
|
||
final url = '$devtoolsUrl/?port=$vmServicePort#'; |
There was a problem hiding this comment.
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"}] |
There was a problem hiding this comment.
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.
int port, | ||
}) async { | ||
final dataDir = Directory.systemTemp.createTempSync(); | ||
args ??= []; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 🤔
There was a problem hiding this comment.
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._( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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())}#'; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed