2022-07-02 02:58:32 +05:30
|
|
|
import Defaults
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct AdvancedSettings: View {
|
|
|
|
@Default(.showMPVPlaybackStats) private var showMPVPlaybackStats
|
2022-07-02 16:19:57 +05:30
|
|
|
@Default(.mpvCacheSecs) private var mpvCacheSecs
|
|
|
|
@Default(.mpvCachePauseWait) private var mpvCachePauseWait
|
2024-05-19 07:17:05 +05:30
|
|
|
@Default(.mpvCachePauseInital) private var mpvCachePauseInital
|
2024-02-02 14:13:46 +05:30
|
|
|
@Default(.mpvDeinterlace) private var mpvDeinterlace
|
2022-07-07 03:38:38 +05:30
|
|
|
@Default(.mpvEnableLogging) private var mpvEnableLogging
|
2024-05-22 22:12:08 +05:30
|
|
|
@Default(.mpvHWdec) private var mpvHWdec
|
|
|
|
@Default(.mpvDemuxerLavfProbeInfo) private var mpvDemuxerLavfProbeInfo
|
2024-05-23 22:32:13 +05:30
|
|
|
@Default(.mpvInitialAudioSync) private var mpvInitialAudioSync
|
2022-12-13 16:39:20 +05:30
|
|
|
@Default(.showCacheStatus) private var showCacheStatus
|
|
|
|
@Default(.feedCacheSize) private var feedCacheSize
|
2023-05-27 02:19:38 +05:30
|
|
|
@Default(.showPlayNowInBackendContextMenu) private var showPlayNowInBackendContextMenu
|
2022-07-07 03:38:38 +05:30
|
|
|
|
|
|
|
@State private var filesToShare = [MPVClient.logFile]
|
2022-11-12 00:25:18 +05:30
|
|
|
@State private var presentingShareSheet = false
|
2022-12-10 07:31:59 +05:30
|
|
|
|
|
|
|
private var settings = SettingsModel.shared
|
2022-07-02 02:58:32 +05:30
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
VStack(alignment: .leading) {
|
|
|
|
#if os(macOS)
|
|
|
|
advancedSettings
|
|
|
|
Spacer()
|
|
|
|
#else
|
|
|
|
List {
|
|
|
|
advancedSettings
|
|
|
|
}
|
|
|
|
#if os(iOS)
|
2022-07-07 03:38:38 +05:30
|
|
|
.sheet(isPresented: $presentingShareSheet) {
|
|
|
|
ShareSheet(activityItems: filesToShare)
|
|
|
|
.id("logs-\(filesToShare.count)")
|
|
|
|
}
|
2022-07-02 02:58:32 +05:30
|
|
|
.listStyle(.insetGrouped)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#if os(tvOS)
|
|
|
|
.frame(maxWidth: 1000)
|
|
|
|
#endif
|
|
|
|
.navigationTitle("Advanced")
|
|
|
|
}
|
|
|
|
|
2022-07-07 03:38:38 +05:30
|
|
|
var logButton: some View {
|
|
|
|
Button {
|
|
|
|
#if os(macOS)
|
|
|
|
NSWorkspace.shared.selectFile(MPVClient.logFile.path, inFileViewerRootedAtPath: YatteeApp.logsDirectory.path)
|
|
|
|
#else
|
|
|
|
presentingShareSheet = true
|
|
|
|
#endif
|
|
|
|
} label: {
|
|
|
|
#if os(macOS)
|
2022-10-12 22:19:47 +05:30
|
|
|
let labelText = "Open logs in Finder".localized()
|
2022-07-07 03:38:38 +05:30
|
|
|
#else
|
2022-10-12 22:19:47 +05:30
|
|
|
let labelText = "Share Logs...".localized()
|
2022-07-07 03:38:38 +05:30
|
|
|
#endif
|
|
|
|
Text(labelText)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-02 02:58:32 +05:30
|
|
|
@ViewBuilder var advancedSettings: some View {
|
2023-05-27 02:19:38 +05:30
|
|
|
Section(header: SettingsHeader(text: "Advanced")) {
|
|
|
|
showPlayNowInBackendButtonsToggle
|
|
|
|
}
|
|
|
|
|
2022-07-02 16:19:57 +05:30
|
|
|
Section(header: SettingsHeader(text: "MPV"), footer: mpvFooter) {
|
|
|
|
showMPVPlaybackStatsToggle
|
2022-07-07 03:38:38 +05:30
|
|
|
#if !os(tvOS)
|
|
|
|
mpvEnableLoggingToggle
|
|
|
|
#endif
|
2022-07-02 16:19:57 +05:30
|
|
|
|
2024-05-19 07:17:05 +05:30
|
|
|
Toggle(isOn: $mpvCachePauseInital) {
|
|
|
|
HStack {
|
|
|
|
Text("cache-pause-initial")
|
|
|
|
#if !os(tvOS)
|
2024-05-22 22:12:08 +05:30
|
|
|
Image(systemName: "link")
|
|
|
|
.accessibilityAddTraits([.isButton, .isLink])
|
|
|
|
.font(.footnote)
|
2024-05-23 15:23:41 +05:30
|
|
|
#if os(iOS)
|
2024-05-22 22:12:08 +05:30
|
|
|
.onTapGesture {
|
|
|
|
UIApplication.shared.open(URL(string: "https://mpv.io/manual/stable/#options-cache-pause-initial")!)
|
|
|
|
}
|
2024-05-23 15:23:41 +05:30
|
|
|
#elseif os(macOS)
|
2024-05-23 22:32:13 +05:30
|
|
|
.onTapGesture {
|
|
|
|
NSWorkspace.shared.open(URL(string: "https://mpv.io/manual/stable/#options-cache-pause-initial")!)
|
|
|
|
}
|
2024-05-22 22:12:08 +05:30
|
|
|
.onHover(perform: onHover(_:))
|
2024-05-19 07:17:05 +05:30
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-02 16:19:57 +05:30
|
|
|
HStack {
|
|
|
|
Text("cache-secs")
|
2024-05-19 07:17:05 +05:30
|
|
|
#if !os(tvOS)
|
2024-05-22 22:12:08 +05:30
|
|
|
Image(systemName: "link")
|
|
|
|
.accessibilityAddTraits([.isButton, .isLink])
|
|
|
|
.font(.footnote)
|
2024-05-23 15:23:41 +05:30
|
|
|
#if os(iOS)
|
2024-05-22 22:12:08 +05:30
|
|
|
.onTapGesture {
|
|
|
|
UIApplication.shared.open(URL(string: "https://mpv.io/manual/stable/#options-cache-secs")!)
|
|
|
|
}
|
2024-05-23 15:23:41 +05:30
|
|
|
#elseif os(macOS)
|
2024-05-23 22:32:13 +05:30
|
|
|
.onTapGesture {
|
|
|
|
NSWorkspace.shared.open(URL(string: "https://mpv.io/manual/stable/#options-cache-secs")!)
|
|
|
|
}
|
2024-05-22 22:12:08 +05:30
|
|
|
.onHover(perform: onHover(_:))
|
|
|
|
#endif
|
|
|
|
|
2024-05-19 07:17:05 +05:30
|
|
|
#endif
|
2022-07-02 16:19:57 +05:30
|
|
|
TextField("cache-secs", text: $mpvCacheSecs)
|
2022-12-22 01:46:47 +05:30
|
|
|
#if !os(macOS)
|
2024-05-09 18:32:31 +05:30
|
|
|
.keyboardType(.numberPad)
|
2022-12-22 01:46:47 +05:30
|
|
|
#endif
|
2022-07-02 16:19:57 +05:30
|
|
|
}
|
2022-07-04 02:02:26 +05:30
|
|
|
.multilineTextAlignment(.trailing)
|
2022-07-02 16:19:57 +05:30
|
|
|
|
|
|
|
HStack {
|
2024-05-19 07:17:05 +05:30
|
|
|
Group {
|
|
|
|
Text("cache-pause-wait")
|
|
|
|
#if !os(tvOS)
|
2024-05-22 22:12:08 +05:30
|
|
|
Image(systemName: "link")
|
|
|
|
.accessibilityAddTraits([.isButton, .isLink])
|
|
|
|
.font(.footnote)
|
2024-05-23 15:23:41 +05:30
|
|
|
#if os(iOS)
|
2024-05-22 22:12:08 +05:30
|
|
|
.onTapGesture {
|
|
|
|
UIApplication.shared.open(URL(string: "https://mpv.io/manual/stable/#options-cache-pause-wait")!)
|
|
|
|
}
|
2024-05-23 15:23:41 +05:30
|
|
|
#elseif os(macOS)
|
2024-05-23 22:32:13 +05:30
|
|
|
.onTapGesture {
|
|
|
|
NSWorkspace.shared.open(URL(string: "https://mpv.io/manual/stable/#options-cache-pause-wait")!)
|
|
|
|
}
|
2024-05-19 15:21:22 +05:30
|
|
|
.onHover(perform: onHover(_:))
|
|
|
|
#endif
|
2024-05-19 07:17:05 +05:30
|
|
|
#endif
|
|
|
|
}.frame(minWidth: 140, alignment: .leading)
|
|
|
|
|
2022-07-02 16:19:57 +05:30
|
|
|
TextField("cache-pause-wait", text: $mpvCachePauseWait)
|
2022-12-22 01:46:47 +05:30
|
|
|
#if !os(macOS)
|
2024-05-09 18:32:31 +05:30
|
|
|
.keyboardType(.numberPad)
|
2022-12-22 01:46:47 +05:30
|
|
|
#endif
|
2022-07-02 16:19:57 +05:30
|
|
|
}
|
2022-07-04 02:02:26 +05:30
|
|
|
.multilineTextAlignment(.trailing)
|
2022-07-07 03:38:38 +05:30
|
|
|
|
2024-05-19 07:17:05 +05:30
|
|
|
Toggle(isOn: $mpvDeinterlace) {
|
|
|
|
HStack {
|
|
|
|
Text("deinterlace")
|
|
|
|
#if !os(tvOS)
|
2024-05-22 22:12:08 +05:30
|
|
|
Image(systemName: "link")
|
|
|
|
.accessibilityAddTraits([.isButton, .isLink])
|
|
|
|
.font(.footnote)
|
2024-05-23 15:23:41 +05:30
|
|
|
#if os(iOS)
|
2024-05-22 22:12:08 +05:30
|
|
|
.onTapGesture {
|
|
|
|
UIApplication.shared.open(URL(string: "https://mpv.io/manual/stable/#options-deinterlace")!)
|
|
|
|
}
|
2024-05-23 15:23:41 +05:30
|
|
|
#elseif os(macOS)
|
2024-05-23 22:32:13 +05:30
|
|
|
.onTapGesture {
|
|
|
|
NSWorkspace.shared.open(URL(string: "https://mpv.io/manual/stable/#options-deinterlace")!)
|
|
|
|
}
|
|
|
|
.onHover(perform: onHover(_:))
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Toggle(isOn: $mpvInitialAudioSync) {
|
|
|
|
HStack {
|
|
|
|
Text("initial-audio-sync")
|
|
|
|
#if !os(tvOS)
|
|
|
|
Image(systemName: "link")
|
|
|
|
.accessibilityAddTraits([.isButton, .isLink])
|
|
|
|
.font(.footnote)
|
|
|
|
#if os(iOS)
|
|
|
|
.onTapGesture {
|
|
|
|
UIApplication.shared.open(URL(string: "https://mpv.io/manual/stable/#options-initial-audio-sync")!)
|
|
|
|
}
|
|
|
|
#elseif os(macOS)
|
|
|
|
.onTapGesture {
|
|
|
|
NSWorkspace.shared.open(URL(string: "https://mpv.io/manual/stable/#options-initial-audio-sync")!)
|
|
|
|
}
|
2024-05-22 22:12:08 +05:30
|
|
|
.onHover(perform: onHover(_:))
|
2024-05-19 07:17:05 +05:30
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2024-02-02 14:13:46 +05:30
|
|
|
|
2024-05-22 22:12:08 +05:30
|
|
|
HStack {
|
|
|
|
Text("hwdec")
|
|
|
|
|
|
|
|
#if !os(tvOS)
|
|
|
|
Image(systemName: "link")
|
|
|
|
.accessibilityAddTraits([.isButton, .isLink])
|
|
|
|
.font(.footnote)
|
2024-05-23 15:23:41 +05:30
|
|
|
#if os(iOS)
|
2024-05-22 22:12:08 +05:30
|
|
|
.onTapGesture {
|
|
|
|
UIApplication.shared.open(URL(string: "https://mpv.io/manual/stable/#options-hwdec")!)
|
|
|
|
}
|
2024-05-23 15:23:41 +05:30
|
|
|
#elseif os(macOS)
|
2024-05-23 22:32:13 +05:30
|
|
|
.onTapGesture {
|
|
|
|
NSWorkspace.shared.open(URL(string: "https://mpv.io/manual/stable/#options-hwdec")!)
|
|
|
|
}
|
2024-05-23 15:23:41 +05:30
|
|
|
.onHover(perform: onHover(_:))
|
2024-05-22 22:12:08 +05:30
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
Picker("", selection: $mpvHWdec) {
|
|
|
|
ForEach(["auto", "auto-safe", "auto-copy"], id: \.self) {
|
|
|
|
Text($0)
|
|
|
|
}
|
|
|
|
}
|
2024-05-23 15:23:41 +05:30
|
|
|
#if !os(tvOS)
|
2024-05-22 22:12:08 +05:30
|
|
|
.pickerStyle(MenuPickerStyle())
|
2024-05-23 15:23:41 +05:30
|
|
|
#endif
|
2024-05-22 22:12:08 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
HStack {
|
|
|
|
Text("demuxer-lavf-probe-info")
|
|
|
|
|
|
|
|
#if !os(tvOS)
|
|
|
|
Image(systemName: "link")
|
|
|
|
.accessibilityAddTraits([.isButton, .isLink])
|
|
|
|
.font(.footnote)
|
2024-05-23 15:23:41 +05:30
|
|
|
#if os(iOS)
|
2024-05-22 22:12:08 +05:30
|
|
|
.onTapGesture {
|
|
|
|
UIApplication.shared.open(URL(string: "https://mpv.io/manual/stable/#options-demuxer-lavf-probe-info")!)
|
|
|
|
}
|
2024-05-23 15:23:41 +05:30
|
|
|
#elseif os(macOS)
|
2024-05-23 22:32:13 +05:30
|
|
|
.onTapGesture {
|
|
|
|
NSWorkspace.shared.open(URL(string: "https://mpv.io/manual/stable/#options-demuxer-lavf-probe-info")!)
|
|
|
|
}
|
2024-05-23 15:23:41 +05:30
|
|
|
.onHover(perform: onHover(_:))
|
2024-05-22 22:12:08 +05:30
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
Picker("", selection: $mpvDemuxerLavfProbeInfo) {
|
|
|
|
ForEach(["yes", "no", "auto", "nostreams"], id: \.self) {
|
|
|
|
Text($0)
|
|
|
|
}
|
|
|
|
}
|
2024-05-23 15:23:41 +05:30
|
|
|
#if !os(tvOS)
|
2024-05-22 22:12:08 +05:30
|
|
|
.pickerStyle(MenuPickerStyle())
|
2024-05-23 15:23:41 +05:30
|
|
|
#endif
|
2024-05-22 22:12:08 +05:30
|
|
|
}
|
|
|
|
|
2022-07-07 03:38:38 +05:30
|
|
|
if mpvEnableLogging {
|
|
|
|
logButton
|
|
|
|
}
|
2022-07-02 16:19:57 +05:30
|
|
|
}
|
2022-12-10 07:31:59 +05:30
|
|
|
|
2022-12-13 16:39:20 +05:30
|
|
|
Section(header: SettingsHeader(text: "Cache"), footer: cacheSize) {
|
|
|
|
showCacheStatusToggle
|
|
|
|
feedCacheSizeTextField
|
2022-12-10 07:31:59 +05:30
|
|
|
clearCacheButton
|
|
|
|
}
|
2022-07-02 16:19:57 +05:30
|
|
|
}
|
2022-07-02 02:58:32 +05:30
|
|
|
|
2022-07-02 16:19:57 +05:30
|
|
|
@ViewBuilder var mpvFooter: some View {
|
2024-05-19 07:17:05 +05:30
|
|
|
let url = "https://mpv.io/manual/stable/"
|
2022-07-04 02:02:26 +05:30
|
|
|
|
2022-07-02 16:19:57 +05:30
|
|
|
VStack(alignment: .leading) {
|
|
|
|
Text("Restart the app to apply the settings above.")
|
2024-05-19 07:17:05 +05:30
|
|
|
.padding(.bottom, 1)
|
2022-07-04 02:02:26 +05:30
|
|
|
VStack(alignment: .leading, spacing: 2) {
|
|
|
|
#if os(tvOS)
|
2024-05-19 07:17:05 +05:30
|
|
|
Text("More info can be found in MPV reference manual:")
|
2022-07-04 02:02:26 +05:30
|
|
|
Text(url)
|
|
|
|
#else
|
2024-05-19 07:17:05 +05:30
|
|
|
Text("Further information can be found in the ")
|
|
|
|
+ Text("MPV reference manual").underline().bold()
|
|
|
|
+ Text(" by clicking on the link icon next to the option.")
|
2022-07-04 02:02:26 +05:30
|
|
|
#endif
|
2022-07-02 16:19:57 +05:30
|
|
|
}
|
2022-07-02 02:58:32 +05:30
|
|
|
}
|
2022-07-02 16:19:57 +05:30
|
|
|
.foregroundColor(.secondary)
|
2022-07-02 02:58:32 +05:30
|
|
|
}
|
|
|
|
|
2023-05-27 02:19:38 +05:30
|
|
|
var showPlayNowInBackendButtonsToggle: some View {
|
|
|
|
Toggle("Show video context menu options to force selected backend", isOn: $showPlayNowInBackendContextMenu)
|
|
|
|
}
|
|
|
|
|
2022-07-02 02:58:32 +05:30
|
|
|
var showMPVPlaybackStatsToggle: some View {
|
2022-07-02 16:19:57 +05:30
|
|
|
Toggle("Show playback statistics", isOn: $showMPVPlaybackStats)
|
2022-07-02 02:58:32 +05:30
|
|
|
}
|
2022-07-04 02:02:26 +05:30
|
|
|
|
2022-07-07 03:38:38 +05:30
|
|
|
var mpvEnableLoggingToggle: some View {
|
|
|
|
Toggle("Enable logging", isOn: $mpvEnableLogging)
|
|
|
|
}
|
|
|
|
|
2022-07-04 02:02:26 +05:30
|
|
|
#if os(macOS)
|
|
|
|
private func onHover(_ inside: Bool) {
|
|
|
|
if inside {
|
|
|
|
NSCursor.pointingHand.push()
|
|
|
|
} else {
|
|
|
|
NSCursor.pop()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2022-11-12 00:25:18 +05:30
|
|
|
|
2022-12-13 16:39:20 +05:30
|
|
|
private var feedCacheSizeTextField: some View {
|
|
|
|
HStack {
|
|
|
|
Text("Maximum feed items")
|
|
|
|
.frame(minWidth: 200, alignment: .leading)
|
2023-04-23 02:40:05 +05:30
|
|
|
.multilineTextAlignment(.leading)
|
2022-12-13 16:39:20 +05:30
|
|
|
TextField("Limit", text: $feedCacheSize)
|
2023-04-23 02:40:05 +05:30
|
|
|
.multilineTextAlignment(.trailing)
|
2022-12-13 16:39:20 +05:30
|
|
|
#if !os(macOS)
|
|
|
|
.keyboardType(.numberPad)
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private var showCacheStatusToggle: some View {
|
|
|
|
Toggle("Show cache status", isOn: $showCacheStatus)
|
|
|
|
}
|
|
|
|
|
2022-12-10 07:31:59 +05:30
|
|
|
private var clearCacheButton: some View {
|
2022-11-12 00:25:18 +05:30
|
|
|
Button {
|
2022-12-10 07:31:59 +05:30
|
|
|
settings.presentAlert(
|
|
|
|
Alert(
|
|
|
|
title: Text(
|
|
|
|
"Are you sure you want to clear cache?"
|
|
|
|
),
|
2022-12-12 14:51:46 +05:30
|
|
|
primaryButton: .destructive(Text("Clear"), action: BaseCacheModel.shared.clear),
|
2022-12-10 07:31:59 +05:30
|
|
|
secondaryButton: .cancel()
|
|
|
|
)
|
|
|
|
)
|
2022-11-12 00:25:18 +05:30
|
|
|
} label: {
|
2022-12-10 07:31:59 +05:30
|
|
|
Text("Clear all")
|
|
|
|
.foregroundColor(.red)
|
2022-11-12 00:25:18 +05:30
|
|
|
}
|
|
|
|
}
|
2022-12-10 07:31:59 +05:30
|
|
|
|
|
|
|
var cacheSize: some View {
|
2023-04-23 02:40:05 +05:30
|
|
|
Text(String(format: "Total size: %@".localized(), BaseCacheModel.shared.totalSizeFormatted))
|
2022-12-10 07:31:59 +05:30
|
|
|
.foregroundColor(.secondary)
|
|
|
|
}
|
2022-07-02 02:58:32 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
struct AdvancedSettings_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
AdvancedSettings()
|
2022-11-12 00:25:18 +05:30
|
|
|
.injectFixtureEnvironmentObjects()
|
2022-07-02 02:58:32 +05:30
|
|
|
}
|
|
|
|
}
|