Skip to content

Commit bebc4e8

Browse files
authored
Fix bugs where package:devtools was still used when devtools_app was required. (#1059)
1 parent e5344ad commit bebc4e8

18 files changed

+163
-837
lines changed

packages/devtools_app/example/readme.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/devtools_app/example/test.dart

Lines changed: 0 additions & 94 deletions
This file was deleted.

packages/devtools_app/example/test_foo.dart

Lines changed: 0 additions & 7 deletions
This file was deleted.

packages/devtools_app/lib/main.dart

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// Copyright 2018 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'dart:async';
6+
import 'package:html_shim/html.dart';
7+
8+
import 'package:devtools_app/src/framework/framework_core.dart';
9+
import 'package:devtools_app/src/main.dart';
10+
import 'package:devtools_app/src/ui/analytics.dart' as ga;
11+
import 'package:devtools_app/src/ui/analytics_platform.dart' as ga_platform;
12+
import 'package:platform_detect/platform_detect.dart';
13+
14+
void main() {
15+
// Run in a zone in order to catch all Dart exceptions.
16+
runZoned(
17+
() {
18+
// Initialize the core framework.
19+
FrameworkCore.init();
20+
21+
// Load the web app framework.
22+
final PerfToolFramework framework = PerfToolFramework();
23+
24+
// Show the opt-in dialog for collection analytics?
25+
try {
26+
if (ga.isGtagsEnabled() &
27+
(!window.localStorage.containsKey(ga_platform.devToolsProperty()) ||
28+
window.localStorage[ga_platform.devToolsProperty()].isEmpty)) {
29+
framework.showAnalyticsDialog();
30+
}
31+
} catch (e) {
32+
// If there are errors setting up analytics, write them to the console
33+
// but do not prevent DevTools from loading.
34+
window.console.error(e);
35+
}
36+
37+
if (!browser.isChrome) {
38+
final browserName =
39+
// Edge shows up as IE, so we replace it's name to avoid confusion.
40+
browser.isInternetExplorer || browser == Browser.UnknownBrowser
41+
? 'an unsupported browser'
42+
: browser.name;
43+
framework.disableAppWithError(
44+
'ERROR: You are running DevTools on $browserName, '
45+
'but DevTools only runs on Chrome.',
46+
'Reopen this url in a Chrome browser to use DevTools.',
47+
);
48+
return;
49+
}
50+
51+
FrameworkCore.initVmService(errorReporter: (String title, dynamic error) {
52+
framework.showError(title, error);
53+
}).then((bool connected) {
54+
if (!connected) {
55+
framework.showConnectionDialog();
56+
framework.showSnapshotMessage();
57+
// Clear the main element so it stops displaying "Loading..."
58+
// TODO(jacobr): display a message explaining how to launch a Flutter
59+
// application from the command line and connect to it with DevTools.
60+
framework.mainElement.clear();
61+
}
62+
});
63+
64+
framework.loadScreenFromLocation();
65+
},
66+
zoneSpecification: const ZoneSpecification(
67+
handleUncaughtError: _handleUncaughtError,
68+
),
69+
);
70+
}
71+
72+
void _handleUncaughtError(
73+
Zone self,
74+
ZoneDelegate parent,
75+
Zone zone,
76+
Object error,
77+
StackTrace stackTrace,
78+
) {
79+
// TODO(devoncarew): `stackTrace` always seems to be null.
80+
81+
// Report exceptions with DevTools to GA; user's Flutter app exceptions are
82+
// not collected.
83+
ga.error('$error\n${stackTrace ?? ''}'.trim(), true);
84+
85+
final Console console = window.console;
86+
87+
// Also write them to the console to aid debugging.
88+
final errorLines = error.toString().split('\n');
89+
console.groupCollapsed(
90+
'DevTools exception: [${error.runtimeType}] ${errorLines.first}');
91+
console.log(errorLines.skip(1).join('\n'));
92+
93+
if (stackTrace != null) {
94+
if (errorLines.length > 1) {
95+
console.log('\n');
96+
}
97+
console.log(stackTrace.toString().trim());
98+
}
99+
100+
console.groupEnd();
101+
}

packages/devtools_app/lib/src/memory/memory_plotly.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import 'package:js/js_util.dart';
5+
import 'package:html_shim/js_util.dart';
6+
import 'package:plotly_js/plotly.dart';
67

7-
import '../ui/fake_flutter/dart_ui/dart_ui.dart';
8+
import '../ui/fake_flutter/fake_flutter.dart';
89
import '../ui/flutter_html_shim.dart';
9-
import '../ui/plotly.dart';
1010
import '../ui/theme.dart';
1111
import 'memory_chart.dart';
1212

packages/devtools_app/lib/src/model/model.dart

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ library model;
1010

1111
import 'dart:async';
1212
import 'dart:convert';
13-
import 'dart:js' as js;
13+
14+
// TODO(jacobr): remove these dependencies on html_shim.
15+
import 'package:html_shim/html.dart' show window;
16+
import 'package:html_shim/js.dart' as js;
17+
import 'package:html_shim/js_util.dart' as js_util;
1418

1519
import 'package:vm_service/vm_service.dart';
1620

@@ -64,8 +68,9 @@ class App {
6468
final PerfToolFramework framework;
6569

6670
void _bind() {
67-
final js.JsObject binding = js.JsObject.jsify(<dynamic, dynamic>{});
68-
binding['send'] = (String method, int id, dynamic arg) {
71+
final binding = js_util.newObject();
72+
js_util.setProperty(binding, 'send',
73+
js.allowInterop((String method, int id, dynamic arg) {
6974
try {
7075
final dynamic result = _dispatch(method, id, arg);
7176
Future<dynamic>.value(result).then((dynamic result) {
@@ -76,9 +81,9 @@ class App {
7681
} catch (error, stackTrace) {
7782
_sendReponseError(id, error, stackTrace);
7883
}
79-
};
84+
}));
8085

81-
js.context['devtools'] = binding;
86+
js_util.setProperty(window, 'devtools', binding);
8287
}
8388

8489
Future<void> devToolsReady(dynamic message) async {

packages/devtools_app/lib/src/timeline/frames_bar_chart.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44

55
import 'dart:async';
66

7+
import 'package:plotly_js/plotly.dart';
8+
79
import '../config_specific/logger.dart';
810
import '../framework/framework.dart';
911
import '../ui/analytics.dart' as ga;
1012
import '../ui/elements.dart';
11-
import '../ui/plotly.dart';
1213
import 'frames_bar_plotly.dart';
1314
import 'timeline_controller.dart';
1415
import 'timeline_model.dart';

packages/devtools_app/lib/src/timeline/frames_bar_plotly.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import 'package:js/js_util.dart';
5+
// TODO(jacobr): remove all uses of JS interop from package:devtools_app
6+
import 'package:html_shim/js_util.dart';
7+
import 'package:plotly_js/plotly.dart';
68

79
import '../ui/colors.dart';
810
import '../ui/flutter_html_shim.dart';
9-
import '../ui/plotly.dart';
1011
import '../ui/theme.dart';
1112

1213
class FramesBarPlotly {

packages/devtools_app/lib/src/ui/html_icon_renderer.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ class _MaterialIconRenderer extends HtmlIconRenderer<MaterialIcon> {
279279
if (_iconsFont == null) {
280280
_iconsFont = FontFace(
281281
'Material Icons',
282-
'url(packages/devtools/src/ui/MaterialIcons-Regular.woff2)',
282+
'url(packages/devtools_app/src/ui/MaterialIcons-Regular.woff2)',
283283
);
284284
document.fonts.add(_iconsFont);
285285
_iconsFontFuture = _iconsFont.load();

0 commit comments

Comments
 (0)