Fix swiftformat offenses

This commit is contained in:
Arkadiusz Fal 2024-05-23 11:44:58 +02:00
parent e53985534e
commit 934bd65752
3 changed files with 146 additions and 146 deletions

View File

@ -11,16 +11,16 @@ struct ControlsOverlay: View {
@Default(.qualityProfiles) private var qualityProfiles @Default(.qualityProfiles) private var qualityProfiles
#if os(tvOS) #if os(tvOS)
enum Field: Hashable { enum Field: Hashable {
case qualityProfile case qualityProfile
case stream case stream
case increaseRate case increaseRate
case decreaseRate case decreaseRate
case captions case captions
} }
@FocusState private var focusedField: Field? @FocusState private var focusedField: Field?
@State private var presentingButtonHintAlert = false @State private var presentingButtonHintAlert = false
#endif #endif
var body: some View { var body: some View {
@ -94,10 +94,10 @@ struct ControlsOverlay: View {
#endif #endif
#if os(tvOS) #if os(tvOS)
Text("Press and hold remote button to open captions and quality menus") Text("Press and hold remote button to open captions and quality menus")
.frame(maxWidth: 400) .frame(maxWidth: 400)
.font(.caption) .font(.caption)
.foregroundColor(.secondary) .foregroundColor(.secondary)
#endif #endif
} }
.frame(maxHeight: overlayHeight) .frame(maxHeight: overlayHeight)
@ -117,9 +117,9 @@ struct ControlsOverlay: View {
private var overlayHeight: Double { private var overlayHeight: Double {
#if os(tvOS) #if os(tvOS)
contentSize.height + 80.0 contentSize.height + 80.0
#else #else
contentSize.height contentSize.height
#endif #endif
} }
@ -160,26 +160,26 @@ struct ControlsOverlay: View {
@ViewBuilder private var rateButton: some View { @ViewBuilder private var rateButton: some View {
#if os(macOS) #if os(macOS)
ratePicker
.labelsHidden()
.frame(maxWidth: 100)
#elseif os(iOS)
Menu {
ratePicker ratePicker
} label: { .labelsHidden()
Text(player.rateLabel(player.currentRate)) .frame(maxWidth: 100)
.foregroundColor(.primary) #elseif os(iOS)
.frame(width: 123) Menu {
} ratePicker
.transaction { t in t.animation = .none } } label: {
.buttonStyle(.plain) Text(player.rateLabel(player.currentRate))
.foregroundColor(.primary) .foregroundColor(.primary)
.frame(width: 123, height: 40) .frame(width: 123)
.modifier(ControlBackgroundModifier()) }
.mask(RoundedRectangle(cornerRadius: 3)) .transaction { t in t.animation = .none }
.buttonStyle(.plain)
.foregroundColor(.primary)
.frame(width: 123, height: 40)
.modifier(ControlBackgroundModifier())
.mask(RoundedRectangle(cornerRadius: 3))
#else #else
Text(player.rateLabel(player.currentRate)) Text(player.rateLabel(player.currentRate))
.frame(minWidth: 120) .frame(minWidth: 120)
#endif #endif
} }
@ -241,50 +241,50 @@ struct ControlsOverlay: View {
private var rateButtonsSpacing: Double { private var rateButtonsSpacing: Double {
#if os(tvOS) #if os(tvOS)
10 10
#else #else
8 8
#endif #endif
} }
@ViewBuilder private var qualityProfileButton: some View { @ViewBuilder private var qualityProfileButton: some View {
#if os(macOS) #if os(macOS)
qualityProfilePicker
.labelsHidden()
.frame(maxWidth: 300)
#elseif os(iOS)
Menu {
qualityProfilePicker qualityProfilePicker
} label: { .labelsHidden()
Text(player.qualityProfileSelection?.description ?? "Automatic".localized()) .frame(maxWidth: 300)
.frame(maxWidth: 240) #elseif os(iOS)
} Menu {
.transaction { t in t.animation = .none } qualityProfilePicker
.buttonStyle(.plain) } label: {
.foregroundColor(.primary) Text(player.qualityProfileSelection?.description ?? "Automatic".localized())
.frame(maxWidth: 240) .frame(maxWidth: 240)
.frame(height: 40) }
.modifier(ControlBackgroundModifier()) .transaction { t in t.animation = .none }
.mask(RoundedRectangle(cornerRadius: 3)) .buttonStyle(.plain)
#else .foregroundColor(.primary)
ControlsOverlayButton(focusedField: $focusedField, field: .qualityProfile) { .frame(maxWidth: 240)
Text(player.qualityProfileSelection?.description ?? "Automatic".localized()) .frame(height: 40)
.lineLimit(1) .modifier(ControlBackgroundModifier())
.frame(maxWidth: 320) .mask(RoundedRectangle(cornerRadius: 3))
} #else
.contextMenu { ControlsOverlayButton(focusedField: $focusedField, field: .qualityProfile) {
Button("Automatic") { player.qualityProfileSelection = nil } Text(player.qualityProfileSelection?.description ?? "Automatic".localized())
.lineLimit(1)
ForEach(qualityProfiles) { qualityProfile in .frame(maxWidth: 320)
Button { }
player.qualityProfileSelection = qualityProfile .contextMenu {
} label: { Button("Automatic") { player.qualityProfileSelection = nil }
Text(qualityProfile.description)
} ForEach(qualityProfiles) { qualityProfile in
Button {
Button("Cancel", role: .cancel) {} player.qualityProfileSelection = qualityProfile
} label: {
Text(qualityProfile.description)
}
Button("Cancel", role: .cancel) {}
}
} }
}
#endif #endif
} }
@ -300,91 +300,91 @@ struct ControlsOverlay: View {
@ViewBuilder private var qualityButton: some View { @ViewBuilder private var qualityButton: some View {
#if os(macOS) #if os(macOS)
StreamControl()
.labelsHidden()
.frame(maxWidth: 300)
#elseif os(iOS)
Menu {
StreamControl() StreamControl()
} label: { .labelsHidden()
Text(player.streamSelection?.resolutionAndFormat ?? "loading") .frame(maxWidth: 300)
.frame(width: 140, height: 40) #elseif os(iOS)
.foregroundColor(.primary) Menu {
} StreamControl()
.transaction { t in t.animation = .none } } label: {
.buttonStyle(.plain) Text(player.streamSelection?.resolutionAndFormat ?? "loading")
.foregroundColor(.primary) .frame(width: 140, height: 40)
.frame(width: 240, height: 40) .foregroundColor(.primary)
.modifier(ControlBackgroundModifier()) }
.mask(RoundedRectangle(cornerRadius: 3)) .transaction { t in t.animation = .none }
.buttonStyle(.plain)
.foregroundColor(.primary)
.frame(width: 240, height: 40)
.modifier(ControlBackgroundModifier())
.mask(RoundedRectangle(cornerRadius: 3))
#else #else
StreamControl(focusedField: $focusedField) StreamControl(focusedField: $focusedField)
#endif #endif
} }
@ViewBuilder private var captionsButton: some View { @ViewBuilder private var captionsButton: some View {
#if os(macOS) #if os(macOS)
captionsPicker
.labelsHidden()
.frame(maxWidth: 300)
#elseif os(iOS)
Menu {
captionsPicker captionsPicker
} label: { .labelsHidden()
HStack(spacing: 4) { .frame(maxWidth: 300)
Image(systemName: "text.bubble") #elseif os(iOS)
if let captions = captionsBinding.wrappedValue, Menu {
let language = LanguageCodes(rawValue: captions.code) captionsPicker
} label: {
HStack(spacing: 4) {
Image(systemName: "text.bubble")
if let captions = captionsBinding.wrappedValue,
let language = LanguageCodes(rawValue: captions.code)
{ {
Text("\(language.description.capitalized) (\(language.rawValue))") Text("\(language.description.capitalized) (\(language.rawValue))")
.foregroundColor(.accentColor)
} else {
if captionsBinding.wrappedValue == nil {
Text("Not available")
} else {
Text("Disabled")
.foregroundColor(.accentColor) .foregroundColor(.accentColor)
} else {
if captionsBinding.wrappedValue == nil {
Text("Not available")
} else {
Text("Disabled")
.foregroundColor(.accentColor)
}
} }
} }
.frame(width: 240)
.frame(height: 40)
} }
.transaction { t in t.animation = .none }
.buttonStyle(.plain)
.foregroundColor(.primary)
.frame(width: 240) .frame(width: 240)
.frame(height: 40) .modifier(ControlBackgroundModifier())
} .mask(RoundedRectangle(cornerRadius: 3))
.transaction { t in t.animation = .none }
.buttonStyle(.plain)
.foregroundColor(.primary)
.frame(width: 240)
.modifier(ControlBackgroundModifier())
.mask(RoundedRectangle(cornerRadius: 3))
#else #else
ControlsOverlayButton(focusedField: $focusedField, field: .captions) { ControlsOverlayButton(focusedField: $focusedField, field: .captions) {
HStack(spacing: 8) { HStack(spacing: 8) {
Image(systemName: "text.bubble") Image(systemName: "text.bubble")
if let captions = captionsBinding.wrappedValue, if let captions = captionsBinding.wrappedValue,
let language = LanguageCodes(rawValue: captions.code) let language = LanguageCodes(rawValue: captions.code)
{ {
Text("\(language.description.capitalized) (\(language.rawValue))") Text("\(language.description.capitalized) (\(language.rawValue))")
.foregroundColor(.accentColor)
} else {
if captionsBinding.wrappedValue == nil {
Text("Not available")
} else {
Text("Disabled")
.foregroundColor(.accentColor) .foregroundColor(.accentColor)
} else {
if captionsBinding.wrappedValue == nil {
Text("Not available")
} else {
Text("Disabled")
.foregroundColor(.accentColor)
}
} }
} }
.frame(maxWidth: 320)
} }
.frame(maxWidth: 320) .contextMenu {
} Button("Disabled") { captionsBinding.wrappedValue = nil }
.contextMenu {
Button("Disabled") { captionsBinding.wrappedValue = nil }
ForEach(player.currentVideo?.captions ?? []) { caption in ForEach(player.currentVideo?.captions ?? []) { caption in
Button(caption.description) { captionsBinding.wrappedValue = caption } Button(caption.description) { captionsBinding.wrappedValue = caption }
}
Button("Cancel", role: .cancel) {}
} }
Button("Cancel", role: .cancel) {}
}
#endif #endif
} }

View File

@ -1,6 +1,6 @@
import Logging import Logging
#if !os(tvOS) #if !os(tvOS)
import WebKit import WebKit
#endif #endif
final class UserAgentManager { final class UserAgentManager {
@ -8,7 +8,7 @@ final class UserAgentManager {
private(set) var userAgent: String private(set) var userAgent: String
#if !os(tvOS) #if !os(tvOS)
private var webView: WKWebView? private var webView: WKWebView?
#endif #endif
private init() { private init() {
@ -19,19 +19,19 @@ final class UserAgentManager {
userAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)" userAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"
#if !os(tvOS) #if !os(tvOS)
webView = WKWebView() webView = WKWebView()
webView?.evaluateJavaScript("navigator.userAgent") { [weak self] result, _ in webView?.evaluateJavaScript("navigator.userAgent") { [weak self] result, _ in
if let userAgent = result as? String { if let userAgent = result as? String {
DispatchQueue.main.async { DispatchQueue.main.async {
self?.userAgent = userAgent self?.userAgent = userAgent
Logger(label: "stream.yattee.userAgentManager").info("User-Agent: \(userAgent)") Logger(label: "stream.yattee.userAgentManager").info("User-Agent: \(userAgent)")
}
} else {
Logger(label: "stream.yattee.userAgentManager").warning("Failed to update User-Agent.")
} }
} else {
Logger(label: "stream.yattee.userAgentManager").warning("Failed to update User-Agent.")
} }
}
#else #else
Logger(label: "stream.yattee.userAgentManager.tvOS").info("User-Agent: \(userAgent)") Logger(label: "stream.yattee.userAgentManager.tvOS").info("User-Agent: \(userAgent)")
#endif #endif
} }
} }