Performance improvements

This commit is contained in:
Arkadiusz Fal 2022-08-23 23:14:13 +02:00
parent 4dbdd00829
commit 9197309115
5 changed files with 33 additions and 44 deletions

View File

@ -37,39 +37,25 @@ final class PlayerControlsModel: ObservableObject {
} }
func handlePresentationChange() { func handlePresentationChange() {
DispatchQueue.main.async { [weak self] in guard let player = player else { return }
guard let self = self, if presentingControls {
let player = self.player else { return } player.backend.startControlsUpdates()
if self.presentingControls { resetTimer()
player.backend.startControlsUpdates() } else {
self.resetTimer() if !player.musicMode {
player.backend.stopControlsUpdates()
removeTimer()
} else { } else {
if !player.musicMode { presentingControls = true
player.backend.stopControlsUpdates()
self.removeTimer()
} else {
self.presentingControls = true
}
} }
} }
} }
func handleSettingsOverlayPresentationChange() { func handleSettingsOverlayPresentationChange() {
player?.backend.setNeedsNetworkStateUpdates(presentingControlsOverlay && Defaults[.showMPVPlaybackStats]) player?.backend.setNeedsNetworkStateUpdates(presentingControlsOverlay && Defaults[.showMPVPlaybackStats])
if presentingControlsOverlay {
removeTimer()
} else {
resetTimer()
}
} }
func handleDetailsOverlayPresentationChange() { func handleDetailsOverlayPresentationChange() {}
if presentingDetailsOverlay {
removeTimer()
} else {
resetTimer()
}
}
var presentingOverlays: Bool { var presentingOverlays: Bool {
presentingDetailsOverlay || presentingControlsOverlay presentingDetailsOverlay || presentingControlsOverlay

View File

@ -136,12 +136,7 @@ struct PlayerControls: View {
} }
.onChange(of: model.presentingOverlays) { newValue in .onChange(of: model.presentingOverlays) { newValue in
if newValue { if newValue {
player.backend.stopControlsUpdates() model.hide()
} else {
#if os(tvOS)
focusedField = .play
#endif
player.backend.startControlsUpdates()
} }
} }
#if os(tvOS) #if os(tvOS)

View File

@ -103,7 +103,7 @@ struct VideoDescription: View {
} }
func updateUIView(_: UIViewType, context _: Context) { func updateUIView(_: UIViewType, context _: Context) {
customizeLabel() updatePreferredMaxLayoutWidth()
} }
func customizeLabel() { func customizeLabel() {
@ -143,6 +143,10 @@ struct VideoDescription: View {
} }
} }
} }
func updatePreferredMaxLayoutWidth() {
label.preferredMaxLayoutWidth = (detailsSize?.width ?? 330) - 30
}
} }
#endif #endif

View File

@ -454,10 +454,9 @@ struct VideoPlayerView: View {
if drag > 60, if drag > 60,
player.playingFullScreen player.playingFullScreen
{ {
player.exitFullScreen() player.exitFullScreen(showControls: false)
if Defaults[.rotateToPortraitOnExitFullScreen] { if Defaults[.rotateToPortraitOnExitFullScreen] {
Orientation.lockOrientation(.allButUpsideDown, andRotateTo: .portrait) Orientation.lockOrientation(.allButUpsideDown, andRotateTo: .portrait)
playerControls.show()
} }
} }
} }

View File

@ -27,20 +27,25 @@ struct ShareButton: View {
private var instanceActions: some View { private var instanceActions: some View {
Group { Group {
if let url = player.playerAPI.shareURL(contentItem) { Button(labelForShareURL(accounts.app.name)) {
Button(labelForShareURL(accounts.app.name)) { if let url = player.playerAPI.shareURL(contentItem) {
shareAction(url) shareAction(url)
} else {
navigation.presentAlert(
title: "Could not create share link",
message: "For custom locations you can configure Frontend URL in Locations settings"
)
} }
}
if contentItemIsPlayerCurrentVideo { if contentItemIsPlayerCurrentVideo {
Button(labelForShareURL(accounts.app.name, withTime: true)) { Button(labelForShareURL(accounts.app.name, withTime: true)) {
shareAction( shareAction(
player.playerAPI.shareURL( player.playerAPI.shareURL(
contentItem, contentItem,
time: player.backend.currentTime time: player.backend.currentTime
)! )!
) )
}
} }
} }
} }