mirror of
https://github.com/XcodesOrg/XcodesApp.git
synced 2026-03-25 08:55:46 +00:00
Merge pull request #632 from abiligiri/feature/more_managed_preferences
Restrict allowed versions & hide 'Support Xcodes'
This commit is contained in:
commit
a75c54f2f6
3 changed files with 64 additions and 12 deletions
|
|
@ -24,6 +24,8 @@ enum PreferenceKey: String {
|
||||||
case downloader
|
case downloader
|
||||||
case dataSource
|
case dataSource
|
||||||
case xcodeListCategory
|
case xcodeListCategory
|
||||||
|
case allowedMajorVersions
|
||||||
|
case hideSupportXcodes
|
||||||
|
|
||||||
func isManaged() -> Bool { UserDefaults.standard.objectIsForced(forKey: self.rawValue) }
|
func isManaged() -> Bool { UserDefaults.standard.objectIsForced(forKey: self.rawValue) }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ import SwiftUI
|
||||||
|
|
||||||
struct BottomStatusModifier: ViewModifier {
|
struct BottomStatusModifier: ViewModifier {
|
||||||
@EnvironmentObject var appState: AppState
|
@EnvironmentObject var appState: AppState
|
||||||
|
@AppStorage(PreferenceKey.hideSupportXcodes.rawValue) var hideSupportXcodes = false
|
||||||
|
|
||||||
@SwiftUI.Environment(\.openURL) var openURL: OpenURLAction
|
@SwiftUI.Environment(\.openURL) var openURL: OpenURLAction
|
||||||
|
|
||||||
func body(content: Content) -> some View {
|
func body(content: Content) -> some View {
|
||||||
|
|
@ -20,17 +22,19 @@ struct BottomStatusModifier: ViewModifier {
|
||||||
Divider()
|
Divider()
|
||||||
HStack {
|
HStack {
|
||||||
Text(appState.bottomStatusBarMessage)
|
Text(appState.bottomStatusBarMessage)
|
||||||
.font(.subheadline)
|
.font(.subheadline)
|
||||||
Spacer()
|
Spacer()
|
||||||
Button(action: {
|
if !hideSupportXcodes {
|
||||||
openURL(URL(string: "https://opencollective.com/xcodesapp")!)
|
Button(action: {
|
||||||
}) {
|
openURL(URL(string: "https://opencollective.com/xcodesapp")!)
|
||||||
HStack {
|
}) {
|
||||||
Image(systemName: "heart.circle")
|
HStack {
|
||||||
Text("Support.Xcodes")
|
Image(systemName: "heart.circle")
|
||||||
|
Text("Support.Xcodes")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Text(Bundle.main.shortVersion!)
|
Text("\(Bundle.main.shortVersion!) (\(Bundle.main.version!))")
|
||||||
.font(.subheadline)
|
.font(.subheadline)
|
||||||
}
|
}
|
||||||
.frame(maxWidth: .infinity, maxHeight: 30, alignment: .leading)
|
.frame(maxWidth: .infinity, maxHeight: 30, alignment: .leading)
|
||||||
|
|
@ -51,8 +55,34 @@ extension View {
|
||||||
|
|
||||||
struct Previews_BottomStatusBar_Previews: PreviewProvider {
|
struct Previews_BottomStatusBar_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
HStack {
|
Group {
|
||||||
|
HStack {
|
||||||
}.bottomStatusBar()
|
|
||||||
|
}
|
||||||
|
.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
|
||||||
|
}())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,8 @@ struct XcodeListView: View {
|
||||||
private let searchText: String
|
private let searchText: String
|
||||||
private let category: XcodeListCategory
|
private let category: XcodeListCategory
|
||||||
private let isInstalledOnly: Bool
|
private let isInstalledOnly: Bool
|
||||||
|
@AppStorage(PreferenceKey.allowedMajorVersions.rawValue) private var allowedMajorVersions = Int.max
|
||||||
|
|
||||||
init(selectedXcodeID: Binding<Xcode.ID?>, searchText: String, category: XcodeListCategory, isInstalledOnly: Bool) {
|
init(selectedXcodeID: Binding<Xcode.ID?>, searchText: String, category: XcodeListCategory, isInstalledOnly: Bool) {
|
||||||
self._selectedXcodeID = selectedXcodeID
|
self._selectedXcodeID = selectedXcodeID
|
||||||
self.searchText = searchText
|
self.searchText = searchText
|
||||||
|
|
@ -27,6 +28,22 @@ struct XcodeListView: View {
|
||||||
xcodes = appState.allXcodes.filter { $0.version.isPrerelease }
|
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 {
|
if !searchText.isEmpty {
|
||||||
xcodes = xcodes.filter { $0.description.contains(searchText) }
|
xcodes = xcodes.filter { $0.description.contains(searchText) }
|
||||||
}
|
}
|
||||||
|
|
@ -87,6 +104,9 @@ struct XcodeListView_Previews: PreviewProvider {
|
||||||
Xcode(version: Version("12.2.0")!, installState: .notInstalled, selected: false, 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.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("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
|
return a
|
||||||
}())
|
}())
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue