Repository Public License
1// ORIX Secure2// File: App/Sources/Features/Storage/StorageView.swift3// Description: Storage overview: the volume's measured capacity, ORIX Secure's own files with verified cleanup, entry points to4// photo and file cleanup, and the breakdowns iOS does not give to apps.5//6// Author: Simon-Pierre Boucher7// Contact: contact@spboucher.ai8import ORIXDesign9import ORIXSecureEngines10import ORIXSecureModel11import SwiftUI1213struct StorageView: View {14 @Environment(AppModel.self) private var model15 @Environment(\.horizontalSizeClass) private var sizeClass16 @State private var confirmClear = false17 @State private var cleanupResult: OwnedCleanupResult?18 @State private var saved = false1920 var body: some View {21 let overview = model.storage22 let volume = overview.volume23 ScreenScroll {24 VStack(alignment: .leading, spacing: ORIX.Space.md) {25 if let total = volume.total.value, let free = volume.bestAvailable.value {26 HStack(alignment: .firstTextBaseline) {27 Text(verbatim: ORIXFormat.bytes(free)).font(.system(.largeTitle, design: .rounded, weight: .bold)).foregroundStyle(ORIX.Palette.textPrimary)28 Text("available").font(.orixCallout).foregroundStyle(ORIX.Palette.textSecondary)29 }30 ORIXProgressBar(value: volume.usedFraction ?? 0)31 Text("\(ORIXFormat.bytes(total - free)) used of \(ORIXFormat.bytes(total))").font(.orixCallout).foregroundStyle(ORIX.Palette.textSecondary)32 } else {33 Text("Capacity not available").font(.orixHeadline)34 Text(verbatim: volume.total.unavailability?.detail ?? "").font(.orixCaption).foregroundStyle(ORIX.Palette.textSecondary)35 }36 Divider()37 ReadingRow(label: String(localized: "Capacity"), value: volume.total.map { ORIXFormat.bytes($0) })38 ReadingRow(label: String(localized: "Available for what you ask for"), value: volume.availableForImportantUsage.map { ORIXFormat.bytes($0) },39 note: String(localized: "Includes space iOS can reclaim from caches. This is the closest figure to the one in Settings."))40 ReadingRow(label: String(localized: "Free on the file system right now"), value: volume.available.map { ORIXFormat.bytes($0) })41 }42 .orixCard()43 .accessibilityElement(children: .combine)44 .accessibilityIdentifier("storage.volume")45 FindingList(findings: overview.findings)46 ORIXSectionHeader("Cleanup you control")47 NavigationTile(destination: .photoCleanup, detail: String(localized: "Duplicates, similar photos, screenshots, large videos"))48 NavigationTile(destination: .fileCleanup, detail: String(localized: "Duplicates and large files in a folder you choose"))49 ORIXSectionHeader("ORIX Secure's own files")50 VStack(spacing: 0) {51 ForEach(Array(overview.owned.enumerated()), id: \.element.id) { index, entry in52 ReadingRow(label: entry.kind.title, value: .measured(ORIXFormat.bytes(entry.bytes)), note: entry.kind.clearingEffect)53 if index < overview.owned.count - 1 { Divider() }54 }55 }56 .orixCard(padding: ORIX.Space.sm)57 Button { confirmClear = true } label: { Label("Clear Caches and Temporary Files (\(ORIXFormat.bytes(overview.clearableBytes)))", systemImage: "trash") }58 .buttonStyle(.orixSecondary)59 .disabled(overview.clearableBytes == 0)60 .accessibilityIdentifier("storage.clearOwned")61 if let cleanupResult {62 ORIXBanner(cleanupResult.errors.isEmpty ? .success : .warning,63 title: Text("\(ORIXFormat.bytes(cleanupResult.freedBytes)) freed, \(cleanupResult.filesRemoved) file(s) removed"),64 message: Text(cleanupResult.errors.isEmpty ? String(localized: "Measured before and after the deletion.") : cleanupResult.errors.joined(separator: "\n")))65 .accessibilityIdentifier("storage.cleared")66 }67 LimitsCard(title: "What iOS does not tell apps about storage", items: overview.notExposed.map { "\($0.title) — \($0.reason) \($0.whereToLook ?? "")" } + [68 String(localized: "An app cannot delete another app's cache or “System Data”. Apps that claim to clean them are not doing it."),69 ])70 }71 .navigationTitle("Storage")72 .toolbar {73 ToolbarItemGroup(placement: .topBarTrailing) {74 Button { saved = model.store.save(ReportBuilder.storage(model.storage)); ORIXHaptics.success() } label: {75 Label("Save Report", systemImage: saved ? "checkmark" : "square.and.arrow.down")76 }77 .accessibilityIdentifier("storage.save")78 Button { model.refresh(); saved = false } label: { Label("Refresh", systemImage: "arrow.clockwise") }79 }80 }81 .confirmationDialog("Clear caches and temporary files?", isPresented: $confirmClear, titleVisibility: .visible) {82 Button("Clear \(ORIXFormat.bytes(overview.clearableBytes))", role: .destructive) {83 cleanupResult = model.storageEngine.clear([.caches, .temporary, .exports])84 model.refresh()85 ORIXHaptics.success()86 }87 } message: { Text("Only ORIX Secure's own caches, working files and export copies. Your reports and answers are kept.") }88 .accessibilityIdentifier("storage")89 }90}91