Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -279,5 +279,5 @@ jobs:
echo "| SHA-256 DMG | \`${DMG_SHA256}\` |"
echo "| SHA-256 ZIP | \`${ZIP_SHA256}\` |"
echo "| Архитектуры | arm64 + x86_64 |"
echo "| Тесты | 150 XCTest |"
echo "| Тесты | 153 XCTest |"
} >> "$GITHUB_STEP_SUMMARY"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ Headless-сканер для бенчмарков:

## Тесты

150 тестов: сравнение суммы скана с `du`, агрегация мелких файлов, пакеты,
153 теста: сравнение суммы скана с `du`, агрегация мелких файлов, пакеты,
симлинки, Unicode-имена, отказ доступа, отмена, copy-on-write удаление,
свойства squarified-раскладки, вложенные ячейки, полный цикл `AppModel`
(скан → навигация → фильтры), даты создания и изменения, правила очистки,
Expand Down
2 changes: 1 addition & 1 deletion ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
| 2.0 — Платформа | 6/6: локализация, notarization/Sparkle/Homebrew, CLI, App Intents, доступность, меню-бар |
| Backlog | 5/5: кэш, параллельный скан, бюджеты, старые файлы, APFS-клоны |

Текущая база: **150 XCTest**, 17,9 тыс. строк исходников, 398 ключей
Текущая база: **153 XCTest**, 17,9 тыс. строк исходников, 398 ключей
локализации, `main` зелёный.

## Принципы
Expand Down
94 changes: 11 additions & 83 deletions Sources/DiskScopeKit/App/AppModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ public final class AppModel: ObservableObject {
}
}

@Published public private(set) var volumes: [VolumeInfo] = VolumeInfo.loadAll()
@Published public private(set) var fileCount = 0
@Published public private(set) var folderCount = 0
@Published public private(set) var largestItems: [ItemRow] = []
@Published public private(set) var categoryStats: [CategoryStat] = []
@Published public internal(set) var volumes: [VolumeInfo] = VolumeInfo.loadAll()
@Published public internal(set) var fileCount = 0
@Published public internal(set) var folderCount = 0
@Published public internal(set) var largestItems: [ItemRow] = []
@Published public internal(set) var categoryStats: [CategoryStat] = []
@Published public private(set) var media = MediaModel()

@Published public var toast: Toast?
Expand All @@ -106,6 +106,7 @@ public final class AppModel: ObservableObject {
@Published public internal(set) var similar = SimilarModel()
@Published public internal(set) var inspector = InspectorModel()
@Published public internal(set) var report = ReportModel()
@Published public internal(set) var preview = PreviewModel()
@Published public var showInspector = false

@Published public internal(set) var budget = BudgetModel()
Expand Down Expand Up @@ -204,6 +205,10 @@ public final class AppModel: ObservableObject {
self?.objectWillChange.send()
}.store(in: &cancellables)
media.attach(appModel: self)
preview.attach(appModel: self)
preview.objectWillChange.sink { [weak self] _ in
self?.objectWillChange.send()
}.store(in: &cancellables)
}

// MARK: - Scan compatibility
Expand Down Expand Up @@ -663,10 +668,9 @@ public final class AppModel: ObservableObject {
)
}

private func resetTrashUndo() {
func resetTrashUndo() {
trash.reset()
}

// MARK: - Cleanup

public func requestCleanup() {
Expand Down Expand Up @@ -827,82 +831,6 @@ public final class AppModel: ObservableObject {
toastWorkItem?.cancel()
toast = nil
}

// MARK: - Previews / snapshots

public func loadPreview(tree: ScanTree) {
scan.invalidate()
scan.finish(tree)
currentIndex = 0
tab = .map
selection = []
resetTrashUndo()
resetCleanup()
resetCollection()
search.reset()
resetDuplicates()
resetSimilar()
fileCount = tree.totalFiles
folderCount = tree.directoryCount()
volumes = VolumeInfo.loadAll()
rebuildCurrentRows()
largestItems = tree.largestItems(limit: 4000).map {
ItemRowFactory.make(tree: tree, index: $0, parentSize: max(tree.totalSize, 1), includePaths: true)
}
categoryStats = tree.categoryStats()
}

/// Fills cleanup state without running the advisor; used by snapshots.
public func previewCleanup(suggestions: [CleanupSuggestion]) {
cleanup.preview(suggestions)
}

/// Fills similar-image groups without running Vision; used by snapshots.
public func previewSimilar(_ groups: [SimilarImageGroup]) {
similar.preview(groups)
}

/// Fills duplicate groups without hashing files; used by snapshots.
public func previewDuplicates(_ groups: [DuplicateGroup]) {
duplicates.preview(groups)
}

/// Fills disk overview state without scanning the real Trash; used by snapshots.
public func previewDiskOverview(_ overview: DiskOverview) {
disk.preview(overview)
}

public func previewScanning(path: String, progress: ScanProgress) {
scan.previewScanning(path: path, progress: progress)
currentIndex = 0
resetTrashUndo()
resetCleanup()
resetCollection()
search.reset()
resetDuplicates()
resetSimilar()
volumes = VolumeInfo.loadAll()
}

public func previewWelcome() {
scan.previewWelcome()
currentIndex = 0
resetTrashUndo()
resetCleanup()
resetCollection()
search.reset()
resetDuplicates()
resetSimilar()
volumes = VolumeInfo.loadAll()
}

public func previewSelect(index: Int32) {
selection = [index]
}

public func previewNavigate(to index: Int32) {
navigate(to: index)
}
}

/// Keeps aggregate folders readable in tables and treemaps.
Expand Down
92 changes: 92 additions & 0 deletions Sources/DiskScopeKit/App/PreviewModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import Combine
import Foundation

/// Fills app state for snapshots and previews without running real scans.
@MainActor
public final class PreviewModel: ObservableObject {
weak var appModel: AppModel?

public init() {}

func attach(appModel: AppModel) {
self.appModel = appModel
}

/// Loads a fully scanned tree as preview state.
public func load(tree: ScanTree) {
guard let model = appModel else { return }
model.scan.invalidate()
model.scan.finish(tree)
model.currentIndex = 0
model.tab = .map
model.selection = []
model.resetTrashUndo()
model.resetCleanup()
model.resetCollection()
model.search.reset()
model.resetDuplicates()
model.resetSimilar()
model.fileCount = tree.totalFiles
model.folderCount = tree.directoryCount()
model.volumes = VolumeInfo.loadAll()
model.rebuildCurrentRows()
model.largestItems = tree.largestItems(limit: 4000).map {
ItemRowFactory.make(tree: tree, index: $0, parentSize: max(tree.totalSize, 1), includePaths: true)
}
model.categoryStats = tree.categoryStats()
}

/// Fills cleanup state without running the advisor; used by snapshots.
public func cleanup(_ suggestions: [CleanupSuggestion]) {
appModel?.cleanup.preview(suggestions)
}

/// Fills similar-image groups without running Vision; used by snapshots.
public func similar(_ groups: [SimilarImageGroup]) {
appModel?.similar.preview(groups)
}

/// Fills duplicate groups without hashing files; used by snapshots.
public func duplicates(_ groups: [DuplicateGroup]) {
appModel?.duplicates.preview(groups)
}

/// Fills disk overview state without scanning the real Trash; used by snapshots.
public func diskOverview(_ overview: DiskOverview) {
appModel?.disk.preview(overview)
}

public func scanning(path: String, progress: ScanProgress) {
guard let model = appModel else { return }
model.scan.previewScanning(path: path, progress: progress)
model.currentIndex = 0
model.resetTrashUndo()
model.resetCleanup()
model.resetCollection()
model.search.reset()
model.resetDuplicates()
model.resetSimilar()
model.volumes = VolumeInfo.loadAll()
}

public func welcome() {
guard let model = appModel else { return }
model.scan.previewWelcome()
model.currentIndex = 0
model.resetTrashUndo()
model.resetCleanup()
model.resetCollection()
model.search.reset()
model.resetDuplicates()
model.resetSimilar()
model.volumes = VolumeInfo.loadAll()
}

public func select(index: Int32) {
appModel?.selection = [index]
}

public func navigate(to index: Int32) {
appModel?.navigate(to: index)
}
}
16 changes: 8 additions & 8 deletions Sources/DiskScopeSnapshots/SnapshotsMain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@
RunLoop.current.run(until: Date().addingTimeInterval(0.4))
}

func renderAll(tree: ScanTree) {

Check warning on line 55 in Sources/DiskScopeSnapshots/SnapshotsMain.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Function body should span 200 lines or less excluding comments and whitespace: currently spans 260 lines (function_body_length)
let model = AppModel()

model.loadPreview(tree: tree)
model.preview.load(tree: tree)
model.tab = .map
render(model: model, named: "01-map-light", dark: false)
render(model: model, named: "02-map-dark", dark: true)
Expand All @@ -70,7 +70,7 @@
let deepFolder = findNode(in: tree, components: ["Xcode.app", "Contents", "Developer", "Platforms"])
?? firstPlausibleFolder(in: tree)
if let deepFolder {
model.previewNavigate(to: deepFolder)
model.preview.navigate(to: deepFolder)
render(model: model, named: "05-map-folder", dark: false)
}

Expand Down Expand Up @@ -200,7 +200,7 @@
selected: false
),
]
model.previewCleanup(suggestions: cleanup)
model.preview.cleanup(cleanup)
model.tab = .cleanup
render(model: model, named: "14-cleanup-light", dark: false)
render(model: model, named: "15-cleanup-dark", dark: true)
Expand Down Expand Up @@ -249,7 +249,7 @@
],
updatedAt: Date()
)
model.previewDiskOverview(diskOverview)
model.preview.diskOverview(diskOverview)
model.tab = .disk
render(model: model, named: "17-disk-light", dark: false)
render(model: model, named: "17-disk-dark", dark: true)
Expand All @@ -274,7 +274,7 @@
modified: nil
)
}
model.previewDuplicates([
model.preview.duplicates([
DuplicateGroup(id: "preview-documents", size: 2_400_000_000, files: firstFiles),
DuplicateGroup(id: "preview-videos", size: 4_800_000_000, files: secondFiles),
])
Expand All @@ -299,19 +299,19 @@
modified: nil
)
}
model.previewSimilar([
model.preview.similar([
SimilarImageGroup(id: "preview-similar", images: similarFiles),
])
model.tab = .similar
render(model: model, named: "19-similar-light", dark: false)
render(model: model, named: "19-similar-dark", dark: true)
model.tab = .map

model.previewWelcome()
model.preview.welcome()
render(model: model, named: "06-welcome", dark: false)
render(model: model, named: "07-welcome-dark", dark: true)

model.previewScanning(
model.preview.scanning(
path: model.homePath + "/Library/Application Support",
progress: ScanProgress(
entries: 2_148_932,
Expand Down
Loading
Loading