fix how platforms are architecture filtered

This commit is contained in:
Matt Kiazyk 2025-09-17 22:37:19 -05:00
parent 6cf9647840
commit fc50db1cee
5 changed files with 50 additions and 6 deletions

View file

@ -11,7 +11,7 @@ import XcodesKit
struct PlatformsView: View {
@EnvironmentObject var appState: AppState
@AppStorage("selectedRuntimeArchitecture") private var selectedRuntimeArchitecture: Architecture = .arm64
@AppStorage("selectedRuntimeArchitecture") private var selectedVariant: ArchitectureVariant = .universal
let xcode: Xcode
@ -22,7 +22,9 @@ struct PlatformsView: View {
appState.downloadableRuntimes.filter {
$0.sdkBuildUpdate?.contains(sdkBuild) ?? false &&
($0.architectures?.isEmpty ?? true ||
$0.architectures?.contains(selectedRuntimeArchitecture) ?? false)
($0.architectures?.isUniversal ?? false && selectedVariant == .universal) ||
($0.architectures?.isAppleSilicon ?? false && selectedVariant == .appleSilicon)
)
}
}
@ -35,8 +37,8 @@ struct PlatformsView: View {
.frame(maxWidth: .infinity, alignment: .leading)
if !architectures.isEmpty {
Spacer()
Picker("Architecture", selection: $selectedRuntimeArchitecture) {
ForEach(Architecture.allCases, id: \.self) { arch in
Picker("Architecture", selection: $selectedVariant) {
ForEach(ArchitectureVariant.allCases, id: \.self) { arch in
Label(arch.displayString, systemImage: arch.iconName)
.tag(arch)
}
@ -73,6 +75,7 @@ struct PlatformsView: View {
ForEach(runtime.architectures ?? [], id: \.self) { architecture in
TagView(text: architecture.displayString)
}
pathIfAvailable(xcode: xcode, runtime: runtime)
if runtime.installState == .notInstalled {

View file

@ -1,4 +1,4 @@
{\rtf1\ansi\ansicpg1252\cocoartf2822
{\rtf1\ansi\ansicpg1252\cocoartf2865
\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fnil\fcharset0 .SFNS-Regular;}
{\colortbl;\red255\green255\blue255;}
{\*\expandedcolortbl;;}

View file

@ -4819,6 +4819,9 @@
}
}
}
},
"Architecture" : {
},
"Authenticating" : {
"extractionState" : "manual",
@ -5683,6 +5686,9 @@
}
}
}
},
"Category" : {
},
"Change" : {
"localizations" : {
@ -9239,6 +9245,9 @@
}
}
}
},
"FilterArchitecturesDescription" : {
},
"FilterAvailableDescription" : {
"localizations" : {
@ -13462,6 +13471,9 @@
}
}
}
},
"Installed Only" : {
},
"InstallHelper" : {
"localizations" : {

View file

@ -5,7 +5,7 @@ import PackageDescription
let package = Package(
name: "XcodesKit",
platforms: [.macOS(.v11)],
platforms: [.macOS(.v13)],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(

View file

@ -35,8 +35,37 @@ public enum Architecture: String, Codable, Equatable, Hashable, Identifiable, Ca
}
}
public enum ArchitectureVariant: String, Codable, Equatable, Hashable, Identifiable, CaseIterable {
public var id: Self { self }
case universal
case appleSilicon
public var displayString: String {
switch self {
case .appleSilicon:
return "Apple Silicon"
case .universal:
return "Universal"
}
}
public var iconName: String {
switch self {
case .appleSilicon:
return "m4.button.horizontal"
case .universal:
return "cpu.fill"
}
}
}
extension Array where Element == Architecture {
public var isAppleSilicon: Bool {
self == [.arm64]
}
public var isUniversal: Bool {
self.contains([.arm64, .x86_64])
}
}