yattee/Model/Player/ControlsOverlayModel.swift

33 lines
903 B
Swift
Raw Normal View History

2022-09-01 23:05:31 +00:00
import Defaults
import Foundation
import SwiftUI
final class ControlOverlaysModel: ObservableObject {
2022-11-17 21:47:45 +00:00
static let animation = Animation.easeInOut(duration: 0.2)
2022-09-01 23:05:31 +00:00
static let shared = ControlOverlaysModel()
2022-11-17 21:47:45 +00:00
@Published private(set) var presenting = false { didSet { handlePresentationChange() } }
2022-09-01 23:05:31 +00:00
private lazy var controls = PlayerControlsModel.shared
private lazy var player: PlayerModel! = PlayerModel.shared
func toggle() {
presenting.toggle()
controls.objectWillChange.send()
}
2022-11-17 21:47:45 +00:00
func hide() {
presenting = false
controls.objectWillChange.send()
}
func show() {
presenting = true
controls.objectWillChange.send()
}
2022-09-01 23:05:31 +00:00
private func handlePresentationChange() {
2022-09-28 14:27:01 +00:00
guard let player else { return }
2022-09-01 23:05:31 +00:00
player.backend.setNeedsNetworkStateUpdates(presenting && Defaults[.showMPVPlaybackStats])
}
}