Skip to content
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

Extensions cleanup and TODOs #6216

Merged
merged 2 commits into from
Aug 18, 2023
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
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
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