mirror of
				https://github.com/yattee/yattee.git
				synced 2025-10-30 12:11:59 +00:00 
			
		
		
		
	Merge pull request #806 from yattee/orientation-location-cleanup
Orientation/Fullscreen fixes and cleanup
This commit is contained in:
		| @@ -136,7 +136,9 @@ final class PlayerModel: ObservableObject { | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         @Default(.rotateToLandscapeOnEnterFullScreen) private var rotateToLandscapeOnEnterFullScreen | ||||
|         @Default(.rotateToLandscapeOnEnterFullScreen) var rotateToLandscapeOnEnterFullScreen | ||||
|         @Default(.lockPortraitWhenBrowsing) var lockPortraitWhenBrowsing | ||||
|         var fullscreenInitiatedByButton = false | ||||
|     #endif | ||||
|  | ||||
|     @Published var currentChapterIndex: Int? | ||||
| @@ -209,7 +211,7 @@ final class PlayerModel: ObservableObject { | ||||
|         #if os(iOS) | ||||
|             isOrientationLocked = Defaults[.isOrientationLocked] | ||||
|  | ||||
|             if isOrientationLocked, Defaults[.lockPortraitWhenBrowsing] { | ||||
|             if isOrientationLocked, lockPortraitWhenBrowsing { | ||||
|                 lockedOrientation = UIInterfaceOrientationMask.portrait | ||||
|                 Orientation.lockOrientation(.portrait, andRotateTo: .portrait) | ||||
|             } else if isOrientationLocked { | ||||
| @@ -564,10 +566,10 @@ final class PlayerModel: ObservableObject { | ||||
|  | ||||
|         if !presentingPlayer { | ||||
|             #if os(iOS) | ||||
|                 if Defaults[.lockPortraitWhenBrowsing] { | ||||
|                 if lockPortraitWhenBrowsing { | ||||
|                     Orientation.lockOrientation(.portrait, andRotateTo: .portrait) | ||||
|                 } else { | ||||
|                     Orientation.lockOrientation(.allButUpsideDown) | ||||
|                     Orientation.lockOrientation(.all) | ||||
|                 } | ||||
|             #endif | ||||
|         } | ||||
| @@ -821,7 +823,7 @@ final class PlayerModel: ObservableObject { | ||||
|             } else { | ||||
|                 isOrientationLocked = false | ||||
|                 lockedOrientation = nil | ||||
|                 Orientation.lockOrientation(.allButUpsideDown) | ||||
|                 Orientation.lockOrientation(.all) | ||||
|             } | ||||
|         } | ||||
|     #endif | ||||
| @@ -1149,16 +1151,27 @@ final class PlayerModel: ObservableObject { | ||||
|         #if os(iOS) | ||||
|             if playingFullScreen { | ||||
|                 if activeBackend == .appleAVPlayer, avPlayerUsesSystemControls { | ||||
|                     fullscreenInitiatedByButton = initiatedByButton | ||||
|                     avPlayerBackend.controller.enterFullScreen(animated: true) | ||||
|                     return | ||||
|                 } | ||||
|                 let lockOrientation = rotateToLandscapeOnEnterFullScreen.interfaceOrientation | ||||
|                 if currentVideoIsLandscape { | ||||
|                     if initiatedByButton { | ||||
|                         Orientation.lockOrientation(self.isOrientationLocked ? (lockOrientation == .landscapeRight ? .landscapeRight : .landscapeLeft) : .landscape) | ||||
|                         Orientation.lockOrientation(isOrientationLocked | ||||
|                             ? (lockOrientation == .landscapeRight ? .landscapeRight : .landscapeLeft) | ||||
|                             : .landscape) | ||||
|                     } | ||||
|                     let orientation = OrientationTracker.shared.currentDeviceOrientation.isLandscape ? OrientationTracker.shared.currentInterfaceOrientation : self.rotateToLandscapeOnEnterFullScreen.interfaceOrientation | ||||
|                     Orientation.lockOrientation(self.isOrientationLocked ? (lockOrientation == .landscapeRight ? .landscapeRight : .landscapeLeft) : .landscape, andRotateTo: orientation) | ||||
|                     let orientation = OrientationTracker.shared.currentDeviceOrientation.isLandscape | ||||
|                         ? OrientationTracker.shared.currentInterfaceOrientation | ||||
|                         : rotateToLandscapeOnEnterFullScreen.interfaceOrientation | ||||
|  | ||||
|                     Orientation.lockOrientation( | ||||
|                         isOrientationLocked | ||||
|                             ? (lockOrientation == .landscapeRight ? .landscapeRight : .landscapeLeft) | ||||
|                             : .all, | ||||
|                         andRotateTo: orientation | ||||
|                     ) | ||||
|                 } | ||||
|             } else { | ||||
|                 if activeBackend == .appleAVPlayer, avPlayerUsesSystemControls { | ||||
| @@ -1166,11 +1179,11 @@ final class PlayerModel: ObservableObject { | ||||
|                     avPlayerBackend.controller.dismiss(animated: true) | ||||
|                     return | ||||
|                 } | ||||
|                 if Defaults[.lockPortraitWhenBrowsing] { | ||||
|                 if lockPortraitWhenBrowsing { | ||||
|                     lockedOrientation = UIInterfaceOrientationMask.portrait | ||||
|                 } | ||||
|                 let rotationOrientation = Defaults[.lockPortraitWhenBrowsing] ? UIInterfaceOrientation.portrait : nil | ||||
|                 Orientation.lockOrientation(Defaults[.lockPortraitWhenBrowsing] ? .portrait : .allButUpsideDown, andRotateTo: rotationOrientation) | ||||
|                 let rotationOrientation = lockPortraitWhenBrowsing ? UIInterfaceOrientation.portrait : nil | ||||
|                 Orientation.lockOrientation(lockPortraitWhenBrowsing ? .portrait : .all, andRotateTo: rotationOrientation) | ||||
|             } | ||||
|         #endif | ||||
|     } | ||||
|   | ||||
| @@ -4,11 +4,6 @@ import SwiftUI | ||||
|  | ||||
| #if !os(macOS) | ||||
|     final class AppleAVPlayerViewControllerDelegate: NSObject, AVPlayerViewControllerDelegate { | ||||
|         #if os(iOS) | ||||
|             @Default(.rotateToLandscapeOnEnterFullScreen) private var rotateToLandscapeOnEnterFullScreen | ||||
|             @Default(.avPlayerUsesSystemControls) private var avPlayerUsesSystemControls | ||||
|         #endif | ||||
|  | ||||
|         var player: PlayerModel { .shared } | ||||
|  | ||||
|         func playerViewControllerShouldAutomaticallyDismissAtPictureInPictureStart(_: AVPlayerViewController) -> Bool { | ||||
| @@ -17,14 +12,23 @@ import SwiftUI | ||||
|  | ||||
|         #if os(iOS) | ||||
|             func playerViewController(_: AVPlayerViewController, willBeginFullScreenPresentationWithAnimationCoordinator _: UIViewControllerTransitionCoordinator) { | ||||
|                 if PlayerModel.shared.currentVideoIsLandscape { | ||||
|                     let delay = PlayerModel.shared.activeBackend == .appleAVPlayer && avPlayerUsesSystemControls ? 0.8 : 0 | ||||
|                     // not sure why but first rotation call is ignore so doing rotate to same orientation first | ||||
|                     Delay.by(delay) { | ||||
|                         let orientation = OrientationTracker.shared.currentDeviceOrientation.isLandscape ? OrientationTracker.shared.currentInterfaceOrientation : self.rotateToLandscapeOnEnterFullScreen.interfaceOrientation | ||||
|                         Orientation.lockOrientation(.allButUpsideDown, andRotateTo: OrientationTracker.shared.currentInterfaceOrientation) | ||||
|                         Orientation.lockOrientation(.allButUpsideDown, andRotateTo: orientation) | ||||
|                 let lockOrientation = player.rotateToLandscapeOnEnterFullScreen.interfaceOrientation | ||||
|                 if player.currentVideoIsLandscape { | ||||
|                     if player.fullscreenInitiatedByButton { | ||||
|                         Orientation.lockOrientation(player.isOrientationLocked | ||||
|                             ? (lockOrientation == .landscapeRight ? .landscapeRight : .landscapeLeft) | ||||
|                             : .landscape) | ||||
|                     } | ||||
|                     let orientation = OrientationTracker.shared.currentDeviceOrientation.isLandscape | ||||
|                         ? OrientationTracker.shared.currentInterfaceOrientation | ||||
|                         : player.rotateToLandscapeOnEnterFullScreen.interfaceOrientation | ||||
|  | ||||
|                     Orientation.lockOrientation( | ||||
|                         player.isOrientationLocked | ||||
|                             ? (lockOrientation == .landscapeRight ? .landscapeRight : .landscapeLeft) | ||||
|                             : .all, | ||||
|                         andRotateTo: orientation | ||||
|                     ) | ||||
|                 } | ||||
|             } | ||||
|  | ||||
| @@ -36,9 +40,11 @@ import SwiftUI | ||||
|                     } | ||||
|                     if !context.isCancelled { | ||||
|                         #if os(iOS) | ||||
|                             if Constants.isIPhone { | ||||
|                                 Orientation.lockOrientation(.allButUpsideDown, andRotateTo: .portrait) | ||||
|                             if self.player.lockPortraitWhenBrowsing { | ||||
|                                 self.player.lockedOrientation = UIInterfaceOrientationMask.portrait | ||||
|                             } | ||||
|                             let rotationOrientation = self.player.lockPortraitWhenBrowsing ? UIInterfaceOrientation.portrait : nil | ||||
|                             Orientation.lockOrientation(self.player.lockPortraitWhenBrowsing ? .portrait : .all, andRotateTo: rotationOrientation) | ||||
|  | ||||
|                             if wasPlaying { | ||||
|                                 self.player.play() | ||||
|   | ||||
| @@ -170,7 +170,7 @@ struct BrowsingSettings: View { | ||||
|                                 Orientation.lockOrientation(.portrait, andRotateTo: .portrait) | ||||
|                             } else { | ||||
|                                 enterFullscreenInLandscape = false | ||||
|                                 Orientation.lockOrientation(.allButUpsideDown) | ||||
|                                 Orientation.lockOrientation(.all) | ||||
|                             } | ||||
|                         } | ||||
|                 } | ||||
|   | ||||
| @@ -211,7 +211,7 @@ struct YatteeApp: App { | ||||
|                         let rotationOrientation = | ||||
|                             OrientationTracker.shared.currentDeviceOrientation.rawValue == 4 ? UIInterfaceOrientation.landscapeRight : | ||||
|                             (OrientationTracker.shared.currentDeviceOrientation.rawValue == 3 ? UIInterfaceOrientation.landscapeLeft : UIInterfaceOrientation.portrait) | ||||
|                         Orientation.lockOrientation(.allButUpsideDown, andRotateTo: rotationOrientation) | ||||
|                         Orientation.lockOrientation(.all, andRotateTo: rotationOrientation) | ||||
|                     } | ||||
|                 } | ||||
|             #endif | ||||
|   | ||||
| @@ -4367,8 +4367,7 @@ | ||||
| 				INFOPLIST_KEY_UIRequiresFullScreen = YES; | ||||
| 				INFOPLIST_KEY_UIStatusBarHidden = NO; | ||||
| 				INFOPLIST_KEY_UIStatusBarStyle = ""; | ||||
| 				INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortrait"; | ||||
| 				INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown"; | ||||
| 				INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown"; | ||||
| 				IPHONEOS_DEPLOYMENT_TARGET = 14.0; | ||||
| 				LD_RUNPATH_SEARCH_PATHS = ( | ||||
| 					"$(inherited)", | ||||
| @@ -4418,8 +4417,7 @@ | ||||
| 				INFOPLIST_KEY_UIRequiresFullScreen = YES; | ||||
| 				INFOPLIST_KEY_UIStatusBarHidden = NO; | ||||
| 				INFOPLIST_KEY_UIStatusBarStyle = ""; | ||||
| 				INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortrait"; | ||||
| 				INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown"; | ||||
| 				INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown"; | ||||
| 				IPHONEOS_DEPLOYMENT_TARGET = 14.0; | ||||
| 				LD_RUNPATH_SEARCH_PATHS = ( | ||||
| 					"$(inherited)", | ||||
|   | ||||
| @@ -5,7 +5,7 @@ import Logging | ||||
| import UIKit | ||||
|  | ||||
| final class AppDelegate: UIResponder, UIApplicationDelegate { | ||||
|     var orientationLock = UIInterfaceOrientationMask.allButUpsideDown | ||||
|     var orientationLock = UIInterfaceOrientationMask.all | ||||
|  | ||||
|     private var logger = Logger(label: "stream.yattee.app.delegate") | ||||
|     private(set) static var instance: AppDelegate! | ||||
|   | ||||
| @@ -1,5 +1,4 @@ | ||||
| import CoreMotion | ||||
| import Defaults | ||||
| import Logging | ||||
| import UIKit | ||||
|  | ||||
| @@ -35,7 +34,7 @@ enum Orientation { | ||||
|             let rotateOrientationMask = rotateOrientation == .portrait ? UIInterfaceOrientationMask.portrait : | ||||
|                 rotateOrientation == .landscapeLeft ? .landscapeLeft : | ||||
|                 rotateOrientation == .landscapeRight ? .landscapeRight : | ||||
|                 .allButUpsideDown | ||||
|                 .all | ||||
|  | ||||
|             windowScene.requestGeometryUpdate(.iOS(interfaceOrientations: rotateOrientationMask)) { error in | ||||
|                 print("denied rotation \(error)") | ||||
|   | ||||
| @@ -13,6 +13,9 @@ final class OrientationModel { | ||||
|     var orientationDebouncer = Debouncer(.milliseconds(300)) | ||||
|     var orientationObserver: Any? | ||||
|  | ||||
|     @Default(.lockPortraitWhenBrowsing) private var lockPortraitWhenBrowsing | ||||
|     @Default(.enterFullscreenInLandscape) private var enterFullscreenInLandscape | ||||
|  | ||||
|     private var player = PlayerModel.shared | ||||
|  | ||||
|     func startOrientationUpdates() { | ||||
| @@ -25,7 +28,7 @@ final class OrientationModel { | ||||
|             self.logger.info("Notification received: Device orientation changed.") | ||||
|  | ||||
|             // We only allow .portrait and are not showing the player | ||||
|             guard (!self.player.presentingPlayer && !Defaults[.lockPortraitWhenBrowsing]) || self.player.presentingPlayer | ||||
|             guard (!self.player.presentingPlayer && !self.lockPortraitWhenBrowsing) || self.player.presentingPlayer | ||||
|             else { | ||||
|                 return | ||||
|             } | ||||
| @@ -42,7 +45,7 @@ final class OrientationModel { | ||||
|             } | ||||
|  | ||||
|             // Only take action if the player is active and presenting | ||||
|             guard (!self.player.isOrientationLocked && !self.player.playingInPictureInPicture) || (!Defaults[.lockPortraitWhenBrowsing] && !self.player.presentingPlayer) || (!Defaults[.lockPortraitWhenBrowsing] && self.player.presentingPlayer && !self.player.isOrientationLocked) | ||||
|             guard (!self.player.isOrientationLocked && !self.player.playingInPictureInPicture) || (!self.lockPortraitWhenBrowsing && !self.player.presentingPlayer) || (!self.lockPortraitWhenBrowsing && self.player.presentingPlayer && !self.player.isOrientationLocked) | ||||
|             else { | ||||
|                 self.logger.info("Only updating orientation without actions.") | ||||
|                 return | ||||
| @@ -52,7 +55,7 @@ final class OrientationModel { | ||||
|                 self.orientationDebouncer.callback = { | ||||
|                     DispatchQueue.main.async { | ||||
|                         if orientation.isLandscape { | ||||
|                             if Defaults[.enterFullscreenInLandscape], self.player.presentingPlayer { | ||||
|                             if self.enterFullscreenInLandscape, self.player.presentingPlayer { | ||||
|                                 self.logger.info("Entering fullscreen because orientation is landscape.") | ||||
|                                 self.player.controls.presentingControls = false | ||||
|                                 self.player.enterFullScreen(showControls: false) | ||||
| @@ -63,7 +66,7 @@ final class OrientationModel { | ||||
|                             if self.player.playingFullScreen { | ||||
|                                 self.player.exitFullScreen(showControls: false) | ||||
|                             } | ||||
|                             if Defaults[.lockPortraitWhenBrowsing] { | ||||
|                             if self.lockPortraitWhenBrowsing { | ||||
|                                 Orientation.lockOrientation(.portrait, andRotateTo: .portrait) | ||||
|                             } else { | ||||
|                                 Orientation.lockOrientation(OrientationTracker.shared.currentInterfaceOrientationMask, andRotateTo: orientation) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Arkadiusz Fal
					Arkadiusz Fal