slide to seek and searchbar fix (#255)
Some checks failed
Build and Release / Build IPA (push) Has been cancelled
Build and Release / Build macOS App (push) Has been cancelled

This commit is contained in:
Mousica 2025-11-28 18:33:59 +02:00 committed by GitHub
parent 611646902c
commit 0361eb9aed
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 115 additions and 42 deletions

View file

@ -25,7 +25,7 @@ struct CircularProgressBar: View {
.animation(.linear, value: progress)
let remainingTimePercentage = UserDefaults.standard.object(forKey: "remainingTimePercentage") != nil ? UserDefaults.standard.double(forKey: "remainingTimePercentage") : 90.0
let threshold = (100.0 - remainingTimePercentage) / 100.0
let threshold = remainingTimePercentage / 100.0
if progress >= threshold {
Image(systemName: "checkmark")

View file

@ -223,7 +223,7 @@ private extension EpisodeCell {
}
.tint(.blue)
if progress <= remainingTimePercentage {
if progress >= remainingTimePercentage / 100.0 {
Button(action: { markAsWatched() }) {
Label("Watched", systemImage: "checkmark.circle")
}
@ -325,7 +325,7 @@ private extension EpisodeCell {
var contextMenuContent: some View {
Group {
if progress <= remainingTimePercentage {
if progress >= remainingTimePercentage / 100.0 {
Button(action: markAsWatched) {
Label("Mark Episode as Watched", systemImage: "checkmark.circle")
}

View file

@ -40,6 +40,7 @@ struct SearchView: View {
@State private var saveDebounceTimer: Timer?
@State private var searchDebounceTimer: Timer?
@State private var isActive: Bool = false
@State private var currentSearchTask: Task<Void, Never>?
init(searchQuery: Binding<String>) {
self._searchQuery = searchQuery
@ -247,37 +248,57 @@ struct SearchView: View {
isSearchFieldFocused = false
currentSearchTask?.cancel()
currentSearchTask = nil
isSearching = true
hasNoResults = false
searchItems = []
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
Task {
currentSearchTask = Task {
do {
try await Task.sleep(nanoseconds: 500_000_000) // 0.5 seconds
guard !Task.isCancelled else { return }
let jsContent = try moduleManager.getModuleContent(module)
jsController.loadScript(jsContent)
guard !Task.isCancelled else { return }
if module.metadata.asyncJS == true {
jsController.fetchJsSearchResults(keyword: searchQuery, module: module) { items in
guard !Task.isCancelled else { return }
DispatchQueue.main.async {
searchItems = items
hasNoResults = items.isEmpty
let uniqueItems = items.reduce(into: [String: SearchItem]()) { dict, item in
dict[item.href] = item
}.values
searchItems = Array(uniqueItems)
hasNoResults = uniqueItems.isEmpty
isSearching = false
currentSearchTask = nil
}
}
} else {
jsController.fetchSearchResults(keyword: searchQuery, module: module) { items in
guard !Task.isCancelled else { return }
DispatchQueue.main.async {
searchItems = items
hasNoResults = items.isEmpty
let uniqueItems = items.reduce(into: [String: SearchItem]()) { dict, item in
dict[item.href] = item
}.values
searchItems = Array(uniqueItems)
hasNoResults = uniqueItems.isEmpty
isSearching = false
currentSearchTask = nil
}
}
}
} catch {
if !Task.isCancelled {
Logger.shared.log("Error loading module: \(error)", type: "Error")
DispatchQueue.main.async {
isSearching = false
hasNoResults = true
currentSearchTask = nil
}
}
}

View file

@ -192,6 +192,59 @@ fileprivate struct SettingsStepperRow: View {
}
}
fileprivate struct SettingsTextFieldRow: View {
let icon: String
let title: String
@Binding var value: Double
let range: ClosedRange<Double>
var showDivider: Bool = true
init(icon: String, title: String, value: Binding<Double>, range: ClosedRange<Double>, showDivider: Bool = true) {
self.icon = icon
self.title = title
self._value = value
self.range = range
self.showDivider = showDivider
}
var body: some View {
VStack(spacing: 0) {
HStack {
Image(systemName: icon)
.frame(width: 24, height: 24)
.foregroundStyle(.primary)
Text(title)
.foregroundStyle(.primary)
Spacer()
TextField("", value: $value, format: .number)
.keyboardType(.decimalPad)
.multilineTextAlignment(.trailing)
.frame(width: 60)
.onChange(of: value) { newValue in
if newValue < range.lowerBound {
value = range.lowerBound
} else if newValue > range.upperBound {
value = range.upperBound
}
}
Text("%")
.foregroundStyle(.gray)
}
.padding(.horizontal, 16)
.padding(.vertical, 12)
if showDivider {
Divider()
.padding(.horizontal, 16)
}
}
}
}
struct SettingsViewPlayer: View {
@AppStorage("externalPlayer") private var externalPlayer: String = "Sora"
@AppStorage("alwaysLandscape") private var isAlwaysLandscape = false
@ -247,12 +300,11 @@ struct SettingsViewPlayer: View {
showDivider: true
)
SettingsPickerRow(
SettingsTextFieldRow(
icon: "timer",
title: NSLocalizedString("Completion Percentage", comment: ""),
options: [60.0, 70.0, 80.0, 90.0, 95.0, 100.0],
optionToString: { "\(Int($0))%" },
selection: $remainingTimePercentage,
value: $remainingTimePercentage,
range: 0...100,
showDivider: false
)
}