From f14f39c60cf402d02289a6172b7c6675e66721e6 Mon Sep 17 00:00:00 2001 From: cranci1 <100066266+cranci1@users.noreply.github.com> Date: Wed, 22 Jan 2025 16:29:23 +0100 Subject: [PATCH 1/2] stuff --- Sora/Views/MediaInfoView/MediaInfoView.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sora/Views/MediaInfoView/MediaInfoView.swift b/Sora/Views/MediaInfoView/MediaInfoView.swift index 3866823..bbafb22 100644 --- a/Sora/Views/MediaInfoView/MediaInfoView.swift +++ b/Sora/Views/MediaInfoView/MediaInfoView.swift @@ -56,7 +56,7 @@ struct MediaInfoView: View { .font(.system(size: 17)) .fontWeight(.bold) - if !aliases.isEmpty && aliases != title && aliases != "N/A" { + if !aliases.isEmpty && aliases != title && aliases != "N/A" && aliases != "No Data" { Text(aliases) .font(.system(size: 13)) .foregroundColor(.secondary) @@ -64,7 +64,7 @@ struct MediaInfoView: View { Spacer() - if !airdate.isEmpty && airdate != "N/A" { + if !airdate.isEmpty && airdate != "N/A" && airdate != "No Data" { HStack(alignment: .center, spacing: 12) { HStack(spacing: 4) { Image(systemName: "calendar") From 9beede786ac5ea013b3a4356590170cb9427f261 Mon Sep 17 00:00:00 2001 From: cranci1 <100066266+cranci1@users.noreply.github.com> Date: Wed, 22 Jan 2025 20:37:25 +0100 Subject: [PATCH 2/2] test --- Sora/Utils/Loaders/JSController.swift | 60 ++++++++++----------------- 1 file changed, 21 insertions(+), 39 deletions(-) diff --git a/Sora/Utils/Loaders/JSController.swift b/Sora/Utils/Loaders/JSController.swift index 7a4240d..6137c9e 100644 --- a/Sora/Utils/Loaders/JSController.swift +++ b/Sora/Utils/Loaders/JSController.swift @@ -294,6 +294,9 @@ class JSController: ObservableObject { var resultItems: [MediaItem] = [] var episodeLinks: [EpisodeLink] = [] + let dispatchGroup = DispatchGroup() + + dispatchGroup.enter() let promiseValueDetails = extractDetailsFunction.call(withArguments: [url.absoluteString]) guard let promiseDetails = promiseValueDetails else { Logger.shared.log("extractDetails did not return a Promise") @@ -302,43 +305,33 @@ class JSController: ObservableObject { } let thenBlockDetails: @convention(block) (JSValue) -> Void = { result in - Logger.shared.log(result.toString()) if let jsonOfDetails = result.toString(), let dataDetails = jsonOfDetails.data(using: .utf8) { do { if let array = try JSONSerialization.jsonObject(with: dataDetails, options: []) as? [[String: Any]] { resultItems = array.map { item -> MediaItem in - let description = item["description"] as? String ?? "" - let aliases = item["aliases"] as? String ?? "" - let airdate = item["airdate"] as? String ?? "" - return MediaItem(description: description, aliases: aliases, airdate: airdate) + MediaItem( + description: item["description"] as? String ?? "", + aliases: item["aliases"] as? String ?? "", + airdate: item["airdate"] as? String ?? "" + ) } } else { Logger.shared.log("Failed to parse JSON of extractDetails") - DispatchQueue.main.async { - completion([], []) - } } } catch { Logger.shared.log("JSON parsing error of extract details: \(error)") - DispatchQueue.main.async { - completion([], []) - } } } else { Logger.shared.log("Result is not a string of extractDetails") - DispatchQueue.main.async { - completion([], []) - } } + dispatchGroup.leave() } let catchBlockDetails: @convention(block) (JSValue) -> Void = { error in Logger.shared.log("Promise rejected of extractDetails: \(String(describing: error.toString()))") - DispatchQueue.main.async { - completion([], []) - } + dispatchGroup.leave() } let thenFunctionDetails = JSValue(object: thenBlockDetails, in: context) @@ -347,7 +340,7 @@ class JSController: ObservableObject { promiseDetails.invokeMethod("then", withArguments: [thenFunctionDetails as Any]) promiseDetails.invokeMethod("catch", withArguments: [catchFunctionDetails as Any]) - + dispatchGroup.enter() let promiseValueEpisodes = extractEpisodesFunction.call(withArguments: [url.absoluteString]) guard let promiseEpisodes = promiseValueEpisodes else { Logger.shared.log("extractEpisodes did not return a Promise") @@ -356,47 +349,32 @@ class JSController: ObservableObject { } let thenBlockEpisodes: @convention(block) (JSValue) -> Void = { result in - Logger.shared.log(result.toString()) if let jsonOfEpisodes = result.toString(), let dataEpisodes = jsonOfEpisodes.data(using: .utf8) { do { if let array = try JSONSerialization.jsonObject(with: dataEpisodes, options: []) as? [[String: Any]] { episodeLinks = array.map { item -> EpisodeLink in - let number = item["number"] as? Int ?? 0 - let href = item["href"] as? String ?? "" - return EpisodeLink(number: number, href: href) + EpisodeLink( + number: item["number"] as? Int ?? 0, + href: item["href"] as? String ?? "" + ) } - - DispatchQueue.main.async { - completion(resultItems, episodeLinks) - } - } else { Logger.shared.log("Failed to parse JSON of extractEpisodes") - DispatchQueue.main.async { - completion([], []) - } } } catch { Logger.shared.log("JSON parsing error of extractEpisodes: \(error)") - DispatchQueue.main.async { - completion([], []) - } } } else { Logger.shared.log("Result is not a string of extractEpisodes") - DispatchQueue.main.async { - completion([], []) - } } + dispatchGroup.leave() } let catchBlockEpisodes: @convention(block) (JSValue) -> Void = { error in Logger.shared.log("Promise rejected of extractEpisodes: \(String(describing: error.toString()))") - DispatchQueue.main.async { - completion([], []) - } + dispatchGroup.leave() } let thenFunctionEpisodes = JSValue(object: thenBlockEpisodes, in: context) @@ -404,5 +382,9 @@ class JSController: ObservableObject { promiseEpisodes.invokeMethod("then", withArguments: [thenFunctionEpisodes as Any]) promiseEpisodes.invokeMethod("catch", withArguments: [catchFunctionEpisodes as Any]) + + dispatchGroup.notify(queue: .main) { + completion(resultItems, episodeLinks) + } } }