mirror of
https://github.com/XcodesOrg/XcodesApp.git
synced 2026-03-25 08:55:46 +00:00
This adds a new filter option that shows only releases, plus any betas that do not have a release version. So as of today (July 7, 2023 the Xcode 15 betas will be shown but the Xcode 14 betas won't. Note that this will also show betas for older Xcode versions if necessary, for example if an Xcode 14.3.2 beta is released it will be shown until the mainline Xcode 14.3.2 is released.
75 lines
3.1 KiB
Swift
75 lines
3.1 KiB
Swift
import Path
|
|
import SwiftUI
|
|
import Version
|
|
|
|
struct XcodeListView: View {
|
|
@EnvironmentObject var appState: AppState
|
|
@Binding var selectedXcodeID: Xcode.ID?
|
|
private let searchText: String
|
|
private let category: XcodeListCategory
|
|
private let isInstalledOnly: Bool
|
|
|
|
init(selectedXcodeID: Binding<Xcode.ID?>, searchText: String, category: XcodeListCategory, isInstalledOnly: Bool) {
|
|
self._selectedXcodeID = selectedXcodeID
|
|
self.searchText = searchText
|
|
self.category = category
|
|
self.isInstalledOnly = isInstalledOnly
|
|
}
|
|
|
|
var visibleXcodes: [Xcode] {
|
|
var xcodes: [Xcode]
|
|
switch category {
|
|
case .all:
|
|
xcodes = appState.allXcodes
|
|
case .release:
|
|
xcodes = appState.allXcodes.filter { $0.version.isNotPrerelease }
|
|
case .beta:
|
|
xcodes = appState.allXcodes.filter { $0.version.isPrerelease }
|
|
case .releasePlusNewBetas:
|
|
let releases = Set(
|
|
appState.allXcodes
|
|
.filter(\.version.isNotPrerelease)
|
|
.map { $0.version.withoutIdentifiers() }
|
|
)
|
|
xcodes = appState.allXcodes.filter {
|
|
$0.version.isNotPrerelease || !releases.contains($0.version.withoutIdentifiers())
|
|
}
|
|
}
|
|
|
|
if !searchText.isEmpty {
|
|
xcodes = xcodes.filter { $0.description.contains(searchText) }
|
|
}
|
|
|
|
if isInstalledOnly {
|
|
xcodes = xcodes.filter { $0.installState.installed }
|
|
}
|
|
|
|
return xcodes
|
|
}
|
|
|
|
var body: some View {
|
|
List(visibleXcodes, selection: $selectedXcodeID) { xcode in
|
|
XcodeListViewRow(xcode: xcode, selected: selectedXcodeID == xcode.id, appState: appState)
|
|
}
|
|
}
|
|
}
|
|
|
|
struct XcodeListView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
Group {
|
|
XcodeListView(selectedXcodeID: .constant(nil), searchText: "", category: .all, isInstalledOnly: false)
|
|
.environmentObject({ () -> AppState in
|
|
let a = AppState()
|
|
a.allXcodes = [
|
|
Xcode(version: Version("12.0.0+1234A")!, identicalBuilds: [Version("12.0.0+1234A")!, Version("12.0.0-RC+1234A")!], installState: .installed(Path("/Applications/Xcode-12.3.0.app")!), selected: false, icon: nil),
|
|
Xcode(version: Version("12.3.0")!, installState: .installed(Path("/Applications/Xcode-12.3.0.app")!), selected: true, icon: nil),
|
|
Xcode(version: Version("12.2.0")!, installState: .notInstalled, selected: false, icon: nil),
|
|
Xcode(version: Version("12.1.0")!, installState: .installing(.downloading(progress: configure(Progress(totalUnitCount: 100)) { $0.completedUnitCount = 40 })), selected: false, icon: nil),
|
|
Xcode(version: Version("12.0.0")!, installState: .installed(Path("/Applications/Xcode-12.3.0.app")!), selected: false, icon: nil),
|
|
]
|
|
return a
|
|
}())
|
|
}
|
|
.previewLayout(.sizeThatFits)
|
|
}
|
|
}
|