Skip to content

Commit

Permalink
Deprecate the DevToolsExtension.requiresRunningApplication field (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kenzieschmoll authored Apr 17, 2024
1 parent b7a3d73 commit 97f25a4
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 70 deletions.
3 changes: 3 additions & 0 deletions packages/devtools_app/release_notes/NEXT_RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ session. - [#7598](https://github.com/flutter/devtools/pull/7598)

## DevTools Extension updates

* Deprecate the `DevToolsExtension.requiresRunningApplication` field in favor of the
new optional `requiresConnection` field that can be added to an extension's `config.yaml`
file. - [#7611](https://github.com/flutter/devtools/pull/7611), [#7602](https://github.com/flutter/devtools/pull/7602)
* Detect extensions for all types of run targets in a package. - [#7533](https://github.com/flutter/devtools/pull/7533),
[#7535](https://github.com/flutter/devtools/pull/7535)

Expand Down
1 change: 1 addition & 0 deletions packages/devtools_extensions/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## 0.2.0-dev.0
* Deprecate the `DevToolsExtension.requiresRunningApplication` field.
* Update `extension_config_spec.md` to include an optional field `requiresConnection`.
* Bump `devtools_shared` dependency to `^10.0.0`.
* Fix file locations in the `dart_foo` extension example.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ void main() {

testWidgets('end to end simulated environment', (tester) async {
runApp(
const DevToolsExtension(
requiresRunningApplication: false,
child: TestDevToolsExtension(),
),
const DevToolsExtension(child: TestDevToolsExtension()),
);
await tester.pump(safePumpDuration);
expect(find.byType(DevToolsExtension), findsOneWidget);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,11 @@ class SimulatedDevToolsWrapper extends StatefulWidget {
const SimulatedDevToolsWrapper({
super.key,
required this.child,
required this.requiresRunningApplication,
required this.onDtdConnectionChange,
});

final Widget child;

final bool requiresRunningApplication;

final Future<void> Function(String?) onDtdConnectionChange;

@override
Expand Down Expand Up @@ -156,8 +153,6 @@ class SimulatedDevToolsWrapperState extends State<SimulatedDevToolsWrapper>
),
_SimulatedApi(
simController: simController,
requiresRunningApplication:
widget.requiresRunningApplication,
connectedToApplication: vmServiceConnected,
),
const PaddedDivider(),
Expand All @@ -183,21 +178,15 @@ class SimulatedDevToolsWrapperState extends State<SimulatedDevToolsWrapper>
class _SimulatedApi extends StatelessWidget {
const _SimulatedApi({
required this.simController,
required this.requiresRunningApplication,
required this.connectedToApplication,
});

final SimulatedDevToolsController simController;

final bool requiresRunningApplication;

final bool connectedToApplication;

@override
Widget build(BuildContext context) {
if (requiresRunningApplication && !connectedToApplication) {
return const SizedBox.shrink();
}
return Padding(
padding: const EdgeInsets.symmetric(vertical: denseSpacing),
child: Column(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,10 @@ T _accessGlobalOrThrow<T>({required String globalName}) {
/// extension should be defined by [child].
///
/// This wrapper:
/// * initializes the [extensionManager] and [serviceManager] globals.
/// * initializes the [extensionManager] with the VM service connection from
/// DevTools when[requiresRunningApplication] is true.
/// * initializes the [extensionManager], [serviceManager], and [dtdManager]
/// globals.
/// * initializes the [extensionManager] with the VM service and Dart Tooling
/// Daemon connections when available.
/// * establishes a connection with DevTools for this extension to interact
/// over.
///
Expand All @@ -114,6 +115,10 @@ class DevToolsExtension extends StatefulWidget {
super.key,
required this.child,
this.eventHandlers = const {},
@Deprecated(
'Set the requiresConnection field in the extension\'s config.yaml '
'file instead.',
)
this.requiresRunningApplication = true,
});

Expand All @@ -126,6 +131,10 @@ class DevToolsExtension extends StatefulWidget {
final Map<DevToolsExtensionEventType, ExtensionEventHandler> eventHandlers;

/// Whether this extension requires a running application to use.
@Deprecated(
'Set the requiresConnection field in the extension\'s config.yaml '
'file instead.',
)
final bool requiresRunningApplication;

@override
Expand All @@ -138,11 +147,7 @@ class _DevToolsExtensionState extends State<DevToolsExtension>
void initState() {
super.initState();
_initGlobals();
unawaited(
extensionManager._init(
connectToVmService: widget.requiresRunningApplication,
),
);
unawaited(extensionManager._init());
for (final handler in widget.eventHandlers.entries) {
extensionManager.registerEventHandler(handler.key, handler.value);
}
Expand Down Expand Up @@ -177,10 +182,6 @@ class _DevToolsExtensionState extends State<DevToolsExtension>

@override
Widget build(BuildContext context) {
final child = _ConnectionAwareWrapper(
requiresRunningApplication: widget.requiresRunningApplication,
child: widget.child,
);
return MaterialApp(
themeMode: extensionManager.darkThemeEnabled.value
? ThemeMode.dark
Expand All @@ -198,38 +199,11 @@ class _DevToolsExtensionState extends State<DevToolsExtension>
home: Scaffold(
body: _useSimulatedEnvironment
? SimulatedDevToolsWrapper(
requiresRunningApplication: widget.requiresRunningApplication,
onDtdConnectionChange: extensionManager._connectToDtd,
child: child,
child: widget.child,
)
: child,
: widget.child,
),
);
}
}

class _ConnectionAwareWrapper extends StatelessWidget {
const _ConnectionAwareWrapper({
required this.child,
required this.requiresRunningApplication,
});

final bool requiresRunningApplication;

final Widget child;

@override
Widget build(BuildContext context) {
return ValueListenableBuilder(
valueListenable: serviceManager.connectedState,
builder: (context, connectedState, _) {
if (requiresRunningApplication && !connectedState.connected) {
return const Center(
child: Text('Please connect an app to use this DevTools Extension'),
);
}
return child;
},
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ExtensionManager {
EventListener? _handleMessageListener;

// ignore: unused_element, false positive due to part files
Future<void> _init({required bool connectToVmService}) async {
Future<void> _init() async {
window.addEventListener(
'message',
_handleMessageListener = _handleMessage.toJS,
Expand All @@ -62,19 +62,17 @@ class ExtensionManager {
}

final vmServiceUri = queryParams[_vmServiceQueryParameter];
if (connectToVmService) {
if (vmServiceUri == null) {
// Request the vm service uri for the connected app. DevTools will
// respond with a [DevToolsPluginEventType.connectedVmService] event
// containing the currently connected app's vm service URI.
postMessageToDevTools(
DevToolsExtensionEvent(
DevToolsExtensionEventType.vmServiceConnection,
),
);
} else {
unawaited(_connectToVmService(vmServiceUri));
}
if (vmServiceUri == null && !_useSimulatedEnvironment) {
// Request the vm service uri for the connected app. DevTools will
// respond with a [DevToolsPluginEventType.connectedVmService] event
// containing the currently connected app's vm service URI.
postMessageToDevTools(
DevToolsExtensionEvent(
DevToolsExtensionEventType.vmServiceConnection,
),
);
} else {
unawaited(_connectToVmService(vmServiceUri));
}
}

Expand Down

0 comments on commit 97f25a4

Please sign in to comment.