mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-13 16:53:29 +01:00
More improvements to unstable features and advanced settings
- added description of what they are and notice if there are none available - move them to advanced settings - add alert for unstable features in dev mode if the build does not have them enabled - move stuff out of the danger zone and into anisette section in advanced settings
This commit is contained in:
@@ -22,7 +22,7 @@ enum AvailableUnstableFeature: String, CaseIterable {
|
||||
func availableOutsideDevMode() -> Bool {
|
||||
switch self {
|
||||
// If your unstable feature is stable enough to be used by nightly users who are not alpha testers or developers,
|
||||
// you may want to have it available in the "Unstable Features" menu in Settings (outside of dev mode). To do so, add this:
|
||||
// you may want to have it available in the Unstable Features menu in Advanced Settings (outside of dev mode). To do so, add this:
|
||||
//case .yourFeature: return true
|
||||
case .jitUrlScheme: return true
|
||||
|
||||
@@ -34,31 +34,42 @@ enum AvailableUnstableFeature: String, CaseIterable {
|
||||
|
||||
class UnstableFeatures: ObservableObject {
|
||||
#if UNSTABLE
|
||||
static let shared = UnstableFeatures()
|
||||
@Published var features: [AvailableUnstableFeature: Bool] = [:]
|
||||
private static var features: [AvailableUnstableFeature: Bool] = [:]
|
||||
|
||||
static func getFeatures(_ inDevMode: Bool) -> [(key: AvailableUnstableFeature, value: Bool)] {
|
||||
return features
|
||||
.filter { feature, _ in
|
||||
feature != .dummy &&
|
||||
(inDevMode || feature.availableOutsideDevMode())
|
||||
}.sorted { a, b in a.key.rawValue > b.key.rawValue } // Convert to array of keys and values
|
||||
}
|
||||
|
||||
static func load() {
|
||||
if shared.features.count > 0 { return print("It seems unstable features have already been loaded, skipping") }
|
||||
if features.count > 0 { return print("It seems unstable features have already been loaded, skipping") }
|
||||
|
||||
if let rawFeatures = UserDefaults.shared.unstableFeatures,
|
||||
let rawFeatures = try? JSONDecoder().decode([String: Bool].self, from: rawFeatures) {
|
||||
for rawFeature in rawFeatures {
|
||||
if let feature = AvailableUnstableFeature.allCases.first(where: { feature in String(describing: feature) == rawFeature.key }) {
|
||||
shared.features[feature] = rawFeature.value
|
||||
features[feature] = rawFeature.value
|
||||
} else {
|
||||
print("Unknown unstable feature: \(rawFeature.key) = \(rawFeature.value)")
|
||||
}
|
||||
}
|
||||
|
||||
// If there's a new feature that wasn't saved and therefore wasn't loaded, let's set it to false
|
||||
// Technically we shouldn't have to do this because enabled() will fallback to false
|
||||
for feature in AvailableUnstableFeature.allCases {
|
||||
if shared.features[feature] == nil {
|
||||
shared.features[feature] = false
|
||||
if features[feature] == nil {
|
||||
features[feature] = false
|
||||
}
|
||||
}
|
||||
|
||||
save(load: true)
|
||||
} else {
|
||||
print("Setting all unstable features to false since we couldn't load them from UserDefaults (either they were never saved or there was an error decoding JSON)")
|
||||
for feature in AvailableUnstableFeature.allCases {
|
||||
shared.features[feature] = false
|
||||
features[feature] = false
|
||||
}
|
||||
save()
|
||||
}
|
||||
@@ -66,7 +77,7 @@ class UnstableFeatures: ObservableObject {
|
||||
|
||||
private static func save(load: Bool = false) {
|
||||
var rawFeatures: [String: Bool] = [:]
|
||||
for feature in shared.features {
|
||||
for feature in features {
|
||||
rawFeatures[String(describing: feature.key)] = feature.value
|
||||
}
|
||||
UserDefaults.shared.unstableFeatures = try! JSONEncoder().encode(rawFeatures)
|
||||
@@ -74,7 +85,7 @@ class UnstableFeatures: ObservableObject {
|
||||
}
|
||||
|
||||
static func set(_ feature: AvailableUnstableFeature, enabled: Bool) {
|
||||
shared.features[feature] = enabled
|
||||
features[feature] = enabled
|
||||
save()
|
||||
}
|
||||
#endif
|
||||
@@ -82,7 +93,7 @@ class UnstableFeatures: ObservableObject {
|
||||
@inline(__always) // hopefully this will help the compiler realize that if statements that use this function should be removed on non-unstable builds
|
||||
static func enabled(_ feature: AvailableUnstableFeature) -> Bool {
|
||||
#if UNSTABLE
|
||||
shared.features[feature] ?? false
|
||||
features[feature] ?? false
|
||||
#else
|
||||
false
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user