-
Notifications
You must be signed in to change notification settings - Fork 82
Daemon App Domain #206
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
Daemon App Domain #206
Changes from all commits
09a49e7
7221637
71225fe
a0c2d48
ed5908a
c3776e0
3635b89
c1c1c42
0369df8
3927058
a7ea72e
6e4183b
a46c5fd
72c9513
53e69f5
9894bf5
b144c51
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file | ||
// 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:io'; | ||
|
||
import 'package:dwds/service.dart'; | ||
import 'package:uuid/uuid.dart'; | ||
import 'package:webdev/src/serve/chrome.dart'; | ||
import 'package:webdev/src/serve/server_manager.dart'; | ||
|
||
import '../serve/debugger/webdev_vm_client.dart'; | ||
import 'daemon.dart'; | ||
import 'domain.dart'; | ||
import 'utilites.dart'; | ||
|
||
/// A collection of method and events relevant to the running application. | ||
class AppDomain extends Domain { | ||
final String _appId; | ||
|
||
WebdevVmClient _webdevVmClient; | ||
DebugService _debugService; | ||
bool _isShutdown = false; | ||
|
||
AppDomain(Daemon daemon, Future<ServerManager> futureServerManager) | ||
: _appId = Uuid().v1() as String, | ||
super(daemon, 'app') { | ||
registerHandler('restart', _restart); | ||
registerHandler('callServiceExtension', _callServiceExtension); | ||
registerHandler('stop', _stop); | ||
|
||
futureServerManager.then((serverManager) async { | ||
if (_isShutdown) return; | ||
sendEvent('app.start', { | ||
'appId': _appId, | ||
'directory': Directory.current.path, | ||
'deviceId': 'chrome', | ||
'launchMode': 'run' | ||
}); | ||
|
||
// TODO(https://github.com/dart-lang/webdev/issues/202) - Embed the appID | ||
// in the WebServer. | ||
var server = serverManager.servers.firstWhere((s) => s.target == 'web'); | ||
var devHandler = server.devHandler; | ||
await devHandler.connections.next; | ||
// TODO(https://github.com/dart-lang/webdev/issues/202) - Remove. | ||
await Future.delayed(Duration(seconds: 2)); | ||
|
||
var chrome = await Chrome.connectedInstance; | ||
// TODO(https://github.com/dart-lang/webdev/issues/202) - Run an eval to | ||
// get the appId. | ||
var appUrl = (await chrome.chromeConnection.getTabs()) | ||
.firstWhere( | ||
(tab) => tab.url.startsWith('http://localhost:${server.port}')) | ||
.url; | ||
|
||
sendEvent('daemon.logMessage', | ||
{'level': 'info', 'message': 'Connecting to $appUrl'}); | ||
|
||
_debugService = await server.devHandler | ||
.startDebugService(chrome.chromeConnection, appUrl); | ||
_webdevVmClient = await WebdevVmClient.create(_debugService); | ||
|
||
sendEvent('app.debugPort', { | ||
'appId': _appId, | ||
'port': _debugService.port, | ||
'wsUri': _debugService.wsUri, | ||
}); | ||
|
||
// Shutdown could have been triggered while awaiting above. | ||
// ignore: invariant_booleans | ||
if (_isShutdown) dispose(); | ||
|
||
// TODO(grouma) - Add an event for when the application is started. | ||
}); | ||
} | ||
|
||
Future<String> _callServiceExtension(Map<String, dynamic> args) { | ||
throw UnimplementedError(); | ||
} | ||
|
||
Future<String> _restart(Map<String, dynamic> args) async { | ||
throw UnimplementedError(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you could implement this as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gonna wait for a follow up PR as I'd like to add some tests. |
||
} | ||
|
||
Future<bool> _stop(Map<String, dynamic> args) async { | ||
var appId = getStringArg(args, 'appId', required: true); | ||
if (_appId != appId) throw ArgumentError("app '$appId' not found"); | ||
var chrome = await Chrome.connectedInstance; | ||
await chrome.close(); | ||
return true; | ||
} | ||
|
||
@override | ||
void dispose() { | ||
_isShutdown = true; | ||
_debugService?.close(); | ||
_webdevVmClient?.close(); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.