From 117639514e4cf6d2f5dab5e374e47e8762e4d37e Mon Sep 17 00:00:00 2001 From: cranci1 <100066266+cranci1@users.noreply.github.com> Date: Wed, 11 Jun 2025 21:23:30 +0200 Subject: [PATCH] =?UTF-8?q?im=20even=20dumber=20=F0=9F=98=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sora/SoraApp.swift | 26 ++------------- .../JavaScriptCore+Extensions.swift | 26 +++++++++++++-- .../EpisodeCell/EpisodeCell.swift | 26 ++++----------- Sora/Views/MediaInfoView/MediaInfoView.swift | 32 +++---------------- .../SettingsViewGeneral.swift | 5 +-- 5 files changed, 38 insertions(+), 77 deletions(-) diff --git a/Sora/SoraApp.swift b/Sora/SoraApp.swift index 86ddd7d..7f620d0 100644 --- a/Sora/SoraApp.swift +++ b/Sora/SoraApp.swift @@ -32,7 +32,7 @@ struct SoraApp: App { var body: some Scene { WindowGroup { Group { - if !UserDefaults.standard.bool(forKey: "hideSplashScreenEnable") { + if !UserDefaults.standard.bool(forKey: "hideSplashScreen") { SplashScreenView() } else { ContentView() @@ -102,26 +102,4 @@ struct SoraApp: App { break } } -} - -@objc class AppInfo: NSObject { - @objc static let shared = AppInfo() - - @objc func getBundleIdentifier() -> String { - return Bundle.main.bundleIdentifier ?? "me.cranci.sulfur" - } - - @objc func getDisplayName() -> String { - return Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as? String ?? Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as! String - } - - @objc func isValidApp() -> Bool { - let bundleId = getBundleIdentifier().lowercased() - let displayName = getDisplayName().lowercased() - - let hasValidBundleId = bundleId.contains("sulfur") - let hasValidDisplayName = displayName == "sora" || displayName == "sulfur" - - return hasValidBundleId && hasValidDisplayName - } -} +} \ No newline at end of file diff --git a/Sora/Utils/Extensions/JavaScriptCore+Extensions.swift b/Sora/Utils/Extensions/JavaScriptCore+Extensions.swift index 0051c0e..a28c119 100644 --- a/Sora/Utils/Extensions/JavaScriptCore+Extensions.swift +++ b/Sora/Utils/Extensions/JavaScriptCore+Extensions.swift @@ -10,9 +10,6 @@ import JavaScriptCore extension JSContext { func setupConsoleLogging() { let consoleObject = JSValue(newObjectIn: self) - let appInfoBridge = AppInfo.shared - - self.setObject(appInfoBridge, forKeyedSubscript: "AppInfo" as NSString) let consoleLogFunction: @convention(block) (String) -> Void = { message in Logger.shared.log(message, type: "Debug") @@ -275,10 +272,33 @@ extension JSContext { self.setObject(atobFunction, forKeyedSubscript: "atob" as NSString) } + func setupAppInfo() { + let bundle = Bundle.main + let appInfo = JSValue(newObjectIn: self) + + appInfo?.setValue(bundle.bundleIdentifier ?? "", forProperty: "bundleId") + appInfo?.setValue( + bundle.object(forInfoDictionaryKey: "CFBundleDisplayName") as? String + ?? bundle.object(forInfoDictionaryKey: "CFBundleName") as? String + ?? "", + forProperty: "displayName" + ) + + let isValidApp: @convention(block) () -> Bool = { + guard let app = appInfo else { return false } + return !(app.forProperty("bundleId").toString().isEmpty || + app.forProperty("displayName").toString().isEmpty) + } + + appInfo?.setObject(isValidApp, forKeyedSubscript: "isValidApp" as NSString) + self.setObject(appInfo, forKeyedSubscript: "AppInfo" as NSString) + } + func setupJavaScriptEnvironment() { setupConsoleLogging() setupNativeFetch() setupFetchV2() setupBase64Functions() + setupAppInfo() } } diff --git a/Sora/Views/MediaInfoView/EpisodeCell/EpisodeCell.swift b/Sora/Views/MediaInfoView/EpisodeCell/EpisodeCell.swift index 7415c02..645ff7b 100644 --- a/Sora/Views/MediaInfoView/EpisodeCell/EpisodeCell.swift +++ b/Sora/Views/MediaInfoView/EpisodeCell/EpisodeCell.swift @@ -9,10 +9,7 @@ import NukeUI import SwiftUI import AVFoundation - struct EpisodeCell: View { - - let episodeIndex: Int let episode: String let episodeID: Int @@ -26,16 +23,13 @@ struct EpisodeCell: View { let tmdbID: Int? let seasonNumber: Int? - let isMultiSelectMode: Bool let isSelected: Bool let onSelectionChanged: ((Bool) -> Void)? - let onTap: (String) -> Void let onMarkAllPrevious: () -> Void - @State private var episodeTitle = "" @State private var episodeImageUrl = "" @State private var isLoading = true @@ -45,23 +39,19 @@ struct EpisodeCell: View { @State private var downloadAnimationScale: CGFloat = 1.0 @State private var activeDownloadTask: AVAssetDownloadTask? - @State private var swipeOffset: CGFloat = 0 @State private var isShowingActions = false @State private var actionButtonWidth: CGFloat = 60 - @State private var retryAttempts = 0 private let maxRetryAttempts = 3 private let initialBackoffDelay: TimeInterval = 1.0 - @ObservedObject private var jsController = JSController.shared @EnvironmentObject var moduleManager: ModuleManager @Environment(\.colorScheme) private var colorScheme @AppStorage("selectedAppearance") private var selectedAppearance: Appearance = .system - init( episodeIndex: Int, episode: String, @@ -98,7 +88,7 @@ struct EpisodeCell: View { self.tmdbID = tmdbID self.seasonNumber = seasonNumber - + let isLightMode = (UserDefaults.standard.string(forKey: "selectedAppearance") == "light") || ((UserDefaults.standard.string(forKey: "selectedAppearance") == "system") && UITraitCollection.current.userInterfaceStyle == .light) @@ -110,13 +100,10 @@ struct EpisodeCell: View { (isLightMode ? defaultLightBanner : defaultDarkBanner) : defaultBannerImage } - var body: some View { ZStack { - actionButtonsBackground - episodeCellContent .offset(x: swipeOffset) .animation(.spring(response: 0.3, dampingFraction: 0.8), value: swipeOffset) @@ -146,7 +133,6 @@ struct EpisodeCell: View { } } - private extension EpisodeCell { var actionButtonsBackground: some View { @@ -365,7 +351,7 @@ private extension EpisodeCell { } func calculateMaxSwipeDistance() -> CGFloat { - var buttonCount = 1 + var buttonCount = 1 if progress <= 0.9 { buttonCount += 1 } if progress != 0 { buttonCount += 1 } @@ -796,7 +782,7 @@ private extension EpisodeCell { self.retryAttempts = 0 if UserDefaults.standard.object(forKey: "fetchEpisodeMetadata") == nil || - UserDefaults.standard.bool(forKey: "fetchEpisodeMetadata") { + UserDefaults.standard.bool(forKey: "fetchEpisodeMetadata") { self.episodeTitle = title["en"] ?? title.values.first ?? "" if !image.isEmpty { @@ -825,9 +811,9 @@ private extension EpisodeCell { let stillPath = json["still_path"] as? String let imageUrl = stillPath.map { path in - tmdbImageWidth == "original" - ? "https://image.tmdb.org/t/p/original\(path)" - : "https://image.tmdb.org/t/p/w\(tmdbImageWidth)\(path)" + tmdbImageWidth == "original" + ? "https://image.tmdb.org/t/p/original\(path)" + : "https://image.tmdb.org/t/p/w\(tmdbImageWidth)\(path)" } ?? "" DispatchQueue.main.async { diff --git a/Sora/Views/MediaInfoView/MediaInfoView.swift b/Sora/Views/MediaInfoView/MediaInfoView.swift index 19386d6..9ef8dfa 100644 --- a/Sora/Views/MediaInfoView/MediaInfoView.swift +++ b/Sora/Views/MediaInfoView/MediaInfoView.swift @@ -9,7 +9,6 @@ import NukeUI import SwiftUI import SafariServices - private let tmdbFetcher = TMDBFetcher() struct MediaItem: Identifiable { @@ -19,9 +18,6 @@ struct MediaItem: Identifiable { let airdate: String } - - - struct MediaInfoView: View { let title: String @State var imageUrl: String @@ -183,8 +179,6 @@ struct MediaInfoView: View { } } - // MARK: - View Builders - @ViewBuilder private var navigationOverlay: some View { VStack { @@ -444,8 +438,6 @@ struct MediaInfoView: View { } } - // MARK: - Computed Properties for Single Episode - private var isBookmarked: Bool { libraryManager.isBookmarked(href: href, moduleName: module.metadata.sourceName) } @@ -470,8 +462,6 @@ struct MediaInfoView: View { return "Mark watched" } - // MARK: - Episodes Section - @ViewBuilder private var episodesSection: some View { if episodeLinks.count != 1 { @@ -638,8 +628,6 @@ struct MediaInfoView: View { .padding(.vertical, 50) } - // MARK: - Menu and Action Buttons - @ViewBuilder private var sourceButton: some View { Button(action: { openSafariViewController(with: href) }) { @@ -737,8 +725,6 @@ struct MediaInfoView: View { } } - // MARK: - Setup and Lifecycle Methods - private func setupViewOnAppear() { buttonRefreshTrigger.toggle() tabBarController.hideTabBar() @@ -790,8 +776,6 @@ struct MediaInfoView: View { showLoadingAlert = false } - // MARK: - Action Methods - private func copyTitleToClipboard() { UIPasteboard.general.string = title DropManager.shared.showDrop( @@ -895,8 +879,6 @@ struct MediaInfoView: View { } } - // MARK: - Menu Action Methods - private func handleAniListMatch(selectedID: Int) { self.customAniListID = selectedID self.itemID = selectedID @@ -951,8 +933,6 @@ struct MediaInfoView: View { ) } - // MARK: - Utility Methods - private func getBannerImageBasedOnAppearance() -> String { let isLightMode = selectedAppearance == .light || (selectedAppearance == .system && colorScheme == .light) return isLightMode @@ -967,7 +947,7 @@ struct MediaInfoView: View { } else { selectedRange = generateRanges().first ?? 0..