Skip to content

Commit

Permalink
Merge pull request #632 from abiligiri/feature/more_managed_preferences
Browse files Browse the repository at this point in the history
Restrict allowed versions & hide 'Support Xcodes'
  • Loading branch information
MattKiazyk authored Oct 29, 2024
2 parents dd9a348 + e3f996d commit a75c54f
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 12 deletions.
2 changes: 2 additions & 0 deletions Xcodes/Backend/AppState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ enum PreferenceKey: String {
case downloader
case dataSource
case xcodeListCategory
case allowedMajorVersions
case hideSupportXcodes

func isManaged() -> Bool { UserDefaults.standard.objectIsForced(forKey: self.rawValue) }
}
Expand Down
52 changes: 41 additions & 11 deletions Xcodes/Frontend/XcodeList/BottomStatusBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import SwiftUI

struct BottomStatusModifier: ViewModifier {
@EnvironmentObject var appState: AppState
@AppStorage(PreferenceKey.hideSupportXcodes.rawValue) var hideSupportXcodes = false

@SwiftUI.Environment(\.openURL) var openURL: OpenURLAction

func body(content: Content) -> some View {
Expand All @@ -20,17 +22,19 @@ struct BottomStatusModifier: ViewModifier {
Divider()
HStack {
Text(appState.bottomStatusBarMessage)
.font(.subheadline)
.font(.subheadline)
Spacer()
Button(action: {
openURL(URL(string: "https://opencollective.com/xcodesapp")!)
}) {
HStack {
Image(systemName: "heart.circle")
Text("Support.Xcodes")
if !hideSupportXcodes {
Button(action: {
openURL(URL(string: "https://opencollective.com/xcodesapp")!)
}) {
HStack {
Image(systemName: "heart.circle")
Text("Support.Xcodes")
}
}
}
Text(Bundle.main.shortVersion!)
Text("\(Bundle.main.shortVersion!) (\(Bundle.main.version!))")
.font(.subheadline)
}
.frame(maxWidth: .infinity, maxHeight: 30, alignment: .leading)
Expand All @@ -51,8 +55,34 @@ extension View {

struct Previews_BottomStatusBar_Previews: PreviewProvider {
static var previews: some View {
HStack {

}.bottomStatusBar()
Group {
HStack {

}
.bottomStatusBar()
.environmentObject({ () -> AppState in
let a = AppState()
return a }()
)
.defaultAppStorage({ () -> UserDefaults in
let d = UserDefaults(suiteName: "hide_support")!
d.set(true, forKey: PreferenceKey.hideSupportXcodes.rawValue)
return d
}())

HStack {

}
.bottomStatusBar()
.environmentObject({ () -> AppState in
let a = AppState()
return a }()
)
.defaultAppStorage({ () -> UserDefaults in
let d = UserDefaults(suiteName: "show_support")!
d.set(false, forKey: PreferenceKey.hideSupportXcodes.rawValue)
return d
}())
}
}
}
22 changes: 21 additions & 1 deletion Xcodes/Frontend/XcodeList/XcodeListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ struct XcodeListView: View {
private let searchText: String
private let category: XcodeListCategory
private let isInstalledOnly: Bool

@AppStorage(PreferenceKey.allowedMajorVersions.rawValue) private var allowedMajorVersions = Int.max

init(selectedXcodeID: Binding<Xcode.ID?>, searchText: String, category: XcodeListCategory, isInstalledOnly: Bool) {
self._selectedXcodeID = selectedXcodeID
self.searchText = searchText
Expand All @@ -27,6 +28,22 @@ struct XcodeListView: View {
xcodes = appState.allXcodes.filter { $0.version.isPrerelease }
}

let latestMajor = xcodes.sorted(\.version)
.filter { $0.version.isNotPrerelease }
.last?
.version
.major

xcodes = xcodes.filter {
if $0.installState.notInstalled,
let latestMajor = latestMajor,
$0.version.major < (latestMajor - min(latestMajor,allowedMajorVersions)) {
return false
}

return true
}

if !searchText.isEmpty {
xcodes = xcodes.filter { $0.description.contains(searchText) }
}
Expand Down Expand Up @@ -87,6 +104,9 @@ struct XcodeListView_Previews: PreviewProvider {
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),
Xcode(version: Version("10.1.0")!, installState: .notInstalled, selected: false, icon: nil),
Xcode(version: Version("10.0.0")!, installState: .installed(Path("/Applications/Xcode-10.0.0.app")!), selected: false, icon: nil),
Xcode(version: Version("9.0.0")!, installState: .notInstalled, selected: false, icon: nil),
]
return a
}())
Expand Down

0 comments on commit a75c54f

Please sign in to comment.