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

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

View File

@ -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()
}
}

View File

@ -64,6 +64,9 @@ extension Defaults.Keys {
static let commentsPlacement = Key<CommentsPlacement>("commentsPlacement", default: .separate)
#endif
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 closePiPOnNavigation = Key<Bool>("closePiPOnNavigation", default: false)

View File

@ -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)
}