Add "Pause when entering background" option (#198)

This commit is contained in:
Arkadiusz Fal 2022-06-30 11:46:20 +02:00
parent 12e427bcb8
commit f10aa1abd9
3 changed files with 16 additions and 2 deletions

View File

@ -522,7 +522,7 @@ final class PlayerModel: ObservableObject {
} }
#else #else
func handleEnterForeground() { func handleEnterForeground() {
setNeedsDrawing(true) setNeedsDrawing(presentingPlayer)
guard closePiPAndOpenPlayerOnEnteringForeground, playingInPictureInPicture else { guard closePiPAndOpenPlayerOnEnteringForeground, playingInPictureInPicture else {
return return
@ -534,7 +534,8 @@ final class PlayerModel: ObservableObject {
func handleEnterBackground() { func handleEnterBackground() {
setNeedsDrawing(false) setNeedsDrawing(false)
if !playingInPictureInPicture, !musicMode {
if Defaults[.pauseOnEnteringBackground], !playingInPictureInPicture, !musicMode {
pause() pause()
} }
} }

View File

@ -64,6 +64,9 @@ extension Defaults.Keys {
static let commentsPlacement = Key<CommentsPlacement>("commentsPlacement", default: .separate) static let commentsPlacement = Key<CommentsPlacement>("commentsPlacement", default: .separate)
#endif #endif
static let pauseOnHidingPlayer = Key<Bool>("pauseOnHidingPlayer", default: defaultForPauseOnHidingPlayer) static let pauseOnHidingPlayer = Key<Bool>("pauseOnHidingPlayer", default: defaultForPauseOnHidingPlayer)
#if !os(macOS)
static let pauseOnEnteringBackground = Key<Bool>("pauseOnEnteringBackground", default: true)
#endif
static let closeLastItemOnPlaybackEnd = Key<Bool>("closeLastItemOnPlaybackEnd", default: false) static let closeLastItemOnPlaybackEnd = Key<Bool>("closeLastItemOnPlaybackEnd", default: false)
static let closePiPOnNavigation = Key<Bool>("closePiPOnNavigation", default: false) static let closePiPOnNavigation = Key<Bool>("closePiPOnNavigation", default: false)

View File

@ -20,6 +20,7 @@ struct PlayerSettings: View {
@Default(.closePiPOnNavigation) private var closePiPOnNavigation @Default(.closePiPOnNavigation) private var closePiPOnNavigation
@Default(.closePiPOnOpeningPlayer) private var closePiPOnOpeningPlayer @Default(.closePiPOnOpeningPlayer) private var closePiPOnOpeningPlayer
#if !os(macOS) #if !os(macOS)
@Default(.pauseOnEnteringBackground) private var pauseOnEnteringBackground
@Default(.closePiPAndOpenPlayerOnEnteringForeground) private var closePiPAndOpenPlayerOnEnteringForeground @Default(.closePiPAndOpenPlayerOnEnteringForeground) private var closePiPAndOpenPlayerOnEnteringForeground
#endif #endif
@ -59,6 +60,9 @@ struct PlayerSettings: View {
sourcePicker sourcePicker
qualityPicker qualityPicker
pauseOnHidingPlayerToggle pauseOnHidingPlayerToggle
#if !os(macOS)
pauseOnEnteringBackgroundToogle
#endif
closeLastItemOnPlaybackEndToggle closeLastItemOnPlaybackEndToggle
} }
@ -190,6 +194,12 @@ struct PlayerSettings: View {
Toggle("Pause when player is closed", isOn: $pauseOnHidingPlayer) 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 { private var closeLastItemOnPlaybackEndToggle: some View {
Toggle("Close video after playing last in the queue", isOn: $closeLastItemOnPlaybackEnd) Toggle("Close video after playing last in the queue", isOn: $closeLastItemOnPlaybackEnd)
} }