Skip to content

Commit

Permalink
Extensions cleanup and TODOs (#6216)
Browse files Browse the repository at this point in the history
  • Loading branch information
kenzieschmoll authored Aug 18, 2023
1 parent d0db8ae commit f5e477e
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// ignore_for_file: avoid_web_libraries_in_flutter, as designed
import 'dart:async';
import 'dart:html' as html;
import 'dart:ui' as ui;
import 'dart:ui_web' as ui_web;

import 'package:devtools_extensions/api.dart';
import 'package:path/path.dart' as path;
Expand All @@ -18,9 +18,9 @@ import 'controller.dart';
/// Each time [EmbeddedExtensionControllerImpl.init] is called, we create a new
/// [html.IFrameElement] and register it to
/// [EmbeddedExtensionControllerImpl.viewId] via
/// [ui.platformViewRegistry.registerViewFactory]. Each new [html.IFrameElement]
/// must have a unique id in the [PlatformViewRegistry], which
/// [_viewIdIncrementer] is used to create.
/// [ui_web.platformViewRegistry.registerViewFactory]. Each new
/// [html.IFrameElement] must have a unique id in the [PlatformViewRegistry],
/// which [_viewIdIncrementer] is used to create.
var _viewIdIncrementer = 0;

class EmbeddedExtensionControllerImpl extends EmbeddedExtensionController {
Expand Down Expand Up @@ -70,10 +70,7 @@ class EmbeddedExtensionControllerImpl extends EmbeddedExtensionController {
..height = '100%'
..width = '100%';

// This ignore is required due to
// https://github.com/flutter/flutter/issues/41563
// ignore: undefined_prefixed_name
final registered = ui.platformViewRegistry.registerViewFactory(
final registered = ui_web.platformViewRegistry.registerViewFactory(
viewId,
(int viewId) => _extensionIFrame,
);
Expand Down
2 changes: 1 addition & 1 deletion packages/devtools_app/lib/src/shared/feature_flags.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ abstract class FeatureFlags {
/// Flag to enable DevTools extensions.
///
/// https://github.com/flutter/devtools/issues/1632
static bool devToolsExtensions = true; // enableExperiments;
static bool devToolsExtensions = enableExperiments;

/// Flag to enable debugging via DAP.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// TODO(https://github.com/flutter/devtools/issues/6215): remove this test.

@TestOn('vm')
import 'package:devtools_app/devtools_app.dart';
import 'package:devtools_app/src/screens/provider/instance_viewer/instance_details.dart';
Expand Down
2 changes: 2 additions & 0 deletions packages/devtools_app/test/provider/provider_screen_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// TODO(https://github.com/flutter/devtools/issues/6215): remove this test.

@TestOn('vm')
import 'package:devtools_app/devtools_app.dart';
import 'package:devtools_app/src/screens/provider/instance_viewer/instance_details.dart';
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import 'dart:html' as html;
import 'package:devtools_app_shared/service.dart';
import 'package:devtools_app_shared/ui.dart';
import 'package:devtools_app_shared/utils.dart';
import 'package:devtools_shared/service.dart';
import 'package:flutter/widgets.dart';
import 'package:logging/logging.dart';
import 'package:vm_service/vm_service.dart';

import '../../api.dart';
import 'connected_app_manager.dart';

part 'extension_manager.dart';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ part of 'devtools_extension.dart';
final _log = Logger('devtools_extensions/extension_manager');

class ExtensionManager {
final appManager = ConnectedAppManager();

final _registeredEventHandlers =
<DevToolsExtensionEventType, ExtensionEventHandler>{};

Expand Down Expand Up @@ -58,7 +56,13 @@ class ExtensionManager {
break;
case DevToolsExtensionEventType.vmServiceConnection:
final vmServiceUri = extensionEvent.data?['uri'] as String?;
unawaited(appManager.connectToVmService(vmServiceUri));
unawaited(
connectToVmService(vmServiceUri).catchError((e) {
// TODO(kenz): post a notification to DevTools for errors
// or create an error panel for the extensions screens.
print('Error connecting to VM service: $e');
}),
);
break;
case DevToolsExtensionEventType.unknown:
default:
Expand All @@ -75,4 +79,26 @@ class ExtensionManager {
void postMessageToDevTools(DevToolsExtensionEvent event) {
html.window.parent?.postMessage(event.toJson(), html.window.origin!);
}

Future<void> connectToVmService(String? vmServiceUri) async {
if (vmServiceUri == null) return;

final finishedCompleter = Completer<void>();
final vmService = await connect<VmService>(
uri: Uri.parse(vmServiceUri),
finishedCompleter: finishedCompleter,
createService: ({
// ignore: avoid-dynamic, code needs to match API from VmService.
required Stream<dynamic> /*String|List<int>*/ inStream,
required void Function(String message) writeMessage,
required Uri connectedUri,
}) {
return VmService(inStream, writeMessage);
},
);
await serviceManager.vmServiceOpened(
vmService,
onClosed: finishedCompleter.future,
);
}
}
1 change: 1 addition & 0 deletions packages/devtools_test/lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ void _mockFlutterAssets() {
);
}

// TODO(https://github.com/flutter/devtools/issues/6215): remove this helper.
/// Load fonts used by the devtool for golden-tests to use them
Future<void> loadFonts() async {
// source: https://medium.com/swlh/test-your-flutter-widgets-using-golden-files-b533ac0de469
Expand Down

0 comments on commit f5e477e

Please sign in to comment.