A coarse approximation of storage management UI

This commit is contained in:
Ali
2022-12-24 20:25:56 +04:00
parent 808f5b80ff
commit d3f078410d
8 changed files with 614 additions and 100 deletions

View File

@@ -91,10 +91,14 @@ public final class AllStorageUsageStats {
}
}
public var deviceAvailableSpace: Int64
public var deviceFreeSpace: Int64
public fileprivate(set) var totalStats: StorageUsageStats
public fileprivate(set) var peers: [EnginePeer.Id: PeerStats]
public init(totalStats: StorageUsageStats, peers: [EnginePeer.Id: PeerStats]) {
public init(deviceAvailableSpace: Int64, deviceFreeSpace: Int64, totalStats: StorageUsageStats, peers: [EnginePeer.Id: PeerStats]) {
self.deviceAvailableSpace = deviceAvailableSpace
self.deviceFreeSpace = deviceFreeSpace
self.totalStats = totalStats
self.peers = peers
}
@@ -242,7 +246,13 @@ func _internal_collectStorageUsageStats(account: Account) -> Signal<AllStorageUs
}
}
let systemAttributes = try? FileManager.default.attributesOfFileSystem(forPath: NSHomeDirectory() as String)
let deviceAvailableSpace = (systemAttributes?[FileAttributeKey.systemSize] as? NSNumber)?.int64Value ?? 0
let deviceFreeSpace = (systemAttributes?[FileAttributeKey.systemFreeSize] as? NSNumber)?.int64Value ?? 0
return AllStorageUsageStats(
deviceAvailableSpace: deviceAvailableSpace,
deviceFreeSpace: deviceFreeSpace,
totalStats: total,
peers: peers
)
@@ -257,7 +267,8 @@ func _internal_renderStorageUsageStatsMessages(account: Account, stats: StorageU
if !categories.contains(category) {
continue
}
for id in value.messages.keys {
for (id, _) in value.messages.sorted(by: { $0.value >= $1.value }).prefix(1000) {
if result[id] == nil {
if let message = existingMessages[id] {
result[id] = message