@@ -10,6 +10,23 @@ import os.log
1010import DockProgress
1111import XcodesKit
1212
13+ enum PreferenceKey : String {
14+ case installPath
15+ case localPath
16+ case unxipExperiment
17+ case createSymLinkOnSelect
18+ case onSelectActionType
19+ case showOpenInRosettaOption
20+ case autoInstallation
21+ case SUEnableAutomaticChecks
22+ case includePrereleaseVersions
23+ case downloader
24+ case dataSource
25+ case xcodeListCategory
26+
27+ func isManaged( ) -> Bool { UserDefaults . standard. objectIsForced ( forKey: self . rawValue) }
28+ }
29+
1330class AppState : ObservableObject {
1431 private let client = AppleAPI . Client ( )
1532 internal let runtimeService = RuntimeService ( )
@@ -66,26 +83,32 @@ class AppState: ObservableObject {
6683 }
6784 }
6885
86+ var disableLocalPathChange : Bool { PreferenceKey . localPath. isManaged ( ) }
87+
6988 @Published var installPath = " " {
7089 didSet {
7190 Current . defaults. set ( installPath, forKey: " installPath " )
7291 }
7392 }
74-
93+
94+ var disableInstallPathChange : Bool { PreferenceKey . installPath. isManaged ( ) }
95+
7596 @Published var unxipExperiment = false {
7697 didSet {
7798 Current . defaults. set ( unxipExperiment, forKey: " unxipExperiment " )
7899 }
79100 }
80101
102+ var disableUnxipExperiment : Bool { PreferenceKey . unxipExperiment. isManaged ( ) }
103+
81104 @Published var createSymLinkOnSelect = false {
82105 didSet {
83106 Current . defaults. set ( createSymLinkOnSelect, forKey: " createSymLinkOnSelect " )
84107 }
85108 }
86109
87110 var createSymLinkOnSelectDisabled : Bool {
88- return onSelectActionType == . rename
111+ return onSelectActionType == . rename || PreferenceKey . createSymLinkOnSelect . isManaged ( )
89112 }
90113
91114 @Published var onSelectActionType = SelectedActionType . none {
@@ -98,6 +121,8 @@ class AppState: ObservableObject {
98121 }
99122 }
100123
124+ var onSelectActionTypeDisabled : Bool { PreferenceKey . onSelectActionType. isManaged ( ) }
125+
101126 @Published var showOpenInRosettaOption = false {
102127 didSet {
103128 Current . defaults. set ( showOpenInRosettaOption, forKey: " showOpenInRosettaOption " )
@@ -178,8 +203,8 @@ class AppState: ObservableObject {
178203 // MARK: Timer
179204 /// Runs a timer every 6 hours when app is open to check if it needs to auto install any xcodes
180205 func setupAutoInstallTimer( ) {
181- guard let storageValue = UserDefaults . standard . object ( forKey: " autoInstallation " ) as? Int , let autoInstallType = AutoInstallationType ( rawValue: storageValue) else { return }
182-
206+ guard let storageValue = Current . defaults . get ( forKey: " autoInstallation " ) as? Int , let autoInstallType = AutoInstallationType ( rawValue: storageValue) else { return }
207+
183208 if autoInstallType == . none { return }
184209
185210 autoInstallTimer = Timer . scheduledTimer ( withTimeInterval: 60 * 60 * 6 , repeats: true ) { [ weak self] _ in
@@ -479,7 +504,7 @@ class AppState: ObservableObject {
479504 . mapError { $0 as Error }
480505 }
481506 . flatMap { [ unowned self] in
482- self . install ( . version( availableXcode) , downloader: Downloader ( rawValue: UserDefaults . standard . string ( forKey: " downloader " ) ?? " aria2 " ) ?? . aria2)
507+ self . install ( . version( availableXcode) , downloader: Downloader ( rawValue: Current . defaults . string ( forKey: " downloader " ) ?? " aria2 " ) ?? . aria2)
483508 }
484509 . receive ( on: DispatchQueue . main)
485510 . sink (
@@ -505,7 +530,7 @@ class AppState: ObservableObject {
505530 func installWithoutLogin( id: Xcode . ID ) {
506531 guard let availableXcode = availableXcodes. first ( where: { $0. version == id } ) else { return }
507532
508- installationPublishers [ id] = self . install ( . version( availableXcode) , downloader: Downloader ( rawValue: UserDefaults . standard . string ( forKey: " downloader " ) ?? " aria2 " ) ?? . aria2)
533+ installationPublishers [ id] = self . install ( . version( availableXcode) , downloader: Downloader ( rawValue: Current . defaults . string ( forKey: " downloader " ) ?? " aria2 " ) ?? . aria2)
509534 . receive ( on: DispatchQueue . main)
510535 . sink (
511536 receiveCompletion: { [ unowned self] completion in
0 commit comments