From 9ca905e5c7708821a97ccc5ba701d6b4ae6cfd0d Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Tue, 23 Aug 2022 23:14:13 +0200 Subject: [PATCH] Performance improvements --- Model/Player/PlayerControlsModel.swift | 34 ++++++--------------- Shared/Player/Controls/PlayerControls.swift | 7 +---- Shared/Player/VideoDescription.swift | 6 +++- Shared/Player/VideoPlayerView.swift | 3 +- Shared/Views/ShareButton.swift | 27 +++++++++------- 5 files changed, 33 insertions(+), 44 deletions(-) diff --git a/Model/Player/PlayerControlsModel.swift b/Model/Player/PlayerControlsModel.swift index 79a08a42..48bbfc84 100644 --- a/Model/Player/PlayerControlsModel.swift +++ b/Model/Player/PlayerControlsModel.swift @@ -37,39 +37,25 @@ final class PlayerControlsModel: ObservableObject { } func handlePresentationChange() { - DispatchQueue.main.async { [weak self] in - guard let self = self, - let player = self.player else { return } - if self.presentingControls { - player.backend.startControlsUpdates() - self.resetTimer() + guard let player = player else { return } + if presentingControls { + player.backend.startControlsUpdates() + resetTimer() + } else { + if !player.musicMode { + player.backend.stopControlsUpdates() + removeTimer() } else { - if !player.musicMode { - player.backend.stopControlsUpdates() - self.removeTimer() - } else { - self.presentingControls = true - } + presentingControls = true } } } func handleSettingsOverlayPresentationChange() { player?.backend.setNeedsNetworkStateUpdates(presentingControlsOverlay && Defaults[.showMPVPlaybackStats]) - if presentingControlsOverlay { - removeTimer() - } else { - resetTimer() - } } - func handleDetailsOverlayPresentationChange() { - if presentingDetailsOverlay { - removeTimer() - } else { - resetTimer() - } - } + func handleDetailsOverlayPresentationChange() {} var presentingOverlays: Bool { presentingDetailsOverlay || presentingControlsOverlay diff --git a/Shared/Player/Controls/PlayerControls.swift b/Shared/Player/Controls/PlayerControls.swift index be2ffda5..d7ab0d98 100644 --- a/Shared/Player/Controls/PlayerControls.swift +++ b/Shared/Player/Controls/PlayerControls.swift @@ -136,12 +136,7 @@ struct PlayerControls: View { } .onChange(of: model.presentingOverlays) { newValue in if newValue { - player.backend.stopControlsUpdates() - } else { - #if os(tvOS) - focusedField = .play - #endif - player.backend.startControlsUpdates() + model.hide() } } #if os(tvOS) diff --git a/Shared/Player/VideoDescription.swift b/Shared/Player/VideoDescription.swift index e6614106..70ee48e9 100644 --- a/Shared/Player/VideoDescription.swift +++ b/Shared/Player/VideoDescription.swift @@ -103,7 +103,7 @@ struct VideoDescription: View { } func updateUIView(_: UIViewType, context _: Context) { - customizeLabel() + updatePreferredMaxLayoutWidth() } func customizeLabel() { @@ -143,6 +143,10 @@ struct VideoDescription: View { } } } + + func updatePreferredMaxLayoutWidth() { + label.preferredMaxLayoutWidth = (detailsSize?.width ?? 330) - 30 + } } #endif diff --git a/Shared/Player/VideoPlayerView.swift b/Shared/Player/VideoPlayerView.swift index a384832c..dc758a52 100644 --- a/Shared/Player/VideoPlayerView.swift +++ b/Shared/Player/VideoPlayerView.swift @@ -454,10 +454,9 @@ struct VideoPlayerView: View { if drag > 60, player.playingFullScreen { - player.exitFullScreen() + player.exitFullScreen(showControls: false) if Defaults[.rotateToPortraitOnExitFullScreen] { Orientation.lockOrientation(.allButUpsideDown, andRotateTo: .portrait) - playerControls.show() } } } diff --git a/Shared/Views/ShareButton.swift b/Shared/Views/ShareButton.swift index f935ec70..3888220b 100644 --- a/Shared/Views/ShareButton.swift +++ b/Shared/Views/ShareButton.swift @@ -27,20 +27,25 @@ struct ShareButton: View { private var instanceActions: some View { 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) + } else { + navigation.presentAlert( + title: "Could not create share link", + message: "For custom locations you can configure Frontend URL in Locations settings" + ) } + } - if contentItemIsPlayerCurrentVideo { - Button(labelForShareURL(accounts.app.name, withTime: true)) { - shareAction( - player.playerAPI.shareURL( - contentItem, - time: player.backend.currentTime - )! - ) - } + if contentItemIsPlayerCurrentVideo { + Button(labelForShareURL(accounts.app.name, withTime: true)) { + shareAction( + player.playerAPI.shareURL( + contentItem, + time: player.backend.currentTime + )! + ) } } }