Skip to content

Faster DevTools launch #747

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

Merged
merged 10 commits into from
Oct 18, 2019
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
1 change: 1 addition & 0 deletions dwds/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- The injected client's connection is now based off the request URI.
- Fix an issue where resuming while paused at the start would cause an error.
- Expose the `ChromeDebugException` class for error handling purposes.
- DevTools will now launch immediately and lazily sets up necessary state.

## 0.7.4

Expand Down
8 changes: 0 additions & 8 deletions dwds/lib/data/run_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,3 @@ abstract class RunRequest implements Built<RunRequest, RunRequestBuilder> {

RunRequest._();
}

abstract class RunResponse implements Built<RunResponse, RunResponseBuilder> {
static Serializer<RunResponse> get serializer => _$runResponseSerializer;

factory RunResponse([Function(RunResponseBuilder) updates]) = _$RunResponse;

RunResponse._();
}
76 changes: 0 additions & 76 deletions dwds/lib/data/run_request.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion dwds/lib/data/serializers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ part 'serializers.g.dart';
DevToolsResponse,
ConnectRequest,
RunRequest,
RunResponse,
DefaultBuildResult,
IsolateExit,
IsolateStart,
Expand Down
3 changes: 1 addition & 2 deletions dwds/lib/data/serializers.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dwds/lib/dwds.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class Dwds {
Future<DebugConnection> debugConnection(AppConnection appConnection) async {
if (!_enableDebugging) throw StateError('Debugging is not enabled.');
var appDebugServices = await _devHandler.loadAppServices(appConnection);
await appDebugServices.chromeProxyService.isInitialized;
return DebugConnection(appDebugServices);
}

Expand Down
13 changes: 8 additions & 5 deletions dwds/lib/src/connections/app_connection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// for details. 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 'dart:convert';

import 'package:sse/server/sse_handler.dart';
Expand All @@ -14,17 +15,19 @@ import '../../data/serializers.dart';
class AppConnection {
/// The initial connection request sent from the application in the browser.
final ConnectRequest request;

final _startedCompleter = Completer<void>();
final SseConnection _connection;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: startCompleter sounds like an action, which is a bit confusing. Maybe _startupCompleter, or _startedCompleter? Or even just '_startup', as it's private in a pretty narrow scope, and Dart style avoids reiterating types in variable names. if (_startup.isCompleted) reads pretty well. And a comment wouldn't hurt.

var _isStarted = false;

AppConnection(this.request, this._connection);

bool get isStarted => _isStarted;
bool get isStarted => _startedCompleter.isCompleted;
Future<void> get onStart => _startedCompleter.future;

void runMain() {
if (_isStarted) throw StateError('Main has already started.');
if (_startedCompleter.isCompleted) {
throw StateError('Main has already started.');
}
_connection.sink.add(jsonEncode(serializers.serialize(RunRequest())));
_isStarted = true;
_startedCompleter.complete();
}
}
38 changes: 3 additions & 35 deletions dwds/lib/src/handlers/dev_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'package:build_daemon/data/serializers.dart' as build_daemon;
import 'package:dwds/data/error_response.dart';
import 'package:dwds/data/run_request.dart';
import 'package:dwds/src/connections/debug_connection.dart';
import 'package:dwds/src/debugging/remote_debugger.dart';
import 'package:dwds/src/debugging/webkit_debugger.dart';
import 'package:dwds/src/servers/extension_backend.dart';
import 'package:logging/logging.dart';
Expand Down Expand Up @@ -148,9 +147,6 @@ class DevHandler {
await startDebugService(await _chromeConnection(), appConnection);
var appServices = await _createAppDebugServices(
appConnection.request.appId, debugService);
if (appConnection.isStarted) {
await appServices.chromeProxyService.resumeFromStart();
}
unawaited(appServices.chromeProxyService.remoteDebugger.onClose.first
.whenComplete(() {
appServices.close();
Expand Down Expand Up @@ -187,8 +183,6 @@ class DevHandler {
await _handleIsolateExit(appConnection);
} else if (message is IsolateStart) {
await _handleIsolateStart(appConnection, injectedConnection);
} else if (message is RunResponse) {
await _handleRunResponse(appConnection);
}
}
} catch (e, s) {
Expand Down Expand Up @@ -262,15 +256,6 @@ class DevHandler {
return;
}

// If you load the same app in a different tab then we need to throw
// away our old services and start new ones.
if (!(await _isCorrectTab(appConnection.request.instanceId,
appServices.chromeProxyService.remoteDebugger))) {
unawaited(appServices.close());
unawaited(_servicesByAppId.remove(appConnection.request.appId));
appServices = await loadAppServices(appConnection);
}

sseConnection.sink.add(jsonEncode(
serializers.serialize(DevToolsResponse((b) => b..success = true))));

Expand All @@ -293,13 +278,9 @@ class DevHandler {
var services = await _servicesByAppId[message.appId];
var connection = AppConnection(message, sseConnection);
if (services != null && services.connectedInstanceId == null) {
// Re-connect to the previous instance if its in the same tab,
// otherwise do nothing for now.
if (await _isCorrectTab(
message.instanceId, services.chromeProxyService.remoteDebugger)) {
services.connectedInstanceId = message.instanceId;
await services.chromeProxyService.createIsolate(connection);
}
// Reconnect to existing service.
services.connectedInstanceId = message.instanceId;
await services.chromeProxyService.createIsolate(connection);
}
_appConnectionByAppId[message.appId] = connection;
_connectedApps.add(connection);
Expand All @@ -322,12 +303,6 @@ class DevHandler {
sseConnection.sink.add(jsonEncode(serializers.serialize(RunRequest())));
}

Future<void> _handleRunResponse(AppConnection appConnection) async {
await (await _servicesByAppId[appConnection.request.appId])
?.chromeProxyService
?.resumeFromStart();
}

void _listen() async {
var injectedConnections = _sseHandler.connections;
while (await injectedConnections.hasNext) {
Expand Down Expand Up @@ -406,10 +381,3 @@ class DevHandler {
});
}
}

/// Checks if connection of [remoteDebugger] is running the app with [instanceId].
Future<bool> _isCorrectTab(
String instanceId, RemoteDebugger remoteDebugger) async {
var result = await remoteDebugger.evaluate(r'window["$dartAppInstanceId"];');
return result.value == instanceId;
}
Loading