forked from firka/flutter
[flutter_tools] remove runFromSource, move runInView to vm_service extension (#54700)
This commit is contained in:
@@ -457,14 +457,18 @@ class HotRunner extends ResidentRunner {
|
||||
|
||||
Future<void> _launchInView(
|
||||
FlutterDevice device,
|
||||
Uri entryUri,
|
||||
Uri packagesUri,
|
||||
Uri assetsDirectoryUri,
|
||||
) {
|
||||
return Future.wait(<Future<void>>[
|
||||
Uri main,
|
||||
Uri assetsDirectory,
|
||||
) async {
|
||||
await Future.wait(<Future<void>>[
|
||||
for (final FlutterView view in device.views)
|
||||
view.runFromSource(entryUri, assetsDirectoryUri),
|
||||
device.vmService.runInView(
|
||||
viewId: view.id,
|
||||
main: main,
|
||||
assetsDirectory: assetsDirectory,
|
||||
),
|
||||
]);
|
||||
await device.refreshViews();
|
||||
}
|
||||
|
||||
Future<void> _launchFromDevFS(String mainScript) async {
|
||||
@@ -473,12 +477,10 @@ class HotRunner extends ResidentRunner {
|
||||
for (final FlutterDevice device in flutterDevices) {
|
||||
final Uri deviceEntryUri = device.devFS.baseUri.resolveUri(
|
||||
globals.fs.path.toUri(entryUri));
|
||||
final Uri devicePackagesUri = device.devFS.baseUri.resolve('.packages');
|
||||
final Uri deviceAssetsDirectoryUri = device.devFS.baseUri.resolveUri(
|
||||
globals.fs.path.toUri(getAssetBuildDirectory()));
|
||||
futures.add(_launchInView(device,
|
||||
deviceEntryUri,
|
||||
devicePackagesUri,
|
||||
deviceAssetsDirectoryUri));
|
||||
}
|
||||
await Future.wait(futures);
|
||||
|
||||
@@ -20,6 +20,7 @@ import 'version.dart';
|
||||
const String kGetSkSLsMethod = '_flutter.getSkSLs';
|
||||
const String kSetAssetBundlePathMethod = '_flutter.setAssetBundlePath';
|
||||
const String kFlushUIThreadTasksMethod = '_flutter.flushUIThreadTasks';
|
||||
const String kRunInViewMethod = '_flutter.runInView';
|
||||
|
||||
/// Override `WebSocketConnector` in [context] to use a different constructor
|
||||
/// for [WebSocket]s (used by tests).
|
||||
@@ -1091,19 +1092,6 @@ class VM extends ServiceObjectOwner {
|
||||
return invokeRpcRaw('_deleteDevFS', params: <String, dynamic>{'fsName': fsName});
|
||||
}
|
||||
|
||||
Future<ServiceMap> runInView(
|
||||
String viewId,
|
||||
Uri main,
|
||||
Uri assetsDirectory,
|
||||
) {
|
||||
return invokeRpc<ServiceMap>('_flutter.runInView',
|
||||
params: <String, dynamic>{
|
||||
'viewId': viewId,
|
||||
'mainScript': main.toString(),
|
||||
'assetDirectory': assetsDirectory.toString(),
|
||||
});
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> clearVMTimeline() {
|
||||
return invokeRpcRaw('clearVMTimeline');
|
||||
}
|
||||
@@ -1541,36 +1529,6 @@ class FlutterView extends ServiceObject {
|
||||
_uiIsolate = map['isolate'] as Isolate;
|
||||
}
|
||||
|
||||
// TODO(johnmccutchan): Report errors when running failed.
|
||||
Future<void> runFromSource(
|
||||
Uri entryUri,
|
||||
Uri assetsDirectoryUri,
|
||||
) async {
|
||||
final String viewId = id;
|
||||
// When this completer completes the isolate is running.
|
||||
final Completer<void> completer = Completer<void>();
|
||||
try {
|
||||
await owner.vm.vmService.streamListen('Isolate');
|
||||
} on vm_service.RPCError {
|
||||
// Do nothing, since the tool is already subscribed.
|
||||
}
|
||||
final StreamSubscription<vm_service.Event> subscription =
|
||||
owner.vm.vmService.onIsolateEvent.listen((vm_service.Event event) {
|
||||
if (event.kind == ServiceEvent.kIsolateRunnable) {
|
||||
globals.printTrace('Isolate is runnable.');
|
||||
if (!completer.isCompleted) {
|
||||
completer.complete();
|
||||
}
|
||||
}
|
||||
});
|
||||
await owner.vm.runInView(viewId,
|
||||
entryUri,
|
||||
assetsDirectoryUri);
|
||||
await completer.future;
|
||||
await owner.vm.refreshViews(waitForViews: true);
|
||||
await subscription.cancel();
|
||||
}
|
||||
|
||||
bool get hasIsolate => _uiIsolate != null;
|
||||
|
||||
@override
|
||||
@@ -1579,6 +1537,7 @@ class FlutterView extends ServiceObject {
|
||||
|
||||
/// Flutter specific VM Service functionality.
|
||||
extension FlutterVmService on vm_service.VmService {
|
||||
|
||||
/// Set the asset directory for the an attached Flutter view.
|
||||
Future<void> setAssetDirectory({
|
||||
@required Uri assetsDirectory,
|
||||
@@ -1623,4 +1582,33 @@ extension FlutterVmService on vm_service.VmService {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// Launch the Dart isolate with entrypoint [main] in the Flutter engine [viewId]
|
||||
/// with [assetsDirectory] as the devFS.
|
||||
///
|
||||
/// This method is used by the tool to hot restart an already running Flutter
|
||||
/// engine.
|
||||
Future<void> runInView({
|
||||
@required String viewId,
|
||||
@required Uri main,
|
||||
@required Uri assetsDirectory,
|
||||
}) async {
|
||||
try {
|
||||
await streamListen('Isolate');
|
||||
} on vm_service.RPCError {
|
||||
// Do nothing, since the tool is already subscribed.
|
||||
}
|
||||
final Future<void> onRunnable = onIsolateEvent.firstWhere((vm_service.Event event) {
|
||||
return event.kind == vm_service.EventKind.kIsolateRunnable;
|
||||
});
|
||||
await callMethod(
|
||||
kRunInViewMethod,
|
||||
args: <String, Object>{
|
||||
'viewId': viewId,
|
||||
'mainScript': main.toString(),
|
||||
'assetDirectory': assetsDirectory.toString(),
|
||||
},
|
||||
);
|
||||
await onRunnable;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user