SPB Git

Repository Public License

TrashView.swift 3.6 KB 61 lines swift

1// ORIX Clean — App/Sources/Features/Trash/TrashView.swift2// Description: Trash inventory per volume and permanent deletion with explicit confirmation.3// Author: Simon-Pierre Boucher — contact@spboucher.ai4import ORIXCleanCore5import SwiftUI67struct TrashView: View {8    @Environment(AppModel.self) private var model910    var body: some View {11        let all = model.trash.flatMap(\.items)12        VStack(spacing: 0) {13            HStack(alignment: .top, spacing: ORIX.Space.m) {14                SectionTitle(title: L("Trash"), subtitle: L("Items in the Trash still occupy disk space. Emptying is permanent: afterwards they can only come back from a backup."))15                Spacer()16                if model.trashPhase == .running { ProgressView().controlSize(.small) }17                VStack(alignment: .trailing, spacing: 2) {18                    Text(ByteFormat.string(model.trash.reduce(0) { $0 + $1.allocated })).font(.title3.weight(.semibold).monospacedDigit())19                    Text(L("%@ items", ByteFormat.count(all.count))).font(.caption).foregroundStyle(ORIX.Palette.textSecondary)20                }21                Button { model.loadTrash(force: true) } label: { Image(systemName: "arrow.clockwise") }.accessibilityLabel(L("Measure again"))22                Button(L("Empty Trash…")) { model.reviewEmptyTrash(all) }.disabled(all.isEmpty).accessibilityIdentifier("trash.empty")23            }24            .padding(ORIX.Space.l)25            Divider()26            if model.trash.contains(where: { !$0.accessible }) {27                InfoBanner(symbol: "lock", text: L("macOS did not allow reading the Trash. Grant Full Disk Access to ORIX Clean to see its content, or empty it from Finder."),28                           actionTitle: L("Open Settings")) { NSWorkspace.shared.open(Permissions.fullDiskAccessSettingsURL) }.padding(ORIX.Space.m)29            }30            if all.isEmpty, model.trashPhase == .done {31                EmptyState(symbol: "trash", title: model.trash.contains { !$0.accessible } ? L("Trash content unknown") : L("The Trash is empty"),32                           message: L("Items you clean with ORIX Clean arrive here first, so you can put them back."))33            } else {34                List {35                    ForEach(model.trash.filter { !$0.items.isEmpty }) { loc in36                        Section("\(loc.volumeName) · \(ByteFormat.string(loc.allocated)) · " + L("%@ files", ByteFormat.count(loc.fileCount))) {37                            ForEach(loc.items) { item in38                                HStack(spacing: ORIX.Space.s) {39                                    FileIcon(path: item.path, size: 22)40                                    Text(item.name).lineLimit(1).truncationMode(.middle)41                                    Spacer()42                                    if let d = item.measurement.modified { Text(ByteFormat.date(d)).font(.caption).foregroundStyle(ORIX.Palette.textSecondary) }43                                    SizeText(bytes: item.measurement.allocated).frame(width: 100, alignment: .trailing)44                                }45                                .contextMenu {46                                    FileMenu(path: item.path)47                                    Button(L("Delete Permanently…")) { model.reviewEmptyTrash([item]) }48                                }49                                .accessibilityElement(children: .combine)50                            }51                        }52                    }53                }54                .listStyle(.inset)55                .accessibilityIdentifier("trash.list")56            }57        }58        .onAppear { model.loadTrash(force: true) }59    }60}61
Files main
Menu

Theme