mirror of
https://github.com/yattee/yattee.git
synced 2024-12-22 21:43:41 +00:00
Fullscreen handling changes
This commit is contained in:
parent
76df80578d
commit
9edcf66557
@ -88,26 +88,6 @@ final class PlayerControlsModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func toggleFullscreen(_ value: Bool) {
|
|
||||||
withAnimation(Animation.easeOut) {
|
|
||||||
resetTimer()
|
|
||||||
withAnimation(PlayerControls.animation) {
|
|
||||||
playingFullscreen = !value
|
|
||||||
}
|
|
||||||
|
|
||||||
#if os(iOS)
|
|
||||||
if playingFullscreen {
|
|
||||||
guard !(UIApplication.shared.windows.first?.windowScene?.interfaceOrientation.isLandscape ?? true) else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
Orientation.lockOrientation(.landscape, andRotateTo: .landscapeRight)
|
|
||||||
} else {
|
|
||||||
Orientation.lockOrientation(.allButUpsideDown, andRotateTo: .portrait)
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func reset() {
|
func reset() {
|
||||||
currentTime = .zero
|
currentTime = .zero
|
||||||
duration = .zero
|
duration = .zero
|
||||||
|
@ -382,8 +382,8 @@ final class PlayerModel: ObservableObject {
|
|||||||
return "\(formatter.string(from: NSNumber(value: rate))!)×"
|
return "\(formatter.string(from: NSNumber(value: rate))!)×"
|
||||||
}
|
}
|
||||||
|
|
||||||
func closeCurrentItem() {
|
func closeCurrentItem(finished: Bool = false) {
|
||||||
prepareCurrentItemForHistory()
|
prepareCurrentItemForHistory(finished: finished)
|
||||||
currentItem = nil
|
currentItem = nil
|
||||||
|
|
||||||
backend.closeItem()
|
backend.closeItem()
|
||||||
@ -498,4 +498,25 @@ final class PlayerModel: ObservableObject {
|
|||||||
|
|
||||||
currentArtwork = MPMediaItemArtwork(boundsSize: image!.size) { _ in image! }
|
currentArtwork = MPMediaItemArtwork(boundsSize: image!.size) { _ in image! }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func toggleFullscreen(_ isFullScreen: Bool) {
|
||||||
|
controls.resetTimer()
|
||||||
|
|
||||||
|
#if os(macOS)
|
||||||
|
Windows.player.toggleFullScreen()
|
||||||
|
#endif
|
||||||
|
|
||||||
|
controls.playingFullscreen = !isFullScreen
|
||||||
|
|
||||||
|
#if os(iOS)
|
||||||
|
if controls.playingFullscreen {
|
||||||
|
guard !(UIApplication.shared.windows.first?.windowScene?.interfaceOrientation.isLandscape ?? true) else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
Orientation.lockOrientation(.landscape, andRotateTo: .landscapeRight)
|
||||||
|
} else {
|
||||||
|
Orientation.lockOrientation(.allButUpsideDown, andRotateTo: .portrait)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -187,7 +187,7 @@ struct PlayerControls: View {
|
|||||||
"Fullscreen",
|
"Fullscreen",
|
||||||
systemImage: fullScreenLayout ? "arrow.down.right.and.arrow.up.left" : "arrow.up.left.and.arrow.down.right"
|
systemImage: fullScreenLayout ? "arrow.down.right.and.arrow.up.left" : "arrow.up.left.and.arrow.down.right"
|
||||||
) {
|
) {
|
||||||
model.toggleFullscreen(fullScreenLayout)
|
player.toggleFullscreen(fullScreenLayout)
|
||||||
}
|
}
|
||||||
#if !os(tvOS)
|
#if !os(tvOS)
|
||||||
.keyboardShortcut(fullScreenLayout ? .cancelAction : .defaultAction)
|
.keyboardShortcut(fullScreenLayout ? .cancelAction : .defaultAction)
|
||||||
|
@ -49,7 +49,6 @@ struct VideoPlayerView: View {
|
|||||||
.onOpenURL { OpenURLHandler(accounts: accounts, player: player).handle($0) }
|
.onOpenURL { OpenURLHandler(accounts: accounts, player: player).handle($0) }
|
||||||
.frame(minWidth: 950, minHeight: 700)
|
.frame(minWidth: 950, minHeight: 700)
|
||||||
#else
|
#else
|
||||||
GeometryReader { geometry in
|
|
||||||
HStack(spacing: 0) {
|
HStack(spacing: 0) {
|
||||||
content
|
content
|
||||||
.onAppear {
|
.onAppear {
|
||||||
@ -80,7 +79,6 @@ struct VideoPlayerView: View {
|
|||||||
motionManager = nil
|
motionManager = nil
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,6 +92,16 @@ struct YatteeApp: App {
|
|||||||
.background(
|
.background(
|
||||||
HostingWindowFinder { window in
|
HostingWindowFinder { window in
|
||||||
Windows.playerWindow = window
|
Windows.playerWindow = window
|
||||||
|
|
||||||
|
NotificationCenter.default.addObserver(
|
||||||
|
forName: NSWindow.willExitFullScreenNotification,
|
||||||
|
object: window,
|
||||||
|
queue: OperationQueue.main
|
||||||
|
) { _ in
|
||||||
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
||||||
|
self.player.controls.playingFullscreen = false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.onAppear { player.presentingPlayer = true }
|
.onAppear { player.presentingPlayer = true }
|
||||||
|
@ -42,6 +42,10 @@ enum Windows: String, CaseIterable {
|
|||||||
Self.main.focus()
|
Self.main.focus()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func toggleFullScreen() {
|
||||||
|
window?.toggleFullScreen(nil)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct HostingWindowFinder: NSViewRepresentable {
|
struct HostingWindowFinder: NSViewRepresentable {
|
||||||
|
Loading…
Reference in New Issue
Block a user