1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-14 14:20:32 +05:30
yattee/Shared/Settings/AdvancedSettings.swift

146 lines
4.5 KiB
Swift
Raw Normal View History

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
2022-07-07 03:38:38 +05:30
@Default(.mpvEnableLogging) private var mpvEnableLogging
2022-11-12 00:25:18 +05:30
@Default(.countryOfPublicInstances) private var countryOfPublicInstances
@Default(.instances) private var instances
2022-07-07 03:38:38 +05:30
2022-11-12 00:25:18 +05:30
@State private var countries = [String]()
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 presentingInstanceForm = false
@State private var presentingShareSheet = false
@State private var savedFormInstanceID: Instance.ID?
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)")
}
.listStyle(.insetGrouped)
#endif
#endif
}
2022-11-12 00:25:18 +05:30
.onChange(of: countryOfPublicInstances) { newCountry in
InstancesManifest.shared.setPublicAccount(newCountry, asCurrent: AccountsModel.shared.current?.isPublic ?? true)
2022-11-12 00:25:18 +05:30
}
.sheet(isPresented: $presentingInstanceForm) {
InstanceForm(savedInstanceID: $savedFormInstanceID)
}
#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)
}
}
@ViewBuilder var advancedSettings: some View {
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
HStack {
Text("cache-secs")
2022-07-04 02:02:26 +05:30
.frame(minWidth: 140, alignment: .leading)
2022-07-02 16:19:57 +05:30
TextField("cache-secs", text: $mpvCacheSecs)
}
2022-07-04 02:02:26 +05:30
.multilineTextAlignment(.trailing)
2022-07-02 16:19:57 +05:30
HStack {
Text("cache-pause-wait")
2022-07-04 02:02:26 +05:30
.frame(minWidth: 140, alignment: .leading)
2022-07-02 16:19:57 +05:30
TextField("cache-pause-wait", text: $mpvCachePauseWait)
}
2022-07-04 02:02:26 +05:30
.multilineTextAlignment(.trailing)
2022-07-07 03:38:38 +05:30
if mpvEnableLogging {
logButton
}
2022-07-02 16:19:57 +05:30
}
}
2022-07-02 16:19:57 +05:30
@ViewBuilder var mpvFooter: some View {
2022-07-04 02:02:26 +05:30
let url = "https://mpv.io/manual/master"
2022-07-02 16:19:57 +05:30
VStack(alignment: .leading) {
Text("Restart the app to apply the settings above.")
2022-07-04 02:02:26 +05:30
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 16:19:57 +05:30
}
}
2022-07-02 16:19:57 +05:30
.foregroundColor(.secondary)
}
var showMPVPlaybackStatsToggle: some View {
2022-07-02 16:19:57 +05:30
Toggle("Show playback statistics", isOn: $showMPVPlaybackStats)
}
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
private var addInstanceButton: some View {
Button {
presentingInstanceForm = true
} label: {
Label("Add Location...", systemImage: "plus")
}
}
}
struct AdvancedSettings_Previews: PreviewProvider {
static var previews: some View {
AdvancedSettings()
2022-11-12 00:25:18 +05:30
.injectFixtureEnvironmentObjects()
}
}