From 23075751c3d5436d3fd19c464eed1094aa8793e4 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Thu, 30 Jun 2022 11:46:20 +0200 Subject: [PATCH] Add "Pause when entering background" option (#198) --- Model/Player/PlayerModel.swift | 5 +++-- Shared/Defaults.swift | 3 +++ Shared/Settings/PlayerSettings.swift | 10 ++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Model/Player/PlayerModel.swift b/Model/Player/PlayerModel.swift index efd6f074..4590e0d9 100644 --- a/Model/Player/PlayerModel.swift +++ b/Model/Player/PlayerModel.swift @@ -522,7 +522,7 @@ final class PlayerModel: ObservableObject { } #else func handleEnterForeground() { - setNeedsDrawing(true) + setNeedsDrawing(presentingPlayer) guard closePiPAndOpenPlayerOnEnteringForeground, playingInPictureInPicture else { return @@ -534,7 +534,8 @@ final class PlayerModel: ObservableObject { func handleEnterBackground() { setNeedsDrawing(false) - if !playingInPictureInPicture, !musicMode { + + if Defaults[.pauseOnEnteringBackground], !playingInPictureInPicture, !musicMode { pause() } } diff --git a/Shared/Defaults.swift b/Shared/Defaults.swift index 8246eb97..0df704dc 100644 --- a/Shared/Defaults.swift +++ b/Shared/Defaults.swift @@ -64,6 +64,9 @@ extension Defaults.Keys { static let commentsPlacement = Key("commentsPlacement", default: .separate) #endif static let pauseOnHidingPlayer = Key("pauseOnHidingPlayer", default: defaultForPauseOnHidingPlayer) + #if !os(macOS) + static let pauseOnEnteringBackground = Key("pauseOnEnteringBackground", default: true) + #endif static let closeLastItemOnPlaybackEnd = Key("closeLastItemOnPlaybackEnd", default: false) static let closePiPOnNavigation = Key("closePiPOnNavigation", default: false) diff --git a/Shared/Settings/PlayerSettings.swift b/Shared/Settings/PlayerSettings.swift index 72b9c524..60f7d0ef 100644 --- a/Shared/Settings/PlayerSettings.swift +++ b/Shared/Settings/PlayerSettings.swift @@ -20,6 +20,7 @@ struct PlayerSettings: View { @Default(.closePiPOnNavigation) private var closePiPOnNavigation @Default(.closePiPOnOpeningPlayer) private var closePiPOnOpeningPlayer #if !os(macOS) + @Default(.pauseOnEnteringBackground) private var pauseOnEnteringBackground @Default(.closePiPAndOpenPlayerOnEnteringForeground) private var closePiPAndOpenPlayerOnEnteringForeground #endif @@ -59,6 +60,9 @@ struct PlayerSettings: View { sourcePicker qualityPicker pauseOnHidingPlayerToggle + #if !os(macOS) + pauseOnEnteringBackgroundToogle + #endif closeLastItemOnPlaybackEndToggle } @@ -190,6 +194,12 @@ struct PlayerSettings: View { Toggle("Pause when player is closed", isOn: $pauseOnHidingPlayer) } + #if !os(macOS) + private var pauseOnEnteringBackgroundToogle: some View { + Toggle("Pause when entering background", isOn: $pauseOnEnteringBackground) + } + #endif + private var closeLastItemOnPlaybackEndToggle: some View { Toggle("Close video after playing last in the queue", isOn: $closeLastItemOnPlaybackEnd) }