Skip to content

Support disabling the launch of DevTools through keybinding #1269

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

Merged
merged 3 commits into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dwds/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Depend on `package:vm_service` version `6.1.0+1`.
- Update the `keepAlive` configs to prevent accidental reuse of a connection after stopping
a debug session.
- Support disabling the launching of Dart DevTools through `Alt + d` with `enableDevtoolsLaunch`.

**Breaking changes:**
- `LoadStrategy`s now require a `moduleInfoForEntrypoint`.
Expand Down
6 changes: 5 additions & 1 deletion dwds/lib/dwds.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,17 @@ class Dwds {
bool useSseForDebugBackend,
bool serveDevTools,
UrlEncoder urlEncoder,
bool spawnDds = true,
bool spawnDds,
bool enableDevtoolsLaunch,
}) async {
hostname ??= 'localhost';
enableDebugging ??= true;
enableDebugExtension ??= false;
useSseForDebugProxy ??= true;
useSseForDebugBackend ??= true;
serveDevTools ??= true;
enableDevtoolsLaunch ??= true;
spawnDds ??= true;
globalLoadStrategy = loadStrategy;

DevTools devTools;
Expand Down Expand Up @@ -146,6 +149,7 @@ class Dwds {
var injected = DwdsInjector(
loadStrategy,
extensionUri: extensionUri,
enableDevtoolsLaunch: enableDevtoolsLaunch,
);

var devHandler = DevHandler(
Expand Down
10 changes: 9 additions & 1 deletion dwds/lib/src/handlers/injector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ class DwdsInjector {
final String _extensionUri;
final _devHandlerPaths = StreamController<String>();
final _logger = Logger('DwdsInjector');
final bool _enableDevtoolsLaunch;

DwdsInjector(
this._loadStrategy, {
String extensionUri,
}) : _extensionUri = extensionUri;
bool enableDevtoolsLaunch,
}) : _extensionUri = extensionUri,
_enableDevtoolsLaunch = enableDevtoolsLaunch;

/// Returns the embedded dev handler paths.
///
Expand Down Expand Up @@ -93,6 +96,7 @@ class DwdsInjector {
entrypoint,
_extensionUri,
_loadStrategy,
_enableDevtoolsLaunch,
);
body += await _loadStrategy.bootstrapFor(entrypoint);
_logger.info('Injected debugging metadata for '
Expand Down Expand Up @@ -122,6 +126,7 @@ String _injectClientAndHoistMain(
String entrypointPath,
String extensionUri,
LoadStrategy loadStrategy,
bool enableDevtoolsLaunch,
) {
var bodyLines = body.split('\n');
var extensionIndex =
Expand All @@ -140,6 +145,7 @@ String _injectClientAndHoistMain(
entrypointPath,
extensionUri,
loadStrategy,
enableDevtoolsLaunch,
);
result += '''
// Injected by dwds for debugging support.
Expand Down Expand Up @@ -172,13 +178,15 @@ String _injectedClientSnippet(
String entrypointPath,
String extensionUri,
LoadStrategy loadStrategy,
bool enableDevtoolsLaunch,
) {
var injectedBody = 'window.\$dartAppId = "$appId";\n'
'window.\$dartReloadConfiguration = "${loadStrategy.reloadConfiguration}";\n'
'window.\$dartModuleStrategy = "${loadStrategy.id}";\n'
'window.\$loadModuleConfig = ${loadStrategy.loadModuleSnippet};\n'
'window.\$dwdsVersion = "$packageVersion";\n'
'window.\$dwdsDevHandlerPath = "$devHandlerPath";\n'
'window.\$dwdsEnableDevtoolsLaunch = $enableDevtoolsLaunch;\n'
'window.\$dartEntrypointPath = "$entrypointPath";\n'
'${loadStrategy.loadClientSnippet(_clientScript)}';
if (extensionUri != null) {
Expand Down
Loading