Files
SideStore/AltStore/SwiftUI/Views/Settings/UnstableFeaturesView.swift
naturecodevoid 026392dbc7 More improvements and fixes (see commit description)
- put SwiftUI in an unstable feature
- Add Reset adi.pb to SwiftUI settings
- Add localizations to more things such as Error Log and Refresh Attempts
- Move debug logging into Advanced Settings
- Add padding to version text at the bottom of SwiftUI settings
- Add some things to Unstable Features such as nesting the Feature enum in UnstableFeatures and allowing on enable/disable hooks
- Don't use ObservableObject for UnstableFeatures as it's not needed
- fix a bug with unstable features where the toggle would be reverted if you go into another tab and then back
- Use SwiftUI advanced settings in UIKit
2023-05-27 21:53:04 -07:00

63 lines
2.6 KiB
Swift

//
// 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 iO = Inject.observer
// Keeping a cache of the features allows us to reload the view every time we change one
// If we don't reload the view there is a bug where the toggle will be reset to previous value if you go to another tab and then back
@State private var featureCache: [(key: UnstableFeatures.Feature, value: Bool)]
var inDevMode: Bool
init(inDevMode: Bool) {
self.inDevMode = inDevMode
self.featureCache = UnstableFeatures.getFeatures(inDevMode)
}
var body: some View {
List {
let description = L10n.UnstableFeaturesView.description + (featureCache.count <= 0 ? "\n\n" + L10n.UnstableFeaturesView.noUnstableFeatures : "")
Section {} footer: {
if #available(iOS 15.0, *),
let string = try? AttributedString(markdown: description, options: AttributedString.MarkdownParsingOptions(interpretedSyntax: .inlineOnlyPreservingWhitespace)) {
Text(string).font(.callout).foregroundColor(.primary)
} else {
Text(description).font(.callout).foregroundColor(.primary)
}
}.listRowInsets(EdgeInsets(top: 8, leading: 0, bottom: 8, trailing: 0))
if featureCache.count > 0 {
ForEach(featureCache.sorted(by: { _, _ in true }), id: \.key) { feature, _ in
Toggle(isOn: Binding(get: { UnstableFeatures.enabled(feature) }, set: { newValue in
UnstableFeatures.set(feature, enabled: newValue)
// Update the cache so we reload the view (this fixes the toggle resetting to the previous value if you go to another tab and then back)
featureCache = UnstableFeatures.getFeatures(inDevMode)
})) {
Text(String(describing: feature))
let link = "https://github.com/SideStore/SideStore/issues/\(feature.rawValue)"
Link(link, destination: URL(string: link)!)
}
}
}
}
.navigationTitle(L10n.UnstableFeaturesView.title)
.enableInjection()
}
}
struct UnstableFeaturesView_Previews: PreviewProvider {
static var previews: some View {
UnstableFeaturesView(inDevMode: true)
}
}
#endif