Fix build issues

This commit is contained in:
Arkadiusz Fal
2024-05-16 18:53:47 +02:00
parent b783db30b6
commit 4ce9dc6729
10 changed files with 120 additions and 81 deletions

View File

@@ -3,7 +3,6 @@ import Foundation
import SwiftUI
enum Constants {
static let yatteeProtocol = "yattee://"
static let overlayAnimation = Animation.linear(duration: 0.2)
static var isAppleTV: Bool {
@@ -98,6 +97,20 @@ enum Constants {
#endif
}
static var defaultNavigationStyle: NavigationStyle {
#if os(macOS)
return .sidebar
#elseif os(iOS)
if isIPad {
return .sidebar
} else {
return .tab
}
#else
return .tab
#endif
}
static func seekIcon(_ type: String, _ interval: TimeInterval) -> String {
let interval = Int(interval)
let allVersions = [10, 15, 30, 45, 60, 75, 90]

View File

@@ -4,8 +4,6 @@ import Siesta
struct OpenURLHandler {
static var firstHandle = true
static let yatteeProtocol = "yattee://"
var accounts: AccountsModel { .shared }
var navigation: NavigationModel { .shared }
var recents: RecentsModel { .shared }

View File

@@ -1,6 +1,8 @@
import Defaults
import SwiftUI
import UIKit
#if canImport(UIKit)
import UIKit
#endif
struct SponsorBlockSettings: View {
@ObservedObject private var settings = SettingsModel.shared
@@ -55,24 +57,27 @@ struct SponsorBlockSettings: View {
Section(header: SettingsHeader(text: "Categories to Skip".localized())) {
categoryRows
}
colorSection
Button {
settings.presentAlert(
Alert(
title: Text("Restore Default Colors?"),
message: Text("This action will reset all custom colors back to their original defaults. " +
"Any custom color changes you've made will be lost."),
primaryButton: .destructive(Text("Restore")) {
resetColors()
},
secondaryButton: .cancel()
#if os(iOS)
colorSection
Button {
settings.presentAlert(
Alert(
title: Text("Restore Default Colors?"),
message: Text("This action will reset all custom colors back to their original defaults. " +
"Any custom color changes you've made will be lost."),
primaryButton: .destructive(Text("Restore")) {
resetColors()
},
secondaryButton: .cancel()
)
)
)
} label: {
Text("Restore Default Colors …")
.foregroundColor(.red)
}
} label: {
Text("Restore Default Colors …")
.foregroundColor(.red)
}
#endif
Section(footer: categoriesDetails) {
EmptyView()
@@ -80,21 +85,23 @@ struct SponsorBlockSettings: View {
}
}
private var colorSection: some View {
Section(header: SettingsHeader(text: "Colors for Categories")) {
ForEach(SponsorBlockAPI.categories, id: \.self) { category in
LazyVStack(alignment: .leading) {
ColorPicker(
SponsorBlockAPI.categoryDescription(category) ?? "Unknown",
selection: Binding(
get: { getColor(for: category) },
set: { setColor($0, for: category) }
#if os(iOS)
private var colorSection: some View {
Section(header: SettingsHeader(text: "Colors for Categories")) {
ForEach(SponsorBlockAPI.categories, id: \.self) { category in
LazyVStack(alignment: .leading) {
ColorPicker(
SponsorBlockAPI.categoryDescription(category) ?? "Unknown",
selection: Binding(
get: { getColor(for: category) },
set: { setColor($0, for: category) }
)
)
)
}
}
}
}
}
#endif
private var categoryRows: some View {
ForEach(SponsorBlockAPI.categories, id: \.self) { category in
@@ -145,25 +152,27 @@ struct SponsorBlockSettings: View {
return Color("AppRedColor") // Fallback color if no match found
}
private func setColor(_ color: Color, for category: String) {
let uiColor = UIColor(color)
#if canImport(UIKit)
private func setColor(_ color: Color, for category: String) {
let uiColor = UIColor(color)
// swiftlint:disable no_cgfloat
var red: CGFloat = 0
var green: CGFloat = 0
var blue: CGFloat = 0
var alpha: CGFloat = 0
// swiftlint:enable no_cgfloat
// swiftlint:disable no_cgfloat
var red: CGFloat = 0
var green: CGFloat = 0
var blue: CGFloat = 0
var alpha: CGFloat = 0
// swiftlint:enable no_cgfloat
uiColor.getRed(&red, green: &green, blue: &blue, alpha: &alpha)
uiColor.getRed(&red, green: &green, blue: &blue, alpha: &alpha)
let r = Int(red * 255.0)
let g = Int(green * 255.0)
let b = Int(blue * 255.0)
let r = Int(red * 255.0)
let g = Int(green * 255.0)
let b = Int(blue * 255.0)
let rgbValue = (r << 16) | (g << 8) | b
sponsorBlockColors[category] = String(format: "#%06x", rgbValue)
}
let rgbValue = (r << 16) | (g << 8) | b
sponsorBlockColors[category] = String(format: "#%06x", rgbValue)
}
#endif
private func resetColors() {
sponsorBlockColors = SponsorBlockColors.dictionary

3
Shared/Strings.swift Normal file
View File

@@ -0,0 +1,3 @@
enum Strings {
static let yatteeProtocol = "yattee://"
}

View File

@@ -77,7 +77,7 @@ struct ShareButton<LabelView: View>: View {
private var youtubeActions: some View {
Group {
if let url = accounts.api.shareURL(contentItem, frontendURL: "https://www.youtube.com") {
if let url = accounts.api.shareURL(contentItem, frontendURLString: "https://www.youtube.com") {
Button(labelForShareURL("YouTube")) {
shareAction(url)
}
@@ -87,7 +87,7 @@ struct ShareButton<LabelView: View>: View {
shareAction(
accounts.api.shareURL(
contentItem,
frontendURL: "https://www.youtube.com",
frontendURLString: "https://www.youtube.com",
time: player.backend.currentTime
)!
)