Skip to content

Commit 4936532

Browse files
authored
Shutdown the daemon when the application is closed (#284)
defaults write -g ApplePressAndHoldEnabled -bool false
1 parent ba5821f commit 4936532

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

webdev/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## 2.0.0-dev
22

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

56
## 2.0.0-alpha.3
67

webdev/lib/src/daemon/app_domain.dart

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import 'dart:io';
88

99
import 'package:build_daemon/data/build_status.dart';
1010
import 'package:dwds/service.dart';
11+
import 'package:pedantic/pedantic.dart';
1112
import 'package:vm_service_lib/vm_service_lib.dart';
1213

13-
import '../serve/chrome.dart';
1414
import '../serve/debugger/app_debug_services.dart';
1515
import '../serve/server_manager.dart';
1616
import 'daemon.dart';
@@ -70,6 +70,18 @@ class AppDomain extends Domain {
7070
_appDebugServices = await devHandler.loadAppServices(
7171
connection.request.appId, connection.request.instanceId);
7272
_appId = connection.request.appId;
73+
unawaited(_appDebugServices
74+
.debugService.chromeProxyService.tabConnection.onClose.first
75+
.then((_) {
76+
sendEvent('app.log', {
77+
'appId': _appId,
78+
'log': 'Lost connection to device.',
79+
});
80+
sendEvent('app.stop', {
81+
'appId': _appId,
82+
});
83+
daemon.shutdown();
84+
}));
7385
sendEvent('app.start', {
7486
'appId': _appId,
7587
'directory': Directory.current.path,
@@ -165,8 +177,8 @@ class AppDomain extends Domain {
165177
Future<bool> _stop(Map<String, dynamic> args) async {
166178
var appId = getStringArg(args, 'appId', required: true);
167179
if (_appId != appId) throw ArgumentError.value(appId, 'appId', 'Not found');
168-
var chrome = await Chrome.connectedInstance;
169-
await chrome.close();
180+
await _appDebugServices.debugService.chromeProxyService.tabConnection
181+
.close();
170182
return true;
171183
}
172184

webdev/test/daemon/app_domain_test.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,21 @@ void main() {
111111
])));
112112
await exitWebdev(webdev);
113113
});
114+
115+
test('.stop', () async {
116+
var webdev =
117+
await runWebDev(['daemon'], workingDirectory: exampleDirectory);
118+
var appId = await _getAppId(webdev);
119+
var stopCall = '[{"method":"app.stop","id":0,'
120+
'"params" : { "appId" : "$appId"}}]';
121+
webdev.stdin.add(utf8.encode('$stopCall\n'));
122+
await expectLater(
123+
webdev.stdout,
124+
emitsThrough(startsWith(
125+
'[{"event":"app.stop","params":{"appId":"$appId"}}')));
126+
// This should cause webdev to exit.
127+
expect(await webdev.exitCode, equals(0));
128+
});
114129
});
115130
}, tags: ['webdriver']);
116131
}

0 commit comments

Comments
 (0)