mirror of
https://github.com/SideStore/SideStore.git
synced 2026-04-05 18:25:41 +02:00
feat: view to enable/disable Unstable Features
This commit is contained in:
@@ -65,7 +65,9 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
// Register default settings before doing anything else.
|
||||
UserDefaults.registerDefaults()
|
||||
|
||||
#if UNSTABLE
|
||||
UnstableFeatures.load()
|
||||
#endif
|
||||
|
||||
LCManager.shared.isVisible = UserDefaults.standard.isConsoleEnabled
|
||||
LCManager.shared.isCharacterLimitDisabled = true // we want all logs exported
|
||||
|
||||
@@ -209,3 +209,6 @@ You should only enable Developer Mode if you meet one of the following requireme
|
||||
"AdvancedSettingsView.dangerZoneInfo" = "If you disable \"Use preferred servers\" then SideStore will use the server you input into the \"Anisette URL\" box rather than one selected in \"Anisette Server\".";
|
||||
"AdvancedSettingsView.DangerZone.usePreferred" = "Use preferred servers";
|
||||
"AdvancedSettingsView.DangerZone.anisetteURL" = "Anisette URL";
|
||||
|
||||
/* UnstableFeaturesView */
|
||||
"UnstableFeaturesView.title" = "Unstable Features";
|
||||
|
||||
@@ -405,6 +405,10 @@ internal enum L10n {
|
||||
/// Trusted Sources
|
||||
internal static let trustedSources = L10n.tr("Localizable", "SourcesView.trustedSources", fallback: "Trusted Sources")
|
||||
}
|
||||
internal enum UnstableFeaturesView {
|
||||
/// UnstableFeaturesView
|
||||
internal static let title = L10n.tr("Localizable", "UnstableFeaturesView.title", fallback: "Unstable Features")
|
||||
}
|
||||
}
|
||||
// swiftlint:enable explicit_type_interface function_parameter_count identifier_name line_length
|
||||
// swiftlint:enable nesting type_body_length type_name vertical_whitespace_opening_braces
|
||||
|
||||
@@ -136,6 +136,15 @@ struct DevModeMenu: View {
|
||||
LCManager.shared.isVisible = value
|
||||
}
|
||||
|
||||
NavigationLink(L10n.UnstableFeaturesView.title) {
|
||||
#if UNSTABLE
|
||||
UnstableFeaturesView(allowDevModeOnlyFeatures: true)
|
||||
#endif
|
||||
}
|
||||
#if !UNSTABLE
|
||||
.disabled(true)
|
||||
#endif
|
||||
|
||||
NavigationLink(L10n.DevModeView.dataExplorer) {
|
||||
FileExplorer.normal(url: FileManager.default.altstoreSharedDirectory)
|
||||
.navigationTitle(L10n.DevModeView.dataExplorer)
|
||||
|
||||
@@ -113,6 +113,10 @@ struct SettingsView: View {
|
||||
SiriShortcutSetupView(shortcut: shortcut)
|
||||
}
|
||||
}
|
||||
|
||||
NavigationLink("Show Refresh Attempts") {
|
||||
RefreshAttemptsView()
|
||||
}
|
||||
} header: {
|
||||
Text(L10n.SettingsView.refreshingApps)
|
||||
} footer: {
|
||||
@@ -162,15 +166,17 @@ struct SettingsView: View {
|
||||
NavigationLink("Show Error Log") {
|
||||
ErrorLogView()
|
||||
}
|
||||
|
||||
NavigationLink("Show Refresh Attempts") {
|
||||
RefreshAttemptsView()
|
||||
}
|
||||
|
||||
NavigationLink(L10n.AdvancedSettingsView.title) {
|
||||
AdvancedSettingsView()
|
||||
}
|
||||
|
||||
#if UNSTABLE
|
||||
NavigationLink(L10n.UnstableFeaturesView.title) {
|
||||
UnstableFeaturesView(allowDevModeOnlyFeatures: false)
|
||||
}
|
||||
#endif
|
||||
|
||||
Toggle(L10n.SettingsView.debugLogging, isOn: self.$isDebugLoggingEnabled)
|
||||
.onChange(of: self.isDebugLoggingEnabled) { value in
|
||||
UserDefaults.shared.isDebugLoggingEnabled = value
|
||||
|
||||
35
AltStore/SwiftUI/Views/Settings/UnstableFeaturesView.swift
Normal file
35
AltStore/SwiftUI/Views/Settings/UnstableFeaturesView.swift
Normal file
@@ -0,0 +1,35 @@
|
||||
//
|
||||
// UnstableFeaturesView.swift
|
||||
// SideStore
|
||||
//
|
||||
// Created by naturecodevoid on 5/20/23.
|
||||
// Copyright © 2023 SideStore. All rights reserved.
|
||||
//
|
||||
|
||||
#if UNSTABLE
|
||||
import SwiftUI
|
||||
|
||||
struct UnstableFeaturesView: View {
|
||||
@ObservedObject private var shared = UnstableFeatures.shared
|
||||
|
||||
var allowDevModeOnlyFeatures: Bool
|
||||
|
||||
var body: some View {
|
||||
List {
|
||||
ForEach(shared.features.filter { feature, _ in feature != AvailableUnstableFeature.dummy && allowDevModeOnlyFeatures ? true : feature.availableOutsideDevMode() }.sorted(by: { _, _ in true }), id: \.key) { feature, _ in
|
||||
Toggle(isOn: Binding(get: { UnstableFeatures.enabled(feature) }, set: { newValue in UnstableFeatures.set(feature, enabled: newValue) })) {
|
||||
Text(String(describing: feature))
|
||||
let link = "https://github.com/SideStore/SideStore/issues/\(feature.rawValue)"
|
||||
Link(link, destination: URL(string: link)!)
|
||||
}
|
||||
}
|
||||
}.navigationTitle(L10n.UnstableFeaturesView.title)
|
||||
}
|
||||
}
|
||||
|
||||
struct UnstableFeaturesView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
UnstableFeaturesView(allowDevModeOnlyFeatures: true)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -6,6 +6,8 @@
|
||||
// Copyright © 2023 SideStore. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
// I prefixed it with Available to make UnstableFeatures come up first in autocomplete, feel free to rename it if you know a better name
|
||||
enum AvailableUnstableFeature: String, CaseIterable {
|
||||
// The value will be the GitHub Issue number. For example, "123" would correspond to https://github.com/SideStore/SideStore/issues/123
|
||||
@@ -29,71 +31,58 @@ enum AvailableUnstableFeature: String, CaseIterable {
|
||||
}
|
||||
}
|
||||
|
||||
class UnstableFeatures {
|
||||
|
||||
class UnstableFeatures: ObservableObject {
|
||||
#if UNSTABLE
|
||||
private static var features: [AvailableUnstableFeature: Bool] = [:]
|
||||
#endif
|
||||
static let shared = UnstableFeatures()
|
||||
@Published var features: [AvailableUnstableFeature: Bool] = [:]
|
||||
|
||||
static func load() {
|
||||
#if UNSTABLE
|
||||
|
||||
if features.count > 0 { return print("It seems unstable features have already been loaded, skipping") }
|
||||
if shared.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 }) {
|
||||
features[feature] = rawFeature.value
|
||||
shared.features[feature] = rawFeature.value
|
||||
} else {
|
||||
print("Unknown unstable feature: \(rawFeature.key) = \(rawFeature.value)")
|
||||
}
|
||||
}
|
||||
for feature in AvailableUnstableFeature.allCases {
|
||||
if shared.features[feature] == nil {
|
||||
shared.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 {
|
||||
features[feature] = false
|
||||
shared.features[feature] = false
|
||||
}
|
||||
save()
|
||||
}
|
||||
|
||||
#else
|
||||
print("Unstable features are not available on this build")
|
||||
#endif
|
||||
}
|
||||
|
||||
private static func save(load: Bool = false) {
|
||||
#if UNSTABLE
|
||||
|
||||
var rawFeatures: [String: Bool] = [:]
|
||||
for feature in features {
|
||||
for feature in shared.features {
|
||||
rawFeatures[String(describing: feature.key)] = feature.value
|
||||
}
|
||||
UserDefaults.shared.unstableFeatures = try! JSONEncoder().encode(rawFeatures)
|
||||
print("\(load ? "Loaded" : "Saved") unstable features: \(String(describing: rawFeatures))")
|
||||
|
||||
#else
|
||||
// we want this to crash, this function should never be triggered on non-unstable builds
|
||||
fatalError("Tried to save unstable features on non-unstable build!")
|
||||
#endif
|
||||
}
|
||||
|
||||
static func set(_ feature: AvailableUnstableFeature, enabled: Bool) {
|
||||
#if UNSTABLE
|
||||
|
||||
features[feature] = enabled
|
||||
shared.features[feature] = enabled
|
||||
save()
|
||||
|
||||
#else
|
||||
// we want this to crash, this function should never be triggered on non-unstable builds
|
||||
fatalError("Tried to set unstable feature \(String(describing: feature)) to \(enabled) on non-unstable build!")
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
@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
|
||||
features[feature] ?? false
|
||||
shared.features[feature] ?? false
|
||||
#else
|
||||
false
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user