Skip to content
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 webdev/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 2.0.0-dev

- Fix an NPE is the reload logic.
- Shutdown the daemon process when the corresponding application is closed.

## 2.0.0-alpha.3

Expand Down
18 changes: 15 additions & 3 deletions webdev/lib/src/daemon/app_domain.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import 'dart:io';

import 'package:build_daemon/data/build_status.dart';
import 'package:dwds/service.dart';
import 'package:pedantic/pedantic.dart';
import 'package:vm_service_lib/vm_service_lib.dart';

import '../serve/chrome.dart';
import '../serve/debugger/app_debug_services.dart';
import '../serve/server_manager.dart';
import 'daemon.dart';
Expand Down Expand Up @@ -70,6 +70,18 @@ class AppDomain extends Domain {
_appDebugServices = await devHandler.loadAppServices(
connection.request.appId, connection.request.instanceId);
_appId = connection.request.appId;
unawaited(_appDebugServices
.debugService.chromeProxyService.tabConnection.onClose.first
.then((_) {
sendEvent('app.log', {
'appId': _appId,
'log': 'Lost connection to device.',
});
sendEvent('app.stop', {
'appId': _appId,
});
daemon.shutdown();
}));
sendEvent('app.start', {
'appId': _appId,
'directory': Directory.current.path,
Expand Down Expand Up @@ -165,8 +177,8 @@ class AppDomain extends Domain {
Future<bool> _stop(Map<String, dynamic> args) async {
var appId = getStringArg(args, 'appId', required: true);
if (_appId != appId) throw ArgumentError.value(appId, 'appId', 'Not found');
var chrome = await Chrome.connectedInstance;
await chrome.close();
await _appDebugServices.debugService.chromeProxyService.tabConnection
.close();
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to clarify, does this only close the application tab?

Copy link
Contributor

Choose a reason for hiding this comment

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

also what happens if the tab is already closed?

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 only closes the tab. In the case that we launch Chrome the resulting chrome process will be killed. The tab can't already be closed because closing the tab results in the daemon shutting down.

return true;
}

Expand Down
15 changes: 15 additions & 0 deletions webdev/test/daemon/app_domain_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,21 @@ void main() {
])));
await exitWebdev(webdev);
});

test('.stop', () async {
var webdev =
await runWebDev(['daemon'], workingDirectory: exampleDirectory);
var appId = await _getAppId(webdev);
var stopCall = '[{"method":"app.stop","id":0,'
'"params" : { "appId" : "$appId"}}]';
webdev.stdin.add(utf8.encode('$stopCall\n'));
await expectLater(
webdev.stdout,
emitsThrough(startsWith(
'[{"event":"app.stop","params":{"appId":"$appId"}}')));
// This should cause webdev to exit.
expect(await webdev.exitCode, equals(0));
});
});
}, tags: ['webdriver']);
}