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 2 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
3 changes: 3 additions & 0 deletions dwds/lib/dwds.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,15 @@ class Dwds {
bool serveDevTools,
UrlEncoder urlEncoder,
bool spawnDds = true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: why do some of these have default values here while others use ??=?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I didn't add that :P I prefer the ??= pattern while this package isn't migrated to null safety. Fixed.

bool enableDevtoolsLaunch,
}) async {
hostname ??= 'localhost';
enableDebugging ??= true;
enableDebugExtension ??= false;
useSseForDebugProxy ??= true;
useSseForDebugBackend ??= true;
serveDevTools ??= true;
enableDevtoolsLaunch ??= true;
globalLoadStrategy = loadStrategy;

DevTools devTools;
Expand Down Expand Up @@ -146,6 +148,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