From 7d7bd40a897c809e411f68083c0fa7de05ec1642 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Sun, 21 May 2023 12:33:59 +0200 Subject: [PATCH] Add option "Close player on end of video" Fix #442 --- Model/Player/Backends/PlayerBackend.swift | 16 +++++++++------- Shared/Defaults.swift | 1 + Shared/Settings/PlayerSettings.swift | 6 ++++++ Shared/Settings/SettingsView.swift | 2 +- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Model/Player/Backends/PlayerBackend.swift b/Model/Player/Backends/PlayerBackend.swift index 51ed391d..3b09e957 100644 --- a/Model/Player/Backends/PlayerBackend.swift +++ b/Model/Player/Backends/PlayerBackend.swift @@ -110,13 +110,15 @@ extension PlayerBackend { model.prepareCurrentItemForHistory(finished: true) if model.queue.isEmpty { - #if os(tvOS) - if model.activeBackend == .appleAVPlayer { - model.avPlayerBackend.controller?.dismiss(animated: false) - } - #endif - model.resetQueue() - model.hide() + if Defaults[.closeVideoOnEOF] { + #if os(tvOS) + if model.activeBackend == .appleAVPlayer { + model.avPlayerBackend.controller?.dismiss(animated: false) + } + #endif + model.resetQueue() + model.hide() + } } else { model.advanceToNextItem() } diff --git a/Shared/Defaults.swift b/Shared/Defaults.swift index b3a4dac9..10a08d47 100644 --- a/Shared/Defaults.swift +++ b/Shared/Defaults.swift @@ -158,6 +158,7 @@ extension Defaults.Keys { #if !os(macOS) static let pauseOnEnteringBackground = Key("pauseOnEnteringBackground", default: true) #endif + static let closeVideoOnEOF = Key("closeVideoOnEOF", default: false) static let closePiPOnNavigation = Key("closePiPOnNavigation", default: false) static let closePiPOnOpeningPlayer = Key("closePiPOnOpeningPlayer", default: false) #if !os(macOS) diff --git a/Shared/Settings/PlayerSettings.swift b/Shared/Settings/PlayerSettings.swift index b4432012..df84f27a 100644 --- a/Shared/Settings/PlayerSettings.swift +++ b/Shared/Settings/PlayerSettings.swift @@ -13,6 +13,7 @@ struct PlayerSettings: View { #endif @Default(.expandVideoDescription) private var expandVideoDescription @Default(.pauseOnHidingPlayer) private var pauseOnHidingPlayer + @Default(.closeVideoOnEOF) private var closeVideoOnEOF #if os(iOS) @Default(.honorSystemOrientationLock) private var honorSystemOrientationLock @Default(.enterFullscreenInLandscape) private var enterFullscreenInLandscape @@ -66,6 +67,7 @@ struct PlayerSettings: View { sourcePicker } pauseOnHidingPlayerToggle + closeVideoOnEOFToggle #if !os(macOS) pauseOnEnteringBackgroundToogle #endif @@ -192,6 +194,10 @@ struct PlayerSettings: View { Toggle("Pause when player is closed", isOn: $pauseOnHidingPlayer) } + private var closeVideoOnEOFToggle: some View { + Toggle("Close video and player on end", isOn: $closeVideoOnEOF) + } + #if !os(macOS) private var pauseOnEnteringBackgroundToogle: some View { Toggle("Pause when entering background", isOn: $pauseOnEnteringBackground) diff --git a/Shared/Settings/SettingsView.swift b/Shared/Settings/SettingsView.swift index 075b2c78..28a061f4 100644 --- a/Shared/Settings/SettingsView.swift +++ b/Shared/Settings/SettingsView.swift @@ -245,7 +245,7 @@ struct SettingsView: View { case .browsing: return 880 case .player: - return 450 + return 480 case .controls: return 920 case .quality: