Skip to content

Commit

Permalink
item show modify date
Browse files Browse the repository at this point in the history
  • Loading branch information
waylybaye committed Sep 1, 2020
1 parent 4bb808f commit 00666fe
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
11 changes: 10 additions & 1 deletion Cleaner4Xcode/MainWindowView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ func ItemRow(
onTrash: @escaping () -> Void
) -> some View {

let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd"

return HStack {
Text(item.displayName)
.font(.subheadline)
Expand All @@ -26,8 +29,14 @@ func ItemRow(
Spacer()

Text(humanize(item.totalSize))
.font(.subheadline)
.padding(.horizontal)

Text(dateFormatter.string(from: item.modifyDate))
.foregroundColor(.secondary)
.font(Font.subheadline.monospacedDigit())
.lineLimit(1)

Button(action: onReveal) {
Image(systemName: "magnifyingglass.circle.fill")
// Image(nsImage: NSImage.init(named: NSImage.revealFreestandingTemplateName)!)
Expand Down Expand Up @@ -77,7 +86,7 @@ struct MainWindowView: View {

var body: some View {
let groups = data.groups.map {$0.0}
let detailWidth: CGFloat = 500
let detailWidth: CGFloat = 550

return NavigationView {
List {
Expand Down
7 changes: 6 additions & 1 deletion DataStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ struct AnalysisItem: Identifiable {
let path: String
let displayName: String
let totalSize: UInt64
let modifyDate: Date
}

enum AppError: Error, Identifiable {
Expand Down Expand Up @@ -277,7 +278,11 @@ class AppData: ObservableObject {
self.objectWillChange.send()

analysis.items.append(
AnalysisItem(path: subDirectory, displayName: display, totalSize: totalSize)
AnalysisItem(
path: subDirectory, displayName: display,
totalSize: totalSize,
modifyDate: (try? fm.getDirectoryUpdateDate(subDirectory)) ?? Date(timeIntervalSince1970: 0)
)
)

analysis.items.sort {
Expand Down
7 changes: 7 additions & 0 deletions FileHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,11 @@ class FileHelper {

return size;
}

func getDirectoryUpdateDate(_ path: String) throws -> Date {
var size: UInt64 = 0

let fileAttrs = try FileManager.default.attributesOfItem(atPath: path)
return fileAttrs[FileAttributeKey.modificationDate] as! Date
}
}

0 comments on commit 00666fe

Please sign in to comment.