mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Send asset evictions notices to Flutter framework (#5303)
This commit is contained in:
parent
95f2e981da
commit
9543366eab
@ -27,6 +27,7 @@ class DevFSEntry {
|
||||
|
||||
final String devicePath;
|
||||
final AssetBundleEntry bundleEntry;
|
||||
String get assetPath => bundleEntry.archivePath;
|
||||
|
||||
final File file;
|
||||
FileStat _fileStat;
|
||||
@ -71,6 +72,8 @@ class DevFSEntry {
|
||||
|
||||
bool get _isSourceEntry => file == null;
|
||||
|
||||
bool get _isAssetEntry => bundleEntry != null;
|
||||
|
||||
Future<List<int>> contentsAsBytes() async {
|
||||
if (_isSourceEntry)
|
||||
return bundleEntry.contentsAsBytes();
|
||||
@ -246,6 +249,7 @@ class DevFS {
|
||||
final Map<String, DevFSEntry> _entries = <String, DevFSEntry>{};
|
||||
final Set<DevFSEntry> _dirtyEntries = new Set<DevFSEntry>();
|
||||
final Set<DevFSEntry> _deletedEntries = new Set<DevFSEntry>();
|
||||
final Set<DevFSEntry> dirtyAssetEntries = new Set<DevFSEntry>();
|
||||
|
||||
final List<Future<Response>> _pendingOperations = new List<Future<Response>>();
|
||||
|
||||
@ -276,6 +280,8 @@ class DevFS {
|
||||
_dirtyEntries.clear();
|
||||
// Clear the deleted entries list.
|
||||
_deletedEntries.clear();
|
||||
// Clear the dirty asset entries.
|
||||
dirtyAssetEntries.clear();
|
||||
}
|
||||
|
||||
Future<dynamic> update({ DevFSProgressReporter progressReporter,
|
||||
@ -422,8 +428,11 @@ class DevFS {
|
||||
}
|
||||
bool needsWrite = entry.isModified;
|
||||
if (needsWrite) {
|
||||
if (_dirtyEntries.add(entry))
|
||||
if (_dirtyEntries.add(entry)) {
|
||||
_bytes += entry.size;
|
||||
if (entry._isAssetEntry)
|
||||
dirtyAssetEntries.add(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -272,6 +272,21 @@ class HotRunner extends ResidentRunner {
|
||||
return true;
|
||||
}
|
||||
|
||||
Future<Null> _evictDirtyAssets() async {
|
||||
if (_devFS == null) {
|
||||
return;
|
||||
}
|
||||
if (_devFS.dirtyAssetEntries.length == 0) {
|
||||
return;
|
||||
}
|
||||
if (serviceProtocol.firstIsolateId == null)
|
||||
throw 'Application isolate not found';
|
||||
for (DevFSEntry entry in _devFS.dirtyAssetEntries) {
|
||||
await serviceProtocol.flutterEvictAsset(serviceProtocol.firstIsolateId,
|
||||
entry.assetPath);
|
||||
}
|
||||
}
|
||||
|
||||
Future<Null> _cleanupDevFS() async {
|
||||
if (_devFS != null) {
|
||||
// Cleanup the devFS.
|
||||
@ -384,6 +399,7 @@ class HotRunner extends ResidentRunner {
|
||||
printError('Hot reload failed:\n$errorMessage');
|
||||
return false;
|
||||
}
|
||||
await _evictDirtyAssets();
|
||||
Status reassembleStatus =
|
||||
logger.startProgress('Reassembling application...');
|
||||
try {
|
||||
|
||||
@ -267,6 +267,13 @@ class Observatory {
|
||||
}).then((dynamic result) => new Response(result));
|
||||
}
|
||||
|
||||
Future<Response> flutterEvictAsset(String isolateId, String assetPath) {
|
||||
return peer.sendRequest('ext.flutter.evict', <String, dynamic>{
|
||||
'isolateId': isolateId,
|
||||
'value': assetPath
|
||||
}).then((dynamic result) => new Response(result));
|
||||
}
|
||||
|
||||
Future<Response> flutterExit(String isolateId) {
|
||||
return peer
|
||||
.sendRequest('ext.flutter.exit', <String, dynamic>{ 'isolateId': isolateId })
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user