Skip to content

Handle page refreshes and opening in new tabs #222

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 11 commits into from
Mar 20, 2019
Prev Previous commit
Next Next commit
fix some tests, pass full message to connectedApps stream
  • Loading branch information
jakemac53 committed Mar 20, 2019
commit c73a54b6ac7f3080353044ea39841362a9cb4d14
1 change: 1 addition & 0 deletions dwds/example/hello_world/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<script defer src="main.dart.js"></script>
<script>
window.$dartAppId = 'id-for-testing';
window.$dartAppInstanceId = 'instance-id-for-testing';
</script>
</head>

Expand Down
32 changes: 18 additions & 14 deletions dwds/lib/src/chrome_proxy_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,6 @@ class ChromeProxyService implements VmServiceInterface {
isolate.extensionRPCs.addAll(
(extensionsResult.result['result']['value'] as List).cast<String>());

// TODO: We shouldn't need to fire these events since they exist on the
// isolate, but devtools doesn't recognize extensions after a page refresh
// otherwise.
for (var extensionRpc in isolate.extensionRPCs) {
_streamNotify(
'Isolate',
Event()
..kind = EventKind.kServiceExtensionAdded
..extensionRPC = extensionRpc);
}

for (var libraryRef in isolate.libraries) {
_libraryRefs[libraryRef.id] = libraryRef;
}
Expand All @@ -169,7 +158,8 @@ class ChromeProxyService implements VmServiceInterface {
'Isolate',
Event()
..kind = EventKind.kServiceExtensionAdded
..extensionRPC = service);
..extensionRPC = service
..isolate = isolateRef);
break;
case 'dart.developer.postEvent':
_streamNotify(
Expand All @@ -178,7 +168,8 @@ class ChromeProxyService implements VmServiceInterface {
..kind = EventKind.kExtension
..extensionKind = event.args[1].value as String
..extensionData = ExtensionData.parse(
jsonDecode(event.args[2].value as String) as Map));
jsonDecode(event.args[2].value as String) as Map)
..isolate = isolateRef);
break;
case 'dart.developer.inspect':
// All inspected objects should be real objects.
Expand All @@ -195,7 +186,8 @@ class ChromeProxyService implements VmServiceInterface {
Event()
..kind = EventKind.kInspect
..inspectee = inspectee
..timestamp = event.timestamp.toInt());
..timestamp = event.timestamp.toInt()
..isolate = isolateRef);
break;
default:
break;
Expand All @@ -215,6 +207,18 @@ class ChromeProxyService implements VmServiceInterface {
Event()
..kind = EventKind.kIsolateRunnable
..isolate = isolateRef);

// TODO: We shouldn't need to fire these events since they exist on the
// isolate, but devtools doesn't recognize extensions after a page refresh
// otherwise.
for (var extensionRpc in isolate.extensionRPCs) {
_streamNotify(
'Isolate',
Event()
..kind = EventKind.kServiceExtensionAdded
..extensionRPC = extensionRpc
..isolate = isolateRef);
}
}

/// Should be called when there is a hot restart or full page refresh.
Expand Down
2 changes: 1 addition & 1 deletion dwds/test/chrome_proxy_service_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void main() {
connection,
assetHandler,
// Provided in the example index.html.
'id-for-testing',
'instance-id-for-testing',
);
});

Expand Down
7 changes: 4 additions & 3 deletions webdev/lib/src/daemon/app_domain.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@ class AppDomain extends Domain {
void _initialize(ServerManager serverManager) async {
var devHandler = serverManager.servers.first.devHandler;
// The connection is established right before `main()` is called.
_appId = await devHandler.connectedApps.first;
var request = await devHandler.connectedApps.first;
_appId = request.appId;
sendEvent('app.start', {
'appId': _appId,
'directory': Directory.current.path,
'deviceId': 'chrome',
'launchMode': 'run'
});
var chrome = await Chrome.connectedInstance;
_debugService =
await devHandler.startDebugService(chrome.chromeConnection, _appId);
_debugService = await devHandler.startDebugService(
chrome.chromeConnection, request.instanceId);
_webdevVmClient = await WebdevVmClient.create(_debugService);
_vmService = _webdevVmClient.client;
sendEvent('app.started', {
Expand Down
6 changes: 3 additions & 3 deletions webdev/lib/src/serve/handlers/dev_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ class DevHandler {
final DevTools _devTools;
final AssetHandler _assetHandler;
final String _hostname;
final _connectedApps = StreamController<String>.broadcast();
final _connectedApps = StreamController<ConnectRequest>.broadcast();
final _servicesByAppId = <String, Future<_AppDebugServices>>{};

Stream<String> get connectedApps => _connectedApps.stream;
Stream<ConnectRequest> get connectedApps => _connectedApps.stream;

DevHandler(Stream<BuildResult> buildResults, this._devTools,
this._assetHandler, this._hostname) {
Expand Down Expand Up @@ -117,7 +117,7 @@ class DevHandler {
.getUrl('json/new/?http://${_devTools.hostname}:${_devTools.port}'
'/?port=${appServices.debugService.port}');
} else if (message is ConnectRequest) {
_connectedApps.add(message.appId);
_connectedApps.add(message);
// After a page refresh, reconnect to the same app services if they
// were previously launched and create the new isolate.
var services = await _servicesByAppId[message.appId];
Expand Down