From e7044891c385d53f1e4d08e5ff1a3fde4ed4b715 Mon Sep 17 00:00:00 2001 From: cranci1 <100066266+cranci1@users.noreply.github.com> Date: Mon, 16 Jun 2025 11:09:11 +0200 Subject: [PATCH] yaeh --- .../NormalPlayer/NormalPlayer.swift | 21 -------- .../MediaUtils/NormalPlayer/VideoPlayer.swift | 48 +++++++++++++++---- 2 files changed, 39 insertions(+), 30 deletions(-) diff --git a/Sora/MediaUtils/NormalPlayer/NormalPlayer.swift b/Sora/MediaUtils/NormalPlayer/NormalPlayer.swift index ed4f53d..28b6d40 100644 --- a/Sora/MediaUtils/NormalPlayer/NormalPlayer.swift +++ b/Sora/MediaUtils/NormalPlayer/NormalPlayer.swift @@ -12,31 +12,10 @@ class NormalPlayer: AVPlayerViewController { private var originalRate: Float = 1.0 private var holdGesture: UILongPressGestureRecognizer? - var onSharePlayRequested: (() -> Void)? - override func viewDidLoad() { super.viewDidLoad() setupHoldGesture() setupAudioSession() - setupSharePlayButton() - } - - private func setupSharePlayButton() { - let sharePlayItem = UIBarButtonItem( - image: UIImage(systemName: "shareplay"), - style: .plain, - target: self, - action: #selector(sharePlayButtonTapped) - ) - sharePlayItem.tintColor = .white - - if responds(to: Selector(("setCustomControlItems:"))) { - setValue([sharePlayItem], forKey: "customControlItems") - } - } - - @objc private func sharePlayButtonTapped() { - onSharePlayRequested?() } private func setupHoldGesture() { diff --git a/Sora/MediaUtils/NormalPlayer/VideoPlayer.swift b/Sora/MediaUtils/NormalPlayer/VideoPlayer.swift index e963f03..319f4b4 100644 --- a/Sora/MediaUtils/NormalPlayer/VideoPlayer.swift +++ b/Sora/MediaUtils/NormalPlayer/VideoPlayer.swift @@ -40,9 +40,6 @@ class VideoPlayerViewController: UIViewController { init(module: ScrapingModule) { self.module = module super.init(nibName: nil, bundle: nil) - if UserDefaults.standard.object(forKey: "subtitlesEnabled") == nil { - UserDefaults.standard.set(true, forKey: "subtitlesEnabled") - } } required init?(coder: NSCoder) { @@ -81,12 +78,6 @@ class VideoPlayerViewController: UIViewController { playerViewController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight] view.addSubview(playerViewController.view) playerViewController.didMove(toParent: self) - - playerViewController.onSharePlayRequested = { [weak self] in - Task { @MainActor in - await self?.startSharePlay() - } - } } addPeriodicTimeObserver(fullURL: fullUrl) @@ -187,6 +178,45 @@ class VideoPlayerViewController: UIViewController { super.viewDidAppear(animated) player?.play() setInitialPlayerRate() + + checkForFaceTimeAndPromptSharePlay() + } + + private func checkForFaceTimeAndPromptSharePlay() { + let autoPromptEnabled = UserDefaults.standard.object(forKey: "autoPromptSharePlay") as? Bool ?? true + guard autoPromptEnabled else { return } + + Task { @MainActor in + do { + try await VideoWatchingActivity.prepareForActivation() + showSharePlayPrompt() + } catch { + Logger.shared.log("SharePlay not available or no active FaceTime call", type: "Debug") + } + } + } + + @MainActor + private func showSharePlayPrompt() { + let alert = UIAlertController( + title: "Watch Together?", + message: "You're in a FaceTime call. Would you like to share this video with everyone?", + preferredStyle: .alert + ) + + alert.addAction(UIAlertAction(title: "Share Video", style: .default) { [weak self] _ in + Task { + await self?.startSharePlay() + } + }) + + alert.addAction(UIAlertAction(title: "Watch Alone", style: .cancel)) + + alert.addAction(UIAlertAction(title: "Don't Ask Again", style: .destructive) { _ in + UserDefaults.standard.set(false, forKey: "autoPromptSharePlay") + }) + + present(alert, animated: true) } override func viewDidDisappear(_ animated: Bool) {