Skip to content

Commit

Permalink
Sort by status first, then by built time
Browse files Browse the repository at this point in the history
  • Loading branch information
znek committed Jun 14, 2024
1 parent 27145f4 commit d99f12d
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions CCMenu/Source/Menu Bar Extra/MenuBarExtraMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,24 @@ struct MenuBarExtraMenu: View {
case .sortedAlphabetically:
return filtered.sorted(by: { $0.name.lowercased() < $1.name.lowercased() })
case .sortedByBuildTime:
return filtered.sorted(by: { $0.status.lastBuild?.timestamp ?? Date.distantPast >
$1.status.lastBuild?.timestamp ?? Date.distantPast})
return filtered.sorted(by: {p1, p2 in
let r1 = p1.status.lastBuild?.result
let r2 = p2.status.lastBuild?.result
if (r1 != r2) {
if (r1 == nil) {
return false
}
else if (r2 == nil) {
return true
}
let resultOrder = [
BuildResult.failure, BuildResult.success,
BuildResult.unknown, BuildResult.other
]
return resultOrder.firstIndex(of: r1!)! < resultOrder.firstIndex(of: r2!)!
}
return p1.status.lastBuild?.timestamp ?? Date.distantFuture > p2.status.lastBuild?.timestamp ?? Date.distantFuture
})
}
}

Expand Down

0 comments on commit d99f12d

Please sign in to comment.