From be3a968f3ee2a2691426e1cb14e34d272c1067ed Mon Sep 17 00:00:00 2001 From: cranci1 <100066266+cranci1@users.noreply.github.com> Date: Mon, 10 Mar 2025 16:45:59 +0100 Subject: [PATCH] made Sora player the default --- Sora/Views/LibraryView/LibraryView.swift | 36 +++++++-------- Sora/Views/MediaInfoView/MediaInfoView.swift | 46 +++++++++---------- .../SettingsSubViews/SettingsViewPlayer.swift | 18 ++++---- 3 files changed, 49 insertions(+), 51 deletions(-) diff --git a/Sora/Views/LibraryView/LibraryView.swift b/Sora/Views/LibraryView/LibraryView.swift index 26a8433..03a558a 100644 --- a/Sora/Views/LibraryView/LibraryView.swift +++ b/Sora/Views/LibraryView/LibraryView.swift @@ -33,11 +33,9 @@ struct LibraryView: View { .foregroundColor(.secondary) .padding(.horizontal, 20) } else { - ContinueWatchingSection(items: $continueWatchingItems, - markAsWatched: { item in + ContinueWatchingSection(items: $continueWatchingItems, markAsWatched: { item in markContinueWatchingItemAsWatched(item: item) - }, - removeItem: { item in + }, removeItem: { item in removeContinueWatchingItem(item: item) }) } @@ -170,7 +168,21 @@ struct ContinueWatchingCell: View { var body: some View { Button(action: { - if UserDefaults.standard.string(forKey: "externalPlayer") == "Sora" { + if UserDefaults.standard.string(forKey: "externalPlayer") == "Default" { + let videoPlayerViewController = VideoPlayerViewController(module: item.module) + videoPlayerViewController.streamUrl = item.streamUrl + videoPlayerViewController.fullUrl = item.fullUrl + videoPlayerViewController.episodeImageUrl = item.imageUrl + videoPlayerViewController.episodeNumber = item.episodeNumber + videoPlayerViewController.mediaTitle = item.mediaTitle + videoPlayerViewController.subtitles = item.subtitles ?? "" + videoPlayerViewController.modalPresentationStyle = .fullScreen + + if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene, + let rootVC = windowScene.windows.first?.rootViewController { + findTopViewController.findViewController(rootVC).present(videoPlayerViewController, animated: true, completion: nil) + } + } else { let customMediaPlayer = CustomMediaPlayerViewController( module: item.module, urlString: item.streamUrl, @@ -187,20 +199,6 @@ struct ContinueWatchingCell: View { let rootVC = windowScene.windows.first?.rootViewController { findTopViewController.findViewController(rootVC).present(customMediaPlayer, animated: true, completion: nil) } - } else { - let videoPlayerViewController = VideoPlayerViewController(module: item.module) - videoPlayerViewController.streamUrl = item.streamUrl - videoPlayerViewController.fullUrl = item.fullUrl - videoPlayerViewController.episodeImageUrl = item.imageUrl - videoPlayerViewController.episodeNumber = item.episodeNumber - videoPlayerViewController.mediaTitle = item.mediaTitle - videoPlayerViewController.subtitles = item.subtitles ?? "" - videoPlayerViewController.modalPresentationStyle = .fullScreen - - if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene, - let rootVC = windowScene.windows.first?.rootViewController { - findTopViewController.findViewController(rootVC).present(videoPlayerViewController, animated: true, completion: nil) - } } }) { VStack(alignment: .leading) { diff --git a/Sora/Views/MediaInfoView/MediaInfoView.swift b/Sora/Views/MediaInfoView/MediaInfoView.swift index 583b778..1504c12 100644 --- a/Sora/Views/MediaInfoView/MediaInfoView.swift +++ b/Sora/Views/MediaInfoView/MediaInfoView.swift @@ -502,7 +502,29 @@ struct MediaInfoView: View { scheme = "outplayer://\(url)" case "nPlayer": scheme = "nplayer-\(url)" - case "Sora": + case "Default": + let videoPlayerViewController = VideoPlayerViewController(module: module) + videoPlayerViewController.streamUrl = url + videoPlayerViewController.fullUrl = fullURL + videoPlayerViewController.episodeNumber = selectedEpisodeNumber + videoPlayerViewController.episodeImageUrl = selectedEpisodeImage + videoPlayerViewController.mediaTitle = title + videoPlayerViewController.subtitles = subtitles ?? "" + videoPlayerViewController.modalPresentationStyle = .fullScreen + + if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene, + let rootVC = windowScene.windows.first?.rootViewController { + findTopViewController.findViewController(rootVC).present(videoPlayerViewController, animated: true, completion: nil) + } + return + default: + break + } + + if let scheme = scheme, let url = URL(string: scheme), UIApplication.shared.canOpenURL(url) { + UIApplication.shared.open(url, options: [:], completionHandler: nil) + Logger.shared.log("Opening external app with scheme: \(url)", type: "General") + } else { let customMediaPlayer = CustomMediaPlayerViewController( module: module, urlString: url, @@ -522,28 +544,6 @@ struct MediaInfoView: View { let rootVC = windowScene.windows.first?.rootViewController { findTopViewController.findViewController(rootVC).present(customMediaPlayer, animated: true, completion: nil) } - return - default: - break - } - - if let scheme = scheme, let url = URL(string: scheme), UIApplication.shared.canOpenURL(url) { - UIApplication.shared.open(url, options: [:], completionHandler: nil) - Logger.shared.log("Opening external app with scheme: \(url)", type: "General") - } else { - let videoPlayerViewController = VideoPlayerViewController(module: module) - videoPlayerViewController.streamUrl = url - videoPlayerViewController.fullUrl = fullURL - videoPlayerViewController.episodeNumber = selectedEpisodeNumber - videoPlayerViewController.episodeImageUrl = selectedEpisodeImage - videoPlayerViewController.mediaTitle = title - videoPlayerViewController.subtitles = subtitles ?? "" - videoPlayerViewController.modalPresentationStyle = .fullScreen - - if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene, - let rootVC = windowScene.windows.first?.rootViewController { - findTopViewController.findViewController(rootVC).present(videoPlayerViewController, animated: true, completion: nil) - } } } } diff --git a/Sora/Views/SettingsView/SettingsSubViews/SettingsViewPlayer.swift b/Sora/Views/SettingsView/SettingsSubViews/SettingsViewPlayer.swift index 4fd7583..7eadefe 100644 --- a/Sora/Views/SettingsView/SettingsSubViews/SettingsViewPlayer.swift +++ b/Sora/Views/SettingsView/SettingsSubViews/SettingsViewPlayer.swift @@ -8,7 +8,7 @@ import SwiftUI struct SettingsViewPlayer: View { - @AppStorage("externalPlayer") private var externalPlayer: String = "Default" + @AppStorage("externalPlayer") private var externalPlayer: String = "Sora" @AppStorage("alwaysLandscape") private var isAlwaysLandscape = false @AppStorage("hideNextButton") private var isHideNextButton = false @AppStorage("rememberPlaySpeed") private var isRememberPlaySpeed = false @@ -109,6 +109,14 @@ struct SubtitleSettingsSection: View { } } + Toggle("Background Enabled", isOn: $backgroundEnabled) + .tint(.accentColor) + .onChange(of: backgroundEnabled) { newValue in + SubtitleSettingsManager.shared.update { settings in + settings.backgroundEnabled = newValue + } + } + HStack { Text("Font Size:") Spacer() @@ -130,14 +138,6 @@ struct SubtitleSettingsSection: View { } } } - - Toggle("Background Enabled", isOn: $backgroundEnabled) - .tint(.accentColor) - .onChange(of: backgroundEnabled) { newValue in - SubtitleSettingsManager.shared.update { settings in - settings.backgroundEnabled = newValue - } - } } } }