Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
3d3b5349
Unverified
Commit
3d3b5349
authored
Aug 17, 2020
by
Helin Shiah
Committed by
GitHub
Aug 17, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Return host and port from devtools launcher (#63795)
parent
8a4ada25
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
16 deletions
+42
-16
daemon.md
packages/flutter_tools/doc/daemon.md
+5
-1
daemon.dart
packages/flutter_tools/lib/src/commands/daemon.dart
+3
-3
resident_runner.dart
packages/flutter_tools/lib/src/resident_runner.dart
+10
-2
daemon_test.dart
...utter_tools/test/commands.shard/hermetic/daemon_test.dart
+24
-10
No files found.
packages/flutter_tools/doc/daemon.md
View file @
3d3b5349
...
...
@@ -256,7 +256,11 @@ The returned `params` will contain:
#### devtools.serve
The
`serve()`
command starts a DevTools server if one isn't already running and returns the host and port of the server.
The
`serve()`
command starts a DevTools server if one isn't already running. The return value will contain:
-
`success`
- whether the server started.
-
`host`
- the address host if the server successfully started.
-
`port`
- the port if the server successfully started.
## 'flutter run --machine' and 'flutter attach --machine'
...
...
packages/flutter_tools/lib/src/commands/daemon.dart
View file @
3d3b5349
...
...
@@ -897,11 +897,11 @@ class DevToolsDomain extends Domain {
Future
<
Map
<
String
,
dynamic
>>
serve
([
Map
<
String
,
dynamic
>
args
])
async
{
_devtoolsLauncher
??=
DevtoolsLauncher
.
instance
;
final
HttpServer
server
=
await
_devtoolsLauncher
.
serve
();
final
DevToolsServerAddress
server
=
await
_devtoolsLauncher
.
serve
();
return
<
String
,
dynamic
>{
'host'
:
server
.
address
.
host
,
'port'
:
server
.
port
,
'host'
:
server
?
.
host
,
'port'
:
server
?
.
port
,
};
}
...
...
packages/flutter_tools/lib/src/resident_runner.dart
View file @
3d3b5349
...
...
@@ -1723,15 +1723,16 @@ class DevtoolsLauncher {
}
}
Future
<
io
.
HttpServer
>
serve
()
async
{
Future
<
DevToolsServerAddress
>
serve
()
async
{
try
{
_devtoolsServer
??=
await
devtools_server
.
serveDevTools
(
enableStdinCommands:
false
,
);
return
DevToolsServerAddress
(
_devtoolsServer
.
address
.
host
,
_devtoolsServer
.
port
);
}
on
Exception
catch
(
e
,
st
)
{
globals
.
printTrace
(
'Failed to serve DevTools:
$e
\n
$st
'
);
return
null
;
}
return
_devtoolsServer
;
}
Future
<
void
>
close
()
async
{
...
...
@@ -1741,3 +1742,10 @@ class DevtoolsLauncher {
static
DevtoolsLauncher
get
instance
=>
context
.
get
<
DevtoolsLauncher
>()
??
DevtoolsLauncher
();
}
class
DevToolsServerAddress
{
DevToolsServerAddress
(
this
.
host
,
this
.
port
);
final
String
host
;
final
int
port
;
}
packages/flutter_tools/test/commands.shard/hermetic/daemon_test.dart
View file @
3d3b5349
...
...
@@ -3,7 +3,6 @@
// found in the LICENSE file.
import
'dart:async'
;
import
'dart:io'
;
import
'package:flutter_tools/src/android/android_workflow.dart'
;
import
'package:flutter_tools/src/base/common.dart'
;
...
...
@@ -304,7 +303,7 @@ void main() {
await
input
.
close
();
});
testUsingContext
(
'devtools.serve command should return host and port'
,
()
async
{
testUsingContext
(
'devtools.serve command should return host and port
on success
'
,
()
async
{
final
StreamController
<
Map
<
String
,
dynamic
>>
commands
=
StreamController
<
Map
<
String
,
dynamic
>>();
final
StreamController
<
Map
<
String
,
dynamic
>>
responses
=
StreamController
<
Map
<
String
,
dynamic
>>();
daemon
=
Daemon
(
...
...
@@ -312,19 +311,34 @@ void main() {
responses
.
add
,
notifyingLogger:
notifyingLogger
,
);
final
HttpServer
mockDevToolsServer
=
MockDevToolsServer
();
final
InternetAddress
mockInternetAddress
=
MockInternetAddress
();
when
(
mockDevToolsServer
.
address
).
thenReturn
(
mockInternetAddress
);
when
(
mockInternetAddress
.
host
).
thenReturn
(
'127.0.0.1'
);
when
(
mockDevToolsServer
.
port
).
thenReturn
(
1234
);
when
(
mockDevToolsLauncher
.
serve
()).
thenAnswer
((
_
)
async
=>
DevToolsServerAddress
(
'127.0.0.1'
,
1234
));
when
(
mockDevToolsLauncher
.
serve
()).
thenAnswer
((
_
)
async
=>
mockDevToolsServer
);
commands
.
add
(<
String
,
dynamic
>{
'id'
:
0
,
'method'
:
'devtools.serve'
});
final
Map
<
String
,
dynamic
>
response
=
await
responses
.
stream
.
firstWhere
((
Map
<
String
,
dynamic
>
response
)
=>
response
[
'id'
]
==
0
);
expect
(
response
[
'result'
],
isNotEmpty
);
expect
(
response
[
'result'
][
'host'
],
'127.0.0.1'
);
expect
(
response
[
'result'
][
'port'
],
1234
);
await
responses
.
close
();
await
commands
.
close
();
},
overrides:
<
Type
,
Generator
>{
DevtoolsLauncher:
()
=>
mockDevToolsLauncher
,
});
testUsingContext
(
'devtools.serve command should return null fields if null returned'
,
()
async
{
final
StreamController
<
Map
<
String
,
dynamic
>>
commands
=
StreamController
<
Map
<
String
,
dynamic
>>();
final
StreamController
<
Map
<
String
,
dynamic
>>
responses
=
StreamController
<
Map
<
String
,
dynamic
>>();
daemon
=
Daemon
(
commands
.
stream
,
responses
.
add
,
notifyingLogger:
notifyingLogger
,
);
when
(
mockDevToolsLauncher
.
serve
()).
thenAnswer
((
_
)
async
=>
null
);
commands
.
add
(<
String
,
dynamic
>{
'id'
:
0
,
'method'
:
'devtools.serve'
});
final
Map
<
String
,
dynamic
>
response
=
await
responses
.
stream
.
firstWhere
((
Map
<
String
,
dynamic
>
response
)
=>
response
[
'id'
]
==
0
);
expect
(
response
[
'result'
],
isNotEmpty
);
expect
(
response
[
'result'
][
'host'
],
equals
(
'127.0.0.1'
)
);
expect
(
response
[
'result'
][
'port'
],
equals
(
1234
)
);
expect
(
response
[
'result'
][
'host'
],
null
);
expect
(
response
[
'result'
][
'port'
],
null
);
await
responses
.
close
();
await
commands
.
close
();
},
overrides:
<
Type
,
Generator
>{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment