Skip to content

Commit 800f17c

Browse files
authored
Support disabling the launch of DevTools through keybinding (#1269)
* Support disabling the launch of DevTools through keybinding * test * review fixes
1 parent b62a32b commit 800f17c

File tree

6 files changed

+141
-105
lines changed

6 files changed

+141
-105
lines changed

dwds/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- Depend on `package:vm_service` version `6.1.0+1`.
1313
- Update the `keepAlive` configs to prevent accidental reuse of a connection after stopping
1414
a debug session.
15+
- Support disabling the launching of Dart DevTools through `Alt + d` with `enableDevtoolsLaunch`.
1516

1617
**Breaking changes:**
1718
- `LoadStrategy`s now require a `moduleInfoForEntrypoint`.

dwds/lib/dwds.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,17 @@ class Dwds {
103103
bool useSseForDebugBackend,
104104
bool serveDevTools,
105105
UrlEncoder urlEncoder,
106-
bool spawnDds = true,
106+
bool spawnDds,
107+
bool enableDevtoolsLaunch,
107108
}) async {
108109
hostname ??= 'localhost';
109110
enableDebugging ??= true;
110111
enableDebugExtension ??= false;
111112
useSseForDebugProxy ??= true;
112113
useSseForDebugBackend ??= true;
113114
serveDevTools ??= true;
115+
enableDevtoolsLaunch ??= true;
116+
spawnDds ??= true;
114117
globalLoadStrategy = loadStrategy;
115118

116119
DevTools devTools;
@@ -146,6 +149,7 @@ class Dwds {
146149
var injected = DwdsInjector(
147150
loadStrategy,
148151
extensionUri: extensionUri,
152+
enableDevtoolsLaunch: enableDevtoolsLaunch,
149153
);
150154

151155
var devHandler = DevHandler(

dwds/lib/src/handlers/injector.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,14 @@ class DwdsInjector {
3434
final String _extensionUri;
3535
final _devHandlerPaths = StreamController<String>();
3636
final _logger = Logger('DwdsInjector');
37+
final bool _enableDevtoolsLaunch;
3738

3839
DwdsInjector(
3940
this._loadStrategy, {
4041
String extensionUri,
41-
}) : _extensionUri = extensionUri;
42+
bool enableDevtoolsLaunch,
43+
}) : _extensionUri = extensionUri,
44+
_enableDevtoolsLaunch = enableDevtoolsLaunch;
4245

4346
/// Returns the embedded dev handler paths.
4447
///
@@ -93,6 +96,7 @@ class DwdsInjector {
9396
entrypoint,
9497
_extensionUri,
9598
_loadStrategy,
99+
_enableDevtoolsLaunch,
96100
);
97101
body += await _loadStrategy.bootstrapFor(entrypoint);
98102
_logger.info('Injected debugging metadata for '
@@ -122,6 +126,7 @@ String _injectClientAndHoistMain(
122126
String entrypointPath,
123127
String extensionUri,
124128
LoadStrategy loadStrategy,
129+
bool enableDevtoolsLaunch,
125130
) {
126131
var bodyLines = body.split('\n');
127132
var extensionIndex =
@@ -140,6 +145,7 @@ String _injectClientAndHoistMain(
140145
entrypointPath,
141146
extensionUri,
142147
loadStrategy,
148+
enableDevtoolsLaunch,
143149
);
144150
result += '''
145151
// Injected by dwds for debugging support.
@@ -172,13 +178,15 @@ String _injectedClientSnippet(
172178
String entrypointPath,
173179
String extensionUri,
174180
LoadStrategy loadStrategy,
181+
bool enableDevtoolsLaunch,
175182
) {
176183
var injectedBody = 'window.\$dartAppId = "$appId";\n'
177184
'window.\$dartReloadConfiguration = "${loadStrategy.reloadConfiguration}";\n'
178185
'window.\$dartModuleStrategy = "${loadStrategy.id}";\n'
179186
'window.\$loadModuleConfig = ${loadStrategy.loadModuleSnippet};\n'
180187
'window.\$dwdsVersion = "$packageVersion";\n'
181188
'window.\$dwdsDevHandlerPath = "$devHandlerPath";\n'
189+
'window.\$dwdsEnableDevtoolsLaunch = $enableDevtoolsLaunch;\n'
182190
'window.\$dartEntrypointPath = "$entrypointPath";\n'
183191
'${loadStrategy.loadClientSnippet(_clientScript)}';
184192
if (extensionUri != null) {

0 commit comments

Comments
 (0)