Unverified Commit af42e7d7 authored by Lau Ching Jun's avatar Lau Ching Jun Committed by GitHub

Only set assets directory after assets are uploaded onto devfs. (#85418)

parent b0462184
......@@ -480,6 +480,9 @@ class DevFS {
final Directory rootDirectory;
final Set<String> assetPathsToEvict = <String>{};
// A flag to indicate whether we have called `setAssetDirectory` on the target device.
bool hasSetAssetDirectory = false;
List<Uri> sources = <Uri>[];
DateTime lastCompiled;
DateTime _previousCompiled;
......
......@@ -660,6 +660,10 @@ class WebDevFS implements DevFS {
Dwds get dwds => webAssetServer.dwds;
// A flag to indicate whether we have called `setAssetDirectory` on the target device.
@override
bool hasSetAssetDirectory = false;
Future<DebugConnection> _cachedExtensionFuture;
StreamSubscription<void> _connectedApps;
......
......@@ -279,14 +279,6 @@ class HotRunner extends ResidentRunner {
device.generator.accept();
}
final List<FlutterView> views = await device.vmService.getFlutterViews();
final Uri deviceAssetsDirectoryUri = device.devFS.baseUri.resolveUri(globals.fs.path.toUri(getAssetBuildDirectory()));
await Future.wait<void>(views.map<Future<void>>(
(FlutterView view) => device.vmService.setAssetDirectory(
assetsDirectory: deviceAssetsDirectoryUri,
uiIsolateId: view.uiIsolate.id,
viewId: view.id,
)
));
for (final FlutterView view in views) {
globals.printTrace('Connected to $view.');
}
......@@ -896,7 +888,7 @@ class HotRunner extends ResidentRunner {
}
reloadVMTimer.stop();
await _evictDirtyAssets();
await evictDirtyAssets();
final Stopwatch reassembleTimer = _stopwatchFactory.createStopwatch('reloadSources:reassemble')..start();
......@@ -997,13 +989,31 @@ class HotRunner extends ResidentRunner {
printDebuggerList();
}
Future<void> _evictDirtyAssets() async {
@visibleForTesting
Future<void> evictDirtyAssets() async {
final List<Future<Map<String, dynamic>>> futures = <Future<Map<String, dynamic>>>[];
for (final FlutterDevice device in flutterDevices) {
if (device.devFS.assetPathsToEvict.isEmpty) {
continue;
}
final List<FlutterView> views = await device.vmService.getFlutterViews();
// If this is the first time we update the assets, make sure to call the setAssetDirectory
if (!device.devFS.hasSetAssetDirectory) {
final Uri deviceAssetsDirectoryUri = device.devFS.baseUri.resolveUri(globals.fs.path.toUri(getAssetBuildDirectory()));
await Future.wait<void>(views.map<Future<void>>(
(FlutterView view) => device.vmService.setAssetDirectory(
assetsDirectory: deviceAssetsDirectoryUri,
uiIsolateId: view.uiIsolate.id,
viewId: view.id,
)
));
for (final FlutterView view in views) {
globals.printTrace('Set asset directory in $view.');
}
device.devFS.hasSetAssetDirectory = true;
}
if (views.first.uiIsolate == null) {
globals.printError('Application isolate not found for $device');
continue;
......
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