needed improvements
Some checks failed
Build and Release IPA / Build IPA (push) Has been cancelled

This commit is contained in:
cranci1 2025-01-18 21:21:06 +01:00
parent a79a7738f4
commit 3cba82d95a
4 changed files with 34 additions and 11 deletions

View file

@ -23,12 +23,14 @@ struct ScrapingModule: Codable, Identifiable, Hashable {
let id: UUID
let metadata: ModuleMetadata
let localPath: String
let metadataUrl: String
var isActive: Bool
init(id: UUID = UUID(), metadata: ModuleMetadata, localPath: String, isActive: Bool = false) {
init(id: UUID = UUID(), metadata: ModuleMetadata, localPath: String, metadataUrl: String, isActive: Bool = false) {
self.id = id
self.metadata = metadata
self.localPath = localPath
self.metadataUrl = metadataUrl
self.isActive = isActive
}
@ -94,7 +96,8 @@ class ModuleManager: ObservableObject {
let module = ScrapingModule(
metadata: metadata,
localPath: fileName
localPath: fileName,
metadataUrl: metadataUrl
)
DispatchQueue.main.async {

View file

@ -6,7 +6,6 @@
//
import Foundation
import SwiftUI
struct LibraryItem: Codable, Identifiable {
let id: UUID
@ -35,15 +34,24 @@ class LibraryManager: ObservableObject {
}
private func loadBookmarks() {
if let data = UserDefaults.standard.data(forKey: bookmarksKey),
let decoded = try? JSONDecoder().decode([LibraryItem].self, from: data) {
bookmarks = decoded
guard let data = UserDefaults.standard.data(forKey: bookmarksKey) else {
print("No bookmarks data found in UserDefaults.")
return
}
do {
bookmarks = try JSONDecoder().decode([LibraryItem].self, from: data)
} catch {
Logger.shared.log("Failed to decode bookmarks: \(error.localizedDescription)")
}
}
private func saveBookmarks() {
if let encoded = try? JSONEncoder().encode(bookmarks) {
do {
let encoded = try JSONEncoder().encode(bookmarks)
UserDefaults.standard.set(encoded, forKey: bookmarksKey)
} catch {
Logger.shared.log("Failed to encode bookmarks: \(error.localizedDescription)")
}
}

View file

@ -56,7 +56,7 @@ struct MediaInfoView: View {
.font(.system(size: 17))
.fontWeight(.bold)
if !aliases.isEmpty && aliases != title {
if !aliases.isEmpty && aliases != title && aliases != "N/A" {
Text(aliases)
.font(.system(size: 13))
.foregroundColor(.secondary)
@ -64,7 +64,7 @@ struct MediaInfoView: View {
Spacer()
if !airdate.isEmpty {
if !airdate.isEmpty && airdate != "N/A" {
HStack(alignment: .center, spacing: 12) {
HStack(spacing: 4) {
Image(systemName: "calendar")

View file

@ -14,6 +14,7 @@ struct SettingsViewModule: View {
@State private var errorMessage: String?
@State private var isLoading = false
@State private var addedModuleUrl: String?
var body: some View {
VStack {
@ -57,7 +58,7 @@ struct SettingsViewModule: View {
}
.contextMenu {
Button(action: {
UIPasteboard.general.string = module.metadata.iconUrl
UIPasteboard.general.string = module.metadataUrl
}) {
Label("Copy URL", systemImage: "doc.on.doc")
}
@ -91,6 +92,15 @@ struct SettingsViewModule: View {
.padding(5)
})
}
.alert(isPresented: .constant(errorMessage != nil)) {
Alert(
title: Text("Error"),
message: Text(errorMessage ?? "Unknown error"),
dismissButton: .default(Text("OK")) {
errorMessage = nil
}
)
}
}
func showAddModuleAlert() {
@ -114,6 +124,7 @@ struct SettingsViewModule: View {
private func addModule(from url: String) {
isLoading = true
errorMessage = nil
addedModuleUrl = url
Task {
do {
@ -124,7 +135,8 @@ struct SettingsViewModule: View {
} catch {
DispatchQueue.main.async {
isLoading = false
errorMessage = error.localizedDescription
errorMessage = "Failed to add module: \(error.localizedDescription)"
Logger.shared.log("Failed to add module: \(error.localizedDescription)")
}
}
}