-
Notifications
You must be signed in to change notification settings - Fork 336
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
Add ability to enable and disable an extension from the extension screen #6140
Merged
kenzieschmoll
merged 6 commits into
flutter:master
from
kenzieschmoll:extension-enable-from-screen
Aug 2, 2023
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2dc7979
Add ability to enable and disable an extension from the extension screen
kenzieschmoll cb93366
Merge branch 'master' of github.com:flutter/devtools into extension-e…
kenzieschmoll 0ad71ae
clean up
kenzieschmoll d0caf98
test
kenzieschmoll 52a1394
add tests
kenzieschmoll 22645b6
formatting
kenzieschmoll File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
239 changes: 239 additions & 0 deletions
239
packages/devtools_app/lib/src/extensions/extension_screen_controls.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,239 @@ | ||
// Copyright 2023 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'dart:async'; | ||
|
||
import 'package:devtools_shared/devtools_extensions.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
import '../shared/analytics/constants.dart' as gac; | ||
import '../shared/common_widgets.dart'; | ||
import '../shared/dialogs.dart'; | ||
import '../shared/globals.dart'; | ||
import '../shared/routing.dart'; | ||
import '../shared/theme.dart'; | ||
|
||
class EmbeddedExtensionHeader extends StatelessWidget { | ||
const EmbeddedExtensionHeader({super.key, required this.extension}); | ||
|
||
final DevToolsExtensionConfig extension; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final theme = Theme.of(context); | ||
final extensionName = extension.displayName; | ||
return AreaPaneHeader( | ||
title: RichText( | ||
text: TextSpan( | ||
text: 'package:$extensionName extension', | ||
style: theme.regularTextStyle.copyWith(fontWeight: FontWeight.bold), | ||
children: [ | ||
TextSpan( | ||
text: ' (v${extension.version})', | ||
style: theme.subtleTextStyle, | ||
), | ||
], | ||
), | ||
), | ||
includeTopBorder: false, | ||
roundedTopBorder: false, | ||
rightPadding: defaultSpacing, | ||
actions: [ | ||
RichText( | ||
text: LinkTextSpan( | ||
link: Link( | ||
display: 'Report an issue', | ||
url: extension.issueTrackerLink, | ||
gaScreenName: gac.extensionScreenId, | ||
gaSelectedItemDescription: gac.extensionFeedback(extensionName), | ||
), | ||
context: context, | ||
), | ||
), | ||
ValueListenableBuilder<ExtensionEnabledState>( | ||
valueListenable: | ||
extensionService.enabledStateListenable(extension.displayName), | ||
builder: (context, activationState, _) { | ||
if (activationState == ExtensionEnabledState.enabled) { | ||
return Padding( | ||
padding: const EdgeInsets.only(left: denseSpacing), | ||
child: DisableExtensionButton(extension: extension), | ||
); | ||
} | ||
return const SizedBox.shrink(); | ||
}, | ||
), | ||
], | ||
); | ||
} | ||
} | ||
|
||
@visibleForTesting | ||
class DisableExtensionButton extends StatelessWidget { | ||
const DisableExtensionButton({super.key, required this.extension}); | ||
|
||
final DevToolsExtensionConfig extension; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return DevToolsButton.iconOnly( | ||
icon: Icons.extension_off_outlined, | ||
outlined: false, | ||
tooltip: 'Disable extension', | ||
gaScreen: gac.extensionScreenId, | ||
gaSelection: gac.extensionDisable(extension.displayName), | ||
onPressed: () => unawaited( | ||
showDialog( | ||
context: context, | ||
builder: (_) => DisableExtensionDialog(extension: extension), | ||
), | ||
), | ||
); | ||
} | ||
} | ||
|
||
@visibleForTesting | ||
class DisableExtensionDialog extends StatelessWidget { | ||
const DisableExtensionDialog({super.key, required this.extension}); | ||
|
||
final DevToolsExtensionConfig extension; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final theme = Theme.of(context); | ||
return DevToolsDialog( | ||
title: const DialogTitleText('Disable extension?'), | ||
content: Column( | ||
mainAxisSize: MainAxisSize.min, | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
RichText( | ||
text: TextSpan( | ||
text: 'Are you sure you want to disable the ', | ||
style: theme.regularTextStyle, | ||
children: [ | ||
TextSpan( | ||
text: extension.displayName, | ||
style: theme.fixedFontStyle, | ||
), | ||
const TextSpan(text: ' extension?'), | ||
], | ||
), | ||
), | ||
const SizedBox(height: denseSpacing), | ||
RichText( | ||
text: TextSpan( | ||
text: 'You can always re-enable this extension later from the ', | ||
style: theme.regularTextStyle, | ||
children: [ | ||
TextSpan( | ||
text: 'DevTools Extensions ', | ||
style: theme.boldTextStyle, | ||
), | ||
WidgetSpan( | ||
child: Icon( | ||
Icons.extension_rounded, | ||
size: defaultIconSize, | ||
), | ||
), | ||
const TextSpan(text: ' menu.'), | ||
], | ||
), | ||
), | ||
], | ||
), | ||
actions: [ | ||
DialogTextButton( | ||
onPressed: () { | ||
unawaited( | ||
extensionService.setExtensionEnabledState( | ||
extension, | ||
enable: false, | ||
), | ||
); | ||
Navigator.of(context).pop(dialogDefaultContext); | ||
DevToolsRouterDelegate.of(context) | ||
.navigateHome(clearScreenParam: true); | ||
}, | ||
child: const Text('YES, DISABLE'), | ||
), | ||
const DialogCancelButton(), | ||
], | ||
); | ||
} | ||
} | ||
|
||
class EnableExtensionPrompt extends StatelessWidget { | ||
const EnableExtensionPrompt({ | ||
super.key, | ||
required this.extension, | ||
}); | ||
|
||
final DevToolsExtensionConfig extension; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final theme = Theme.of(context); | ||
final extensionName = extension.displayName; | ||
return Center( | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
RichText( | ||
text: TextSpan( | ||
text: 'The ', | ||
style: theme.regularTextStyle, | ||
children: [ | ||
TextSpan( | ||
text: extension.name, | ||
style: theme.fixedFontStyle, | ||
), | ||
const TextSpan( | ||
text: ' extension has not been enabled. Do you want to enable' | ||
' this extension?', | ||
), | ||
], | ||
), | ||
), | ||
const SizedBox(height: defaultSpacing), | ||
Row( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
DevToolsButton( | ||
label: 'Enable', | ||
gaScreen: gac.extensionScreenId, | ||
gaSelection: gac.extensionEnable(extensionName), | ||
elevatedButton: true, | ||
onPressed: () { | ||
unawaited( | ||
extensionService.setExtensionEnabledState( | ||
extension, | ||
enable: true, | ||
), | ||
); | ||
}, | ||
), | ||
const SizedBox(width: defaultSpacing), | ||
DevToolsButton( | ||
label: 'No, hide this screen', | ||
gaScreen: gac.extensionScreenId, | ||
gaSelection: gac.extensionDisable(extensionName), | ||
onPressed: () { | ||
unawaited( | ||
extensionService.setExtensionEnabledState( | ||
extension, | ||
enable: false, | ||
), | ||
); | ||
DevToolsRouterDelegate.of(context) | ||
.navigateHome(clearScreenParam: true); | ||
}, | ||
), | ||
], | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved to extension_screen_controls.dart