Commit 34b9ce85 authored by Devon Carew's avatar Devon Carew Committed by GitHub

proxy service extension calls through the daemon protocol (#7554)

* proxy service extension calls through the daemon protocol

* add test for app.callServiceExtension
parent 47de5155
...@@ -22,6 +22,7 @@ import '../ios/simulators.dart'; ...@@ -22,6 +22,7 @@ import '../ios/simulators.dart';
import '../resident_runner.dart'; import '../resident_runner.dart';
import '../run.dart'; import '../run.dart';
import '../runner/flutter_command.dart'; import '../runner/flutter_command.dart';
import '../vmservice.dart';
const String protocolVersion = '0.2.0'; const String protocolVersion = '0.2.0';
...@@ -280,6 +281,7 @@ class AppDomain extends Domain { ...@@ -280,6 +281,7 @@ class AppDomain extends Domain {
AppDomain(Daemon daemon) : super(daemon, 'app') { AppDomain(Daemon daemon) : super(daemon, 'app') {
registerHandler('start', start); registerHandler('start', start);
registerHandler('restart', restart); registerHandler('restart', restart);
registerHandler('callServiceExtension', callServiceExtension);
registerHandler('stop', stop); registerHandler('stop', stop);
registerHandler('discover', discover); registerHandler('discover', discover);
} }
...@@ -435,6 +437,26 @@ class AppDomain extends Domain { ...@@ -435,6 +437,26 @@ class AppDomain extends Domain {
}); });
} }
Future<OperationResult> callServiceExtension(Map<String, dynamic> args) async {
String appId = _getStringArg(args, 'appId', required: true);
String methodName = _getStringArg(args, 'methodName');
Map<String, String> params = args['params'] ?? <String, String>{};
AppInstance app = _getApp(appId);
if (app == null)
throw "app '$appId' not found";
Isolate isolate = app.runner.currentView.uiIsolate;
Map<String, dynamic> result = await isolate.invokeFlutterExtensionRpcRaw(methodName, params: params);
if (result == null)
return new OperationResult(1, 'method not available: $methodName');
if (result.containsKey('error'))
return new OperationResult(1, result['error']);
else
return OperationResult.ok;
}
Future<bool> stop(Map<String, dynamic> args) async { Future<bool> stop(Map<String, dynamic> args) async {
String appId = _getStringArg(args, 'appId', required: true); String appId = _getStringArg(args, 'appId', required: true);
......
...@@ -167,6 +167,33 @@ void main() { ...@@ -167,6 +167,33 @@ void main() {
commands.close(); commands.close();
}); });
_testUsingContext('daemon.callServiceExtension', () async {
DaemonCommand command = new DaemonCommand();
applyMocksToCommand(command);
StreamController<Map<String, dynamic>> commands = new StreamController<Map<String, dynamic>>();
StreamController<Map<String, dynamic>> responses = new StreamController<Map<String, dynamic>>();
daemon = new Daemon(
commands.stream,
(Map<String, dynamic> result) => responses.add(result),
daemonCommand: command,
notifyingLogger: notifyingLogger
);
commands.add(<String, dynamic>{
'id': 0,
'method': 'app.callServiceExtension',
'params': <String, String> {
'methodName': 'ext.flutter.debugPaint'
}
});
Map<String, dynamic> response = await responses.stream.where(_notEvent).first;
expect(response['id'], 0);
expect(response['error'], contains('appId is required'));
responses.close();
commands.close();
});
_testUsingContext('daemon.stop', () async { _testUsingContext('daemon.stop', () async {
DaemonCommand command = new DaemonCommand(); DaemonCommand command = new DaemonCommand();
applyMocksToCommand(command); applyMocksToCommand(command);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment