parent
f2f8f8be14
commit
30e944ffc4
|
@ -38,6 +38,8 @@ struct SupportedOrientationsPreferenceKey: PreferenceKey {
|
||||||
|
|
||||||
static var defaultValue: UIInterfaceOrientationMask = .allButUpsideDown
|
static var defaultValue: UIInterfaceOrientationMask = .allButUpsideDown
|
||||||
|
|
||||||
static func reduce(value: inout UIInterfaceOrientationMask, nextValue: () -> UIInterfaceOrientationMask) {}
|
static func reduce(value: inout UIInterfaceOrientationMask, nextValue: () -> UIInterfaceOrientationMask) {
|
||||||
|
value = nextValue()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -81,6 +81,8 @@ public class UIPreferencesHostingController: UIHostingController<AnyView> {
|
||||||
didSet {
|
didSet {
|
||||||
if #available(iOS 16, *) {
|
if #available(iOS 16, *) {
|
||||||
setNeedsUpdateOfSupportedInterfaceOrientations()
|
setNeedsUpdateOfSupportedInterfaceOrientations()
|
||||||
|
} else {
|
||||||
|
AppRotationUtility.lockOrientation(_orientations)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,3 +113,27 @@ public class UIPreferencesHostingController: UIHostingController<AnyView> {
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: remove after iOS 15 support removed
|
||||||
|
|
||||||
|
#if os(iOS)
|
||||||
|
enum AppRotationUtility {
|
||||||
|
|
||||||
|
static func lockOrientation(_ orientationLock: UIInterfaceOrientationMask) {
|
||||||
|
|
||||||
|
guard UIDevice.current.userInterfaceIdiom == .phone else { return }
|
||||||
|
|
||||||
|
let rotateOrientation: UIInterfaceOrientation
|
||||||
|
|
||||||
|
switch orientationLock {
|
||||||
|
case .landscape:
|
||||||
|
rotateOrientation = .landscapeRight
|
||||||
|
default:
|
||||||
|
rotateOrientation = .portrait
|
||||||
|
}
|
||||||
|
|
||||||
|
UIDevice.current.setValue(rotateOrientation.rawValue, forKey: "orientation")
|
||||||
|
UINavigationController.attemptRotationToDeviceOrientation()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
|
@ -26,11 +26,22 @@ final class LiveVideoPlayerCoordinator: NavigationCoordinatable {
|
||||||
self.videoPlayerManager = manager
|
self.videoPlayerManager = manager
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if os(iOS)
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
func makeStart() -> some View {
|
private var versionedView: some View {
|
||||||
#if os(iOS)
|
if #available(iOS 16, *) {
|
||||||
|
PreferencesView {
|
||||||
PreferencesView {
|
Group {
|
||||||
|
if Defaults[.VideoPlayer.videoPlayerType] == .swiftfin {
|
||||||
|
LiveVideoPlayer(manager: self.videoPlayerManager)
|
||||||
|
} else {
|
||||||
|
LiveNativeVideoPlayer(manager: self.videoPlayerManager)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.preferredColorScheme(.dark)
|
||||||
|
.supportedOrientations(UIDevice.isPhone ? .landscape : .allButUpsideDown)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
Group {
|
Group {
|
||||||
if Defaults[.VideoPlayer.videoPlayerType] == .swiftfin {
|
if Defaults[.VideoPlayer.videoPlayerType] == .swiftfin {
|
||||||
LiveVideoPlayer(manager: self.videoPlayerManager)
|
LiveVideoPlayer(manager: self.videoPlayerManager)
|
||||||
|
@ -40,10 +51,20 @@ final class LiveVideoPlayerCoordinator: NavigationCoordinatable {
|
||||||
}
|
}
|
||||||
.preferredColorScheme(.dark)
|
.preferredColorScheme(.dark)
|
||||||
.supportedOrientations(UIDevice.isPhone ? .landscape : .allButUpsideDown)
|
.supportedOrientations(UIDevice.isPhone ? .landscape : .allButUpsideDown)
|
||||||
|
.preferredColorScheme(.dark)
|
||||||
|
.supportedOrientations(UIDevice.isPhone ? .landscape : .allButUpsideDown)
|
||||||
}
|
}
|
||||||
.ignoresSafeArea()
|
}
|
||||||
.backport
|
#endif
|
||||||
.persistentSystemOverlays(.hidden)
|
|
||||||
|
@ViewBuilder
|
||||||
|
func makeStart() -> some View {
|
||||||
|
#if os(iOS)
|
||||||
|
|
||||||
|
versionedView
|
||||||
|
.ignoresSafeArea()
|
||||||
|
.backport
|
||||||
|
.persistentSystemOverlays(.hidden)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
|
|
@ -26,16 +26,24 @@ final class VideoPlayerCoordinator: NavigationCoordinatable {
|
||||||
self.videoPlayerManager = manager
|
self.videoPlayerManager = manager
|
||||||
}
|
}
|
||||||
|
|
||||||
@ViewBuilder
|
// TODO: removed after iOS 15 support removed
|
||||||
func makeStart() -> some View {
|
|
||||||
#if os(iOS)
|
|
||||||
|
|
||||||
// Some settings have to apply to the root PreferencesView and this
|
#if os(iOS)
|
||||||
// one - separately.
|
@ViewBuilder
|
||||||
// It is assumed that because Stinsen adds a lot of views that the
|
private var versionedView: some View {
|
||||||
// PreferencesView isn't in the right place in the VC chain so that
|
if #available(iOS 16, *) {
|
||||||
// it can apply the settings, even SwiftUI settings.
|
PreferencesView {
|
||||||
PreferencesView {
|
Group {
|
||||||
|
if Defaults[.VideoPlayer.videoPlayerType] == .swiftfin {
|
||||||
|
VideoPlayer(manager: self.videoPlayerManager)
|
||||||
|
} else {
|
||||||
|
NativeVideoPlayer(manager: self.videoPlayerManager)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.preferredColorScheme(.dark)
|
||||||
|
.supportedOrientations(UIDevice.isPhone ? .landscape : .allButUpsideDown)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
Group {
|
Group {
|
||||||
if Defaults[.VideoPlayer.videoPlayerType] == .swiftfin {
|
if Defaults[.VideoPlayer.videoPlayerType] == .swiftfin {
|
||||||
VideoPlayer(manager: self.videoPlayerManager)
|
VideoPlayer(manager: self.videoPlayerManager)
|
||||||
|
@ -46,9 +54,22 @@ final class VideoPlayerCoordinator: NavigationCoordinatable {
|
||||||
.preferredColorScheme(.dark)
|
.preferredColorScheme(.dark)
|
||||||
.supportedOrientations(UIDevice.isPhone ? .landscape : .allButUpsideDown)
|
.supportedOrientations(UIDevice.isPhone ? .landscape : .allButUpsideDown)
|
||||||
}
|
}
|
||||||
.ignoresSafeArea()
|
}
|
||||||
.backport
|
#endif
|
||||||
.persistentSystemOverlays(.hidden)
|
|
||||||
|
@ViewBuilder
|
||||||
|
func makeStart() -> some View {
|
||||||
|
#if os(iOS)
|
||||||
|
|
||||||
|
// Some settings have to apply to the root PreferencesView and this
|
||||||
|
// one - separately.
|
||||||
|
// It is assumed that because Stinsen adds a lot of views that the
|
||||||
|
// PreferencesView isn't in the right place in the VC chain so that
|
||||||
|
// it can apply the settings, even SwiftUI settings.
|
||||||
|
versionedView
|
||||||
|
.ignoresSafeArea()
|
||||||
|
.backport
|
||||||
|
.persistentSystemOverlays(.hidden)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
if Defaults[.VideoPlayer.videoPlayerType] == .swiftfin {
|
if Defaults[.VideoPlayer.videoPlayerType] == .swiftfin {
|
||||||
|
|
|
@ -86,4 +86,6 @@ extension Notifications.Key {
|
||||||
static let didDeleteServer = NotificationKey("didDeleteServer")
|
static let didDeleteServer = NotificationKey("didDeleteServer")
|
||||||
|
|
||||||
static let didChangeUserProfileImage = NotificationKey("didChangeUserProfileImage")
|
static let didChangeUserProfileImage = NotificationKey("didChangeUserProfileImage")
|
||||||
|
|
||||||
|
static let didStartPlayback = NotificationKey("didStartPlayback")
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,31 +71,49 @@ struct SwiftfinApp: App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var body: some Scene {
|
// TODO: removed after iOS 15 support removed
|
||||||
WindowGroup {
|
|
||||||
|
@ViewBuilder
|
||||||
|
private var versionedView: some View {
|
||||||
|
if #available(iOS 16, *) {
|
||||||
PreferencesView {
|
PreferencesView {
|
||||||
MainCoordinator()
|
MainCoordinator()
|
||||||
.view()
|
.view()
|
||||||
.supportedOrientations(UIDevice.isPad ? .allButUpsideDown : .portrait)
|
.supportedOrientations(UIDevice.isPad ? .allButUpsideDown : .portrait)
|
||||||
}
|
}
|
||||||
.ignoresSafeArea()
|
} else {
|
||||||
.onNotification(UIApplication.didEnterBackgroundNotification) { _ in
|
PreferencesView {
|
||||||
Defaults[.backgroundTimeStamp] = Date.now
|
PreferencesView {
|
||||||
}
|
MainCoordinator()
|
||||||
.onNotification(UIApplication.willEnterForegroundNotification) { _ in
|
.view()
|
||||||
|
.supportedOrientations(UIDevice.isPad ? .allButUpsideDown : .portrait)
|
||||||
// TODO: needs to check if any background playback is happening
|
|
||||||
// - atow, background video playback isn't officially supported
|
|
||||||
let backgroundedInterval = Date.now.timeIntervalSince(Defaults[.backgroundTimeStamp])
|
|
||||||
|
|
||||||
if backgroundedInterval > Defaults[.backgroundSignOutInterval] {
|
|
||||||
Defaults[.lastSignedInUserID] = nil
|
|
||||||
Container.shared.currentUserSession.reset()
|
|
||||||
Notifications[.didSignOut].post()
|
|
||||||
}
|
}
|
||||||
|
.ignoresSafeArea()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var body: some Scene {
|
||||||
|
WindowGroup {
|
||||||
|
versionedView
|
||||||
|
.ignoresSafeArea()
|
||||||
|
.onNotification(UIApplication.didEnterBackgroundNotification) { _ in
|
||||||
|
Defaults[.backgroundTimeStamp] = Date.now
|
||||||
|
}
|
||||||
|
.onNotification(UIApplication.willEnterForegroundNotification) { _ in
|
||||||
|
|
||||||
|
// TODO: needs to check if any background playback is happening
|
||||||
|
// - atow, background video playback isn't officially supported
|
||||||
|
let backgroundedInterval = Date.now.timeIntervalSince(Defaults[.backgroundTimeStamp])
|
||||||
|
|
||||||
|
if backgroundedInterval > Defaults[.backgroundSignOutInterval] {
|
||||||
|
Defaults[.lastSignedInUserID] = nil
|
||||||
|
Container.shared.currentUserSession.reset()
|
||||||
|
Notifications[.didSignOut].post()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension UINavigationController {
|
extension UINavigationController {
|
||||||
|
|
Loading…
Reference in New Issue