Add default profiles and option to reset to defaults

This commit is contained in:
Arkadiusz Fal
2022-08-17 00:34:25 +02:00
parent 3999c19a6e
commit a6f2ff9f52
6 changed files with 90 additions and 14 deletions

View File

@@ -68,6 +68,7 @@ struct LocationsSettings: View {
Section(header: SettingsHeader(text: "Custom Locations")) {
#if os(macOS)
InstancesSettings()
.environmentObject(model)
#else
ForEach(instances) { instance in
AccountsNavigationLink(instance: instance)

View File

@@ -1,3 +1,4 @@
import Defaults
import SwiftUI
struct QualityProfileForm: View {
@@ -14,6 +15,8 @@ struct QualityProfileForm: View {
@State private var resolution = ResolutionSetting.hd1080p60
@State private var formats = [QualityProfile.Format]()
@Default(.qualityProfiles) private var qualityProfiles
var qualityProfile: QualityProfile! {
if let id = qualityProfileID {
return QualityProfilesModel.shared.find(id)
@@ -131,7 +134,7 @@ struct QualityProfileForm: View {
.modifier(SettingsPickerModifier())
#if os(iOS)
return HStack {
HStack {
Text("Resolution")
Spacer()
Menu {
@@ -175,7 +178,7 @@ struct QualityProfileForm: View {
}
.modifier(SettingsPickerModifier())
#if os(iOS)
return HStack {
HStack {
Text("Backend")
Spacer()
Menu {
@@ -321,7 +324,12 @@ struct QualityProfileForm: View {
if editing {
QualityProfilesModel.shared.update(qualityProfile, formProfile)
} else {
let wasEmpty = qualityProfiles.isEmpty
QualityProfilesModel.shared.add(formProfile)
if wasEmpty {
QualityProfilesModel.shared.applyToAll(formProfile)
}
}
presentationMode.wrappedValue.dismiss()

View File

@@ -5,8 +5,9 @@ struct QualitySettings: View {
@State private var presentingProfileForm = false
@State private var editedProfileID: QualityProfile.ID?
@Default(.qualityProfiles) private var qualityProfiles
@EnvironmentObject<SettingsModel> private var settings
@Default(.qualityProfiles) private var qualityProfiles
@Default(.batteryCellularProfile) private var batteryCellularProfile
@Default(.batteryNonCellularProfile) private var batteryNonCellularProfile
@Default(.chargingCellularProfile) private var chargingCellularProfile
@@ -75,6 +76,25 @@ struct QualitySettings: View {
}
}
.frame(maxWidth: .infinity, alignment: .leading)
HStack {
Button {
settings.presentAlert(
Alert(
title: Text("Are you sure you want to restore default quality profiles?"),
message: Text("This will remove all your custom profiles and return their default values. This cannot be reverted."),
primaryButton: .destructive(Text("Reset")) {
QualityProfilesModel.shared.reset()
},
secondaryButton: .cancel()
)
)
} label: {
Text("Restore default profiles...")
.foregroundColor(.red)
}
Spacer()
}
}
}