Skip to content

Chrome fixes for VS code #342

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 6 commits into from
Apr 26, 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/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dependencies:

dev_dependencies:
args: ^1.0.0
build_daemon: ^0.5.0
build_runner: ^1.0.0
build_web_compilers: '>=1.0.0 <3.0.0'
test: ^1.6.0
Expand Down
2 changes: 1 addition & 1 deletion dwds/test/test_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class TestContext {
}
printOnFailure(line);
});
await assetReadyCompleter.future;
await assetReadyCompleter.future.timeout(Duration(seconds: 60));
appUrl = 'http://localhost:$port/hello_world/';
var debugPort = await findUnusedPort();
webDriver = await createDriver(desired: {
Expand Down
1 change: 1 addition & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ environment:
dev_dependencies:
build_runner: '>=1.3.0 <2.0.0'
build_web_compilers: '>=1.0.0 <3.0.0'
build_daemon: ^0.5.0
10 changes: 10 additions & 0 deletions webdev/lib/src/command/daemon_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'dart:convert';
import 'dart:io';

import 'package:args/command_runner.dart';
import 'package:async/async.dart';
import 'package:pedantic/pedantic.dart';

import '../daemon/app_domain.dart';
Expand Down Expand Up @@ -52,6 +53,14 @@ class DaemonCommand extends Command<int> {
Future<int> run() async {
Daemon daemon;
DevWorkflow workflow;
var cancelCount = 0;
var cancelSub = StreamGroup.merge(
[ProcessSignal.sigint.watch(), ProcessSignal.sigterm.watch()])
.listen((signal) async {
cancelCount++;
daemon?.shutdown();
if (cancelCount > 1) exit(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know if 1 is actually the desired exit code? It isn't necessarily clear what it should be.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is consistent with build_daemon and a couple internal tools. Gonna leave it as is.

});
try {
daemon = Daemon(_stdinCommandStream, _stdoutCommandResponse);
var daemonDomain = DaemonDomain(daemon);
Expand All @@ -76,6 +85,7 @@ class DaemonCommand extends Command<int> {
daemon?.shutdown();
rethrow;
} finally {
unawaited(cancelSub.cancel());
unawaited(workflow?.shutDown());
}
}
Expand Down
22 changes: 17 additions & 5 deletions webdev/lib/src/serve/chrome.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,33 @@ var _currentCompleter = Completer<Chrome>();
class Chrome {
final int debugPort;
final Process _process;
final Directory _dataDir;

final ChromeConnection chromeConnection;

Chrome._(
this.debugPort,
this.chromeConnection, {
Process process,
}) : _process = process;
Directory dataDir,
}) : _process = process,
_dataDir = dataDir;

Future<void> close() async {
if (_currentCompleter.isCompleted) _currentCompleter = Completer<Chrome>();
chromeConnection.close();
_process?.kill();
_process?.kill(ProcessSignal.sigkill);
await _process?.exitCode;
try {
// Chrome starts another process as soon as it dies that modifies the
// profile information. Give it some time before attempting to delete
// the directory.
await Future.delayed(Duration(milliseconds: 500));
await _dataDir?.delete(recursive: true);
} catch (_) {
// Silently fail if we can't clean up the profile information.
// It is a system tmp directory so it should get cleaned up eventually.
}
}

/// Connects to an instance of Chrome with an open debug port.
Expand All @@ -72,9 +85,7 @@ class Chrome {
///
/// Each url in [urls] will be loaded in a separate tab.
static Future<Chrome> start(List<String> urls, {int port}) async {
var dataDir = Directory(p.joinAll(
[Directory.current.path, '.dart_tool', 'webdev', 'chrome_profile']))
..createSync(recursive: true);
var dataDir = Directory.systemTemp.createTempSync();
port = port == null || port == 0 ? await findUnusedPort() : port;
var args = [
// Using a tmp directory ensures that a new instance of chrome launches
Expand Down Expand Up @@ -109,6 +120,7 @@ class Chrome {
port,
ChromeConnection('localhost', port),
process: process,
dataDir: dataDir,
));
}

Expand Down
8 changes: 5 additions & 3 deletions webdev/lib/src/serve/handlers/dev_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ class DevHandler {

Future<void> close() async {
await _sub.cancel();
for (var connection in _connections) {
await connection.sink.close();
}
// We listen for connections to close and remove them from the connections
// set. Therefore we shouldn't asynchronously iterate through the
// connections.
await Future.wait(
_connections.map((connection) => connection.sink.close()));
await Future.wait(_servicesByAppId.values.map((futureServices) async {
await (await futureServices).close();
}));
Expand Down