2022-07-01 21:28:32 +00:00
|
|
|
import Defaults
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct AdvancedSettings: View {
|
|
|
|
@Default(.showMPVPlaybackStats) private var showMPVPlaybackStats
|
2022-07-02 10:49:57 +00:00
|
|
|
@Default(.mpvCacheSecs) private var mpvCacheSecs
|
|
|
|
@Default(.mpvCachePauseWait) private var mpvCachePauseWait
|
2024-02-02 08:43:46 +00:00
|
|
|
@Default(.mpvDeinterlace) private var mpvDeinterlace
|
2022-07-06 22:08:38 +00:00
|
|
|
@Default(.mpvEnableLogging) private var mpvEnableLogging
|
2022-12-13 11:09:20 +00:00
|
|
|
@Default(.showCacheStatus) private var showCacheStatus
|
|
|
|
@Default(.feedCacheSize) private var feedCacheSize
|
2023-05-26 20:49:38 +00:00
|
|
|
@Default(.showPlayNowInBackendContextMenu) private var showPlayNowInBackendContextMenu
|
2022-07-06 22:08:38 +00:00
|
|
|
|
|
|
|
@State private var filesToShare = [MPVClient.logFile]
|
2022-11-11 18:55:18 +00:00
|
|
|
@State private var presentingShareSheet = false
|
2022-12-10 02:01:59 +00:00
|
|
|
|
|
|
|
private var settings = SettingsModel.shared
|
2022-07-01 21:28:32 +00:00
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
VStack(alignment: .leading) {
|
|
|
|
#if os(macOS)
|
|
|
|
advancedSettings
|
|
|
|
Spacer()
|
|
|
|
#else
|
|
|
|
List {
|
|
|
|
advancedSettings
|
|
|
|
}
|
|
|
|
#if os(iOS)
|
2022-07-06 22:08:38 +00:00
|
|
|
.sheet(isPresented: $presentingShareSheet) {
|
|
|
|
ShareSheet(activityItems: filesToShare)
|
|
|
|
.id("logs-\(filesToShare.count)")
|
|
|
|
}
|
2022-07-01 21:28:32 +00:00
|
|
|
.listStyle(.insetGrouped)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#if os(tvOS)
|
|
|
|
.frame(maxWidth: 1000)
|
|
|
|
#endif
|
|
|
|
.navigationTitle("Advanced")
|
|
|
|
}
|
|
|
|
|
2022-07-06 22:08:38 +00:00
|
|
|
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 16:49:47 +00:00
|
|
|
let labelText = "Open logs in Finder".localized()
|
2022-07-06 22:08:38 +00:00
|
|
|
#else
|
2022-10-12 16:49:47 +00:00
|
|
|
let labelText = "Share Logs...".localized()
|
2022-07-06 22:08:38 +00:00
|
|
|
#endif
|
|
|
|
Text(labelText)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-01 21:28:32 +00:00
|
|
|
@ViewBuilder var advancedSettings: some View {
|
2023-05-26 20:49:38 +00:00
|
|
|
Section(header: SettingsHeader(text: "Advanced")) {
|
|
|
|
showPlayNowInBackendButtonsToggle
|
|
|
|
}
|
|
|
|
|
2022-07-02 10:49:57 +00:00
|
|
|
Section(header: SettingsHeader(text: "MPV"), footer: mpvFooter) {
|
|
|
|
showMPVPlaybackStatsToggle
|
2022-07-06 22:08:38 +00:00
|
|
|
#if !os(tvOS)
|
|
|
|
mpvEnableLoggingToggle
|
|
|
|
#endif
|
2022-07-02 10:49:57 +00:00
|
|
|
|
|
|
|
HStack {
|
|
|
|
Text("cache-secs")
|
2022-07-03 20:32:26 +00:00
|
|
|
.frame(minWidth: 140, alignment: .leading)
|
2022-07-02 10:49:57 +00:00
|
|
|
TextField("cache-secs", text: $mpvCacheSecs)
|
2022-12-21 20:16:47 +00:00
|
|
|
#if !os(macOS)
|
|
|
|
.keyboardType(.URL)
|
|
|
|
#endif
|
2022-07-02 10:49:57 +00:00
|
|
|
}
|
2022-07-03 20:32:26 +00:00
|
|
|
.multilineTextAlignment(.trailing)
|
2022-07-02 10:49:57 +00:00
|
|
|
|
|
|
|
HStack {
|
|
|
|
Text("cache-pause-wait")
|
2022-07-03 20:32:26 +00:00
|
|
|
.frame(minWidth: 140, alignment: .leading)
|
2022-07-02 10:49:57 +00:00
|
|
|
TextField("cache-pause-wait", text: $mpvCachePauseWait)
|
2022-12-21 20:16:47 +00:00
|
|
|
#if !os(macOS)
|
|
|
|
.keyboardType(.URL)
|
|
|
|
#endif
|
2022-07-02 10:49:57 +00:00
|
|
|
}
|
2022-07-03 20:32:26 +00:00
|
|
|
.multilineTextAlignment(.trailing)
|
2022-07-06 22:08:38 +00:00
|
|
|
|
2024-02-02 08:43:46 +00:00
|
|
|
Toggle("deinterlace", isOn: $mpvDeinterlace)
|
|
|
|
|
2022-07-06 22:08:38 +00:00
|
|
|
if mpvEnableLogging {
|
|
|
|
logButton
|
|
|
|
}
|
2022-07-02 10:49:57 +00:00
|
|
|
}
|
2022-12-10 02:01:59 +00:00
|
|
|
|
2022-12-13 11:09:20 +00:00
|
|
|
Section(header: SettingsHeader(text: "Cache"), footer: cacheSize) {
|
|
|
|
showCacheStatusToggle
|
|
|
|
feedCacheSizeTextField
|
2022-12-10 02:01:59 +00:00
|
|
|
clearCacheButton
|
|
|
|
}
|
2022-07-02 10:49:57 +00:00
|
|
|
}
|
2022-07-01 21:28:32 +00:00
|
|
|
|
2022-07-02 10:49:57 +00:00
|
|
|
@ViewBuilder var mpvFooter: some View {
|
2022-07-03 20:32:26 +00:00
|
|
|
let url = "https://mpv.io/manual/master"
|
|
|
|
|
2022-07-02 10:49:57 +00:00
|
|
|
VStack(alignment: .leading) {
|
|
|
|
Text("Restart the app to apply the settings above.")
|
2022-07-03 20:32:26 +00:00
|
|
|
VStack(alignment: .leading, spacing: 2) {
|
|
|
|
#if os(tvOS)
|
|
|
|
Text("More info can be found in MPV Documentation:")
|
|
|
|
Text(url)
|
|
|
|
#else
|
|
|
|
Text("More info can be found in:")
|
|
|
|
Link("MPV Documentation", destination: URL(string: url)!)
|
|
|
|
#if os(macOS)
|
|
|
|
.onHover(perform: onHover(_:))
|
|
|
|
#endif
|
|
|
|
#endif
|
2022-07-02 10:49:57 +00:00
|
|
|
}
|
2022-07-01 21:28:32 +00:00
|
|
|
}
|
2022-07-02 10:49:57 +00:00
|
|
|
.foregroundColor(.secondary)
|
2022-07-01 21:28:32 +00:00
|
|
|
}
|
|
|
|
|
2023-05-26 20:49:38 +00:00
|
|
|
var showPlayNowInBackendButtonsToggle: some View {
|
|
|
|
Toggle("Show video context menu options to force selected backend", isOn: $showPlayNowInBackendContextMenu)
|
|
|
|
}
|
|
|
|
|
2022-07-01 21:28:32 +00:00
|
|
|
var showMPVPlaybackStatsToggle: some View {
|
2022-07-02 10:49:57 +00:00
|
|
|
Toggle("Show playback statistics", isOn: $showMPVPlaybackStats)
|
2022-07-01 21:28:32 +00:00
|
|
|
}
|
2022-07-03 20:32:26 +00:00
|
|
|
|
2022-07-06 22:08:38 +00:00
|
|
|
var mpvEnableLoggingToggle: some View {
|
|
|
|
Toggle("Enable logging", isOn: $mpvEnableLogging)
|
|
|
|
}
|
|
|
|
|
2022-07-03 20:32:26 +00:00
|
|
|
#if os(macOS)
|
|
|
|
private func onHover(_ inside: Bool) {
|
|
|
|
if inside {
|
|
|
|
NSCursor.pointingHand.push()
|
|
|
|
} else {
|
|
|
|
NSCursor.pop()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2022-11-11 18:55:18 +00:00
|
|
|
|
2022-12-13 11:09:20 +00:00
|
|
|
private var feedCacheSizeTextField: some View {
|
|
|
|
HStack {
|
|
|
|
Text("Maximum feed items")
|
|
|
|
.frame(minWidth: 200, alignment: .leading)
|
2023-04-22 21:10:05 +00:00
|
|
|
.multilineTextAlignment(.leading)
|
2022-12-13 11:09:20 +00:00
|
|
|
TextField("Limit", text: $feedCacheSize)
|
2023-04-22 21:10:05 +00:00
|
|
|
.multilineTextAlignment(.trailing)
|
2022-12-13 11:09:20 +00:00
|
|
|
#if !os(macOS)
|
|
|
|
.keyboardType(.numberPad)
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private var showCacheStatusToggle: some View {
|
|
|
|
Toggle("Show cache status", isOn: $showCacheStatus)
|
|
|
|
}
|
|
|
|
|
2022-12-10 02:01:59 +00:00
|
|
|
private var clearCacheButton: some View {
|
2022-11-11 18:55:18 +00:00
|
|
|
Button {
|
2022-12-10 02:01:59 +00:00
|
|
|
settings.presentAlert(
|
|
|
|
Alert(
|
|
|
|
title: Text(
|
|
|
|
"Are you sure you want to clear cache?"
|
|
|
|
),
|
2022-12-12 09:21:46 +00:00
|
|
|
primaryButton: .destructive(Text("Clear"), action: BaseCacheModel.shared.clear),
|
2022-12-10 02:01:59 +00:00
|
|
|
secondaryButton: .cancel()
|
|
|
|
)
|
|
|
|
)
|
2022-11-11 18:55:18 +00:00
|
|
|
} label: {
|
2022-12-10 02:01:59 +00:00
|
|
|
Text("Clear all")
|
|
|
|
.foregroundColor(.red)
|
2022-11-11 18:55:18 +00:00
|
|
|
}
|
|
|
|
}
|
2022-12-10 02:01:59 +00:00
|
|
|
|
|
|
|
var cacheSize: some View {
|
2023-04-22 21:10:05 +00:00
|
|
|
Text(String(format: "Total size: %@".localized(), BaseCacheModel.shared.totalSizeFormatted))
|
2022-12-10 02:01:59 +00:00
|
|
|
.foregroundColor(.secondary)
|
|
|
|
}
|
2022-07-01 21:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct AdvancedSettings_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
AdvancedSettings()
|
2022-11-11 18:55:18 +00:00
|
|
|
.injectFixtureEnvironmentObjects()
|
2022-07-01 21:28:32 +00:00
|
|
|
}
|
|
|
|
}
|