@@ -47,31 +47,43 @@ final _log = Logger('devtools_server_client');
47
47
bool get isDevToolsServerAvailable =>
48
48
kIsWeb && storage is ServerConnectionStorage ;
49
49
50
- const _debugDevToolsServerFlag = 'debug_devtools_server' ;
50
+ const _debugDevToolsServerEnvironmentVariable = String .fromEnvironment (
51
+ 'debug_devtools_server' ,
52
+ );
53
+
54
+ /// Whether DevTools was run using the `dt run` command, which runs DevTools in
55
+ /// debug mode using `flutter run` and connects it to an instance of the
56
+ /// DevTools server.
57
+ bool get usingDebugDevToolsServer =>
58
+ _debugDevToolsServerEnvironmentVariable.isNotEmpty && ! kReleaseMode;
51
59
52
60
String get devToolsServerUriAsString {
53
- const debugDevToolsServerUriAsString = String .fromEnvironment (
54
- _debugDevToolsServerFlag,
55
- );
56
61
// Ensure we only use the debug DevTools server URI in non-release
57
62
// builds. By running `dt run`, an instance of DevTools run with `flutter run`
58
63
// can be connected to the DevTools server on a different port.
59
- return debugDevToolsServerUriAsString.isNotEmpty && ! kReleaseMode
60
- ? debugDevToolsServerUriAsString
64
+ return usingDebugDevToolsServer
65
+ ? _debugDevToolsServerEnvironmentVariable
61
66
: Uri .base .toString ();
62
67
}
63
68
69
+ /// Helper to build a request URI to the DevTools server, which may not be on
70
+ /// the same origin as the DevTools app window.
71
+ Uri buildDevToolsServerRequestUri (String url) {
72
+ // [_debugDevToolsServerEnvironmentVariable] will be the empty string if the
73
+ // [_debugDevToolsServerFlag] environment variable declaration was not set
74
+ // using `--dart-define`.
75
+ const baseUri = _debugDevToolsServerEnvironmentVariable;
76
+ return Uri .parse (path.join (baseUri, url));
77
+ }
78
+
64
79
/// Helper to catch any server request which could fail.
65
80
///
66
81
/// Returns HttpRequest or null (if server failure).
67
82
Future <Response ?> request (String url) async {
68
83
Response ? response;
69
84
70
85
try {
71
- // This will be the empty string if this environment declaration was not
72
- // set using `--dart-define`.
73
- const baseUri = String .fromEnvironment (_debugDevToolsServerFlag);
74
- response = await post (Uri .parse (path.join (baseUri, url)));
86
+ response = await post (buildDevToolsServerRequestUri (url));
75
87
} catch (_) {}
76
88
77
89
return response;
0 commit comments