mirror of
https://github.com/yattee/yattee.git
synced 2024-12-14 06:10:32 +05:30
Add default profiles and option to reset to defaults
This commit is contained in:
parent
76a8270293
commit
23acf636da
@ -4,7 +4,6 @@ import Foundation
|
|||||||
struct QualityProfile: Hashable, Identifiable, Defaults.Serializable {
|
struct QualityProfile: Hashable, Identifiable, Defaults.Serializable {
|
||||||
static var bridge = QualityProfileBridge()
|
static var bridge = QualityProfileBridge()
|
||||||
static var defaultProfile = Self(id: "default", backend: .mpv, resolution: .hd720p60, formats: [.stream])
|
static var defaultProfile = Self(id: "default", backend: .mpv, resolution: .hd720p60, formats: [.stream])
|
||||||
static var highQualityProfile = Self(id: "highQuality", backend: .mpv, resolution: .hd2160p60, formats: [.webm, .mp4, .av1, .avc1])
|
|
||||||
|
|
||||||
enum Format: String, CaseIterable, Identifiable, Defaults.Serializable {
|
enum Format: String, CaseIterable, Identifiable, Defaults.Serializable {
|
||||||
case hls
|
case hls
|
||||||
|
@ -15,11 +15,7 @@ struct QualityProfilesModel {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
func find(_ id: QualityProfile.ID) -> QualityProfile? {
|
func find(_ id: QualityProfile.ID) -> QualityProfile? {
|
||||||
if id == "default" {
|
guard id != "default" else { return QualityProfile.defaultProfile }
|
||||||
return QualityProfile.defaultProfile
|
|
||||||
} else if id == "highQuality" {
|
|
||||||
return QualityProfile.highQualityProfile
|
|
||||||
}
|
|
||||||
|
|
||||||
return Defaults[.qualityProfiles].first { $0.id == id }
|
return Defaults[.qualityProfiles].first { $0.id == id }
|
||||||
}
|
}
|
||||||
@ -47,6 +43,14 @@ struct QualityProfilesModel {
|
|||||||
Defaults[.chargingNonCellularProfile] = qualityProfile.id
|
Defaults[.chargingNonCellularProfile] = qualityProfile.id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func reset() {
|
||||||
|
Defaults.reset(.qualityProfiles)
|
||||||
|
Defaults.reset(.batteryCellularProfile)
|
||||||
|
Defaults.reset(.batteryNonCellularProfile)
|
||||||
|
Defaults.reset(.chargingCellularProfile)
|
||||||
|
Defaults.reset(.chargingNonCellularProfile)
|
||||||
|
}
|
||||||
|
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
private func findCurrentConnection() -> Reachability.Connection? {
|
private func findCurrentConnection() -> Reachability.Connection? {
|
||||||
do {
|
do {
|
||||||
|
@ -38,11 +38,55 @@ extension Defaults.Keys {
|
|||||||
|
|
||||||
static let captionsLanguageCode = Key<String?>("captionsLanguageCode")
|
static let captionsLanguageCode = Key<String?>("captionsLanguageCode")
|
||||||
static let activeBackend = Key<PlayerBackendType>("activeBackend", default: .mpv)
|
static let activeBackend = Key<PlayerBackendType>("activeBackend", default: .mpv)
|
||||||
static let qualityProfiles = Key<[QualityProfile]>("qualityProfiles", default: [QualityProfile.defaultProfile, QualityProfile.highQualityProfile])
|
|
||||||
static let batteryCellularProfile = Key<QualityProfile.ID>("batteryCellularProfile", default: QualityProfile.defaultProfile.id)
|
static let hd2160pMPVProfile = QualityProfile(backend: .mpv, resolution: .hd2160p60, formats: QualityProfile.Format.allCases)
|
||||||
static let batteryNonCellularProfile = Key<QualityProfile.ID>("batteryNonCellularProfile", default: QualityProfile.defaultProfile.id)
|
static let hd1080pMPVProfile = QualityProfile(backend: .mpv, resolution: .hd1080p60, formats: QualityProfile.Format.allCases)
|
||||||
static let chargingCellularProfile = Key<QualityProfile.ID>("chargingCellularProfile", default: QualityProfile.defaultProfile.id)
|
static let hd720pMPVProfile = QualityProfile(backend: .mpv, resolution: .hd720p60, formats: QualityProfile.Format.allCases)
|
||||||
static let chargingNonCellularProfile = Key<QualityProfile.ID>("chargingNonCellularProfile", default: QualityProfile.defaultProfile.id)
|
static let hd720pAVPlayerProfile = QualityProfile(backend: .appleAVPlayer, resolution: .hd720p60, formats: [.hls, .stream])
|
||||||
|
static let sd360pAVPlayerProfile = QualityProfile(backend: .appleAVPlayer, resolution: .sd360p30, formats: [.hls, .stream])
|
||||||
|
|
||||||
|
#if os(iOS)
|
||||||
|
static let qualityProfilesDefault = UIDevice.current.userInterfaceIdiom == .pad ? [
|
||||||
|
hd2160pMPVProfile,
|
||||||
|
hd1080pMPVProfile,
|
||||||
|
hd720pAVPlayerProfile,
|
||||||
|
sd360pAVPlayerProfile
|
||||||
|
] : [
|
||||||
|
hd1080pMPVProfile,
|
||||||
|
hd720pAVPlayerProfile,
|
||||||
|
sd360pAVPlayerProfile
|
||||||
|
]
|
||||||
|
|
||||||
|
static let batteryCellularProfileDefault = hd720pAVPlayerProfile.id
|
||||||
|
static let batteryNonCellularProfileDefault = hd720pAVPlayerProfile.id
|
||||||
|
static let chargingCellularProfileDefault = hd720pAVPlayerProfile.id
|
||||||
|
static let chargingNonCellularProfileDefault = hd1080pMPVProfile.id
|
||||||
|
#elseif os(tvOS)
|
||||||
|
static let qualityProfilesDefault = [
|
||||||
|
hd2160pMPVProfile,
|
||||||
|
hd1080pMPVProfile,
|
||||||
|
hd720pMPVProfile
|
||||||
|
]
|
||||||
|
static let batteryCellularProfileDefault = hd1080pMPVProfile.id
|
||||||
|
static let batteryNonCellularProfileDefault = hd1080pMPVProfile.id
|
||||||
|
static let chargingCellularProfileDefault = hd1080pMPVProfile.id
|
||||||
|
static let chargingNonCellularProfileDefault = hd1080pMPVProfile.id
|
||||||
|
#else
|
||||||
|
static let qualityProfilesDefault = [
|
||||||
|
hd2160pMPVProfile,
|
||||||
|
hd1080pMPVProfile,
|
||||||
|
hd720pAVPlayerProfile
|
||||||
|
]
|
||||||
|
static let batteryCellularProfileDefault = hd1080pMPVProfile.id
|
||||||
|
static let batteryNonCellularProfileDefault = hd1080pMPVProfile.id
|
||||||
|
static let chargingCellularProfileDefault = hd1080pMPVProfile.id
|
||||||
|
static let chargingNonCellularProfileDefault = hd1080pMPVProfile.id
|
||||||
|
#endif
|
||||||
|
static let qualityProfiles = Key<[QualityProfile]>("qualityProfiles", default: qualityProfilesDefault)
|
||||||
|
static let batteryCellularProfile = Key<QualityProfile.ID>("batteryCellularProfile", default: batteryCellularProfileDefault)
|
||||||
|
static let batteryNonCellularProfile = Key<QualityProfile.ID>("batteryNonCellularProfile", default: batteryNonCellularProfileDefault)
|
||||||
|
static let chargingCellularProfile = Key<QualityProfile.ID>("chargingCellularProfile", default: chargingCellularProfileDefault)
|
||||||
|
static let chargingNonCellularProfile = Key<QualityProfile.ID>("chargingNonCellularProfile", default: chargingNonCellularProfileDefault)
|
||||||
|
|
||||||
static let playerSidebar = Key<PlayerSidebarSetting>("playerSidebar", default: PlayerSidebarSetting.defaultValue)
|
static let playerSidebar = Key<PlayerSidebarSetting>("playerSidebar", default: PlayerSidebarSetting.defaultValue)
|
||||||
static let playerInstanceID = Key<Instance.ID?>("playerInstance")
|
static let playerInstanceID = Key<Instance.ID?>("playerInstance")
|
||||||
|
@ -68,6 +68,7 @@ struct LocationsSettings: View {
|
|||||||
Section(header: SettingsHeader(text: "Custom Locations")) {
|
Section(header: SettingsHeader(text: "Custom Locations")) {
|
||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
InstancesSettings()
|
InstancesSettings()
|
||||||
|
.environmentObject(model)
|
||||||
#else
|
#else
|
||||||
ForEach(instances) { instance in
|
ForEach(instances) { instance in
|
||||||
AccountsNavigationLink(instance: instance)
|
AccountsNavigationLink(instance: instance)
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import Defaults
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct QualityProfileForm: View {
|
struct QualityProfileForm: View {
|
||||||
@ -14,6 +15,8 @@ struct QualityProfileForm: View {
|
|||||||
@State private var resolution = ResolutionSetting.hd1080p60
|
@State private var resolution = ResolutionSetting.hd1080p60
|
||||||
@State private var formats = [QualityProfile.Format]()
|
@State private var formats = [QualityProfile.Format]()
|
||||||
|
|
||||||
|
@Default(.qualityProfiles) private var qualityProfiles
|
||||||
|
|
||||||
var qualityProfile: QualityProfile! {
|
var qualityProfile: QualityProfile! {
|
||||||
if let id = qualityProfileID {
|
if let id = qualityProfileID {
|
||||||
return QualityProfilesModel.shared.find(id)
|
return QualityProfilesModel.shared.find(id)
|
||||||
@ -131,7 +134,7 @@ struct QualityProfileForm: View {
|
|||||||
.modifier(SettingsPickerModifier())
|
.modifier(SettingsPickerModifier())
|
||||||
|
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
return HStack {
|
HStack {
|
||||||
Text("Resolution")
|
Text("Resolution")
|
||||||
Spacer()
|
Spacer()
|
||||||
Menu {
|
Menu {
|
||||||
@ -175,7 +178,7 @@ struct QualityProfileForm: View {
|
|||||||
}
|
}
|
||||||
.modifier(SettingsPickerModifier())
|
.modifier(SettingsPickerModifier())
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
return HStack {
|
HStack {
|
||||||
Text("Backend")
|
Text("Backend")
|
||||||
Spacer()
|
Spacer()
|
||||||
Menu {
|
Menu {
|
||||||
@ -321,7 +324,12 @@ struct QualityProfileForm: View {
|
|||||||
if editing {
|
if editing {
|
||||||
QualityProfilesModel.shared.update(qualityProfile, formProfile)
|
QualityProfilesModel.shared.update(qualityProfile, formProfile)
|
||||||
} else {
|
} else {
|
||||||
|
let wasEmpty = qualityProfiles.isEmpty
|
||||||
QualityProfilesModel.shared.add(formProfile)
|
QualityProfilesModel.shared.add(formProfile)
|
||||||
|
|
||||||
|
if wasEmpty {
|
||||||
|
QualityProfilesModel.shared.applyToAll(formProfile)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
presentationMode.wrappedValue.dismiss()
|
presentationMode.wrappedValue.dismiss()
|
||||||
|
@ -5,8 +5,9 @@ struct QualitySettings: View {
|
|||||||
@State private var presentingProfileForm = false
|
@State private var presentingProfileForm = false
|
||||||
@State private var editedProfileID: QualityProfile.ID?
|
@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(.batteryCellularProfile) private var batteryCellularProfile
|
||||||
@Default(.batteryNonCellularProfile) private var batteryNonCellularProfile
|
@Default(.batteryNonCellularProfile) private var batteryNonCellularProfile
|
||||||
@Default(.chargingCellularProfile) private var chargingCellularProfile
|
@Default(.chargingCellularProfile) private var chargingCellularProfile
|
||||||
@ -75,6 +76,25 @@ struct QualitySettings: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.frame(maxWidth: .infinity, alignment: .leading)
|
.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()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user