@@ -11,6 +11,23 @@ import DockProgress
1111import XcodesKit
1212import LibFido2Swift
1313
14+ enum PreferenceKey : String {
15+ case installPath
16+ case localPath
17+ case unxipExperiment
18+ case createSymLinkOnSelect
19+ case onSelectActionType
20+ case showOpenInRosettaOption
21+ case autoInstallation
22+ case SUEnableAutomaticChecks
23+ case includePrereleaseVersions
24+ case downloader
25+ case dataSource
26+ case xcodeListCategory
27+
28+ func isManaged( ) -> Bool { UserDefaults . standard. objectIsForced ( forKey: self . rawValue) }
29+ }
30+
1431class AppState : ObservableObject {
1532 private let client = AppleAPI . Client ( )
1633 internal let runtimeService = RuntimeService ( )
@@ -67,26 +84,32 @@ class AppState: ObservableObject {
6784 }
6885 }
6986
87+ var disableLocalPathChange : Bool { PreferenceKey . localPath. isManaged ( ) }
88+
7089 @Published var installPath = " " {
7190 didSet {
7291 Current . defaults. set ( installPath, forKey: " installPath " )
7392 }
7493 }
75-
94+
95+ var disableInstallPathChange : Bool { PreferenceKey . installPath. isManaged ( ) }
96+
7697 @Published var unxipExperiment = false {
7798 didSet {
7899 Current . defaults. set ( unxipExperiment, forKey: " unxipExperiment " )
79100 }
80101 }
81102
103+ var disableUnxipExperiment : Bool { PreferenceKey . unxipExperiment. isManaged ( ) }
104+
82105 @Published var createSymLinkOnSelect = false {
83106 didSet {
84107 Current . defaults. set ( createSymLinkOnSelect, forKey: " createSymLinkOnSelect " )
85108 }
86109 }
87110
88111 var createSymLinkOnSelectDisabled : Bool {
89- return onSelectActionType == . rename
112+ return onSelectActionType == . rename || PreferenceKey . createSymLinkOnSelect . isManaged ( )
90113 }
91114
92115 @Published var onSelectActionType = SelectedActionType . none {
@@ -99,6 +122,8 @@ class AppState: ObservableObject {
99122 }
100123 }
101124
125+ var onSelectActionTypeDisabled : Bool { PreferenceKey . onSelectActionType. isManaged ( ) }
126+
102127 @Published var showOpenInRosettaOption = false {
103128 didSet {
104129 Current . defaults. set ( showOpenInRosettaOption, forKey: " showOpenInRosettaOption " )
@@ -179,8 +204,8 @@ class AppState: ObservableObject {
179204 // MARK: Timer
180205 /// Runs a timer every 6 hours when app is open to check if it needs to auto install any xcodes
181206 func setupAutoInstallTimer( ) {
182- guard let storageValue = UserDefaults . standard . object ( forKey: " autoInstallation " ) as? Int , let autoInstallType = AutoInstallationType ( rawValue: storageValue) else { return }
183-
207+ guard let storageValue = Current . defaults . get ( forKey: " autoInstallation " ) as? Int , let autoInstallType = AutoInstallationType ( rawValue: storageValue) else { return }
208+
184209 if autoInstallType == . none { return }
185210
186211 autoInstallTimer = Timer . scheduledTimer ( withTimeInterval: 60 * 60 * 6 , repeats: true ) { [ weak self] _ in
@@ -546,7 +571,7 @@ class AppState: ObservableObject {
546571 . mapError { $0 as Error }
547572 }
548573 . flatMap { [ unowned self] in
549- self . install ( . version( availableXcode) , downloader: Downloader ( rawValue: UserDefaults . standard . string ( forKey: " downloader " ) ?? " aria2 " ) ?? . aria2)
574+ self . install ( . version( availableXcode) , downloader: Downloader ( rawValue: Current . defaults . string ( forKey: " downloader " ) ?? " aria2 " ) ?? . aria2)
550575 }
551576 . receive ( on: DispatchQueue . main)
552577 . sink (
@@ -572,7 +597,7 @@ class AppState: ObservableObject {
572597 func installWithoutLogin( id: Xcode . ID ) {
573598 guard let availableXcode = availableXcodes. first ( where: { $0. version == id } ) else { return }
574599
575- installationPublishers [ id] = self . install ( . version( availableXcode) , downloader: Downloader ( rawValue: UserDefaults . standard . string ( forKey: " downloader " ) ?? " aria2 " ) ?? . aria2)
600+ installationPublishers [ id] = self . install ( . version( availableXcode) , downloader: Downloader ( rawValue: Current . defaults . string ( forKey: " downloader " ) ?? " aria2 " ) ?? . aria2)
576601 . receive ( on: DispatchQueue . main)
577602 . sink (
578603 receiveCompletion: { [ unowned self] completion in
0 commit comments