mirror of
https://github.com/yattee/yattee.git
synced 2024-12-22 21:43:41 +00:00
Merge pull request #616 from rickykresslein/main
Add skip, play/pause, and fullscreen shortcuts to macOS player
This commit is contained in:
commit
76801a34ee
@ -177,6 +177,11 @@ final class PlayerModel: ObservableObject {
|
||||
@Default(.playerRate) var playerRate
|
||||
@Default(.systemControlsSeekDuration) var systemControlsSeekDuration
|
||||
|
||||
#if os(macOS)
|
||||
@Default(.buttonBackwardSeekDuration) private var buttonBackwardSeekDuration
|
||||
@Default(.buttonForwardSeekDuration) private var buttonForwardSeekDuration
|
||||
#endif
|
||||
|
||||
#if !os(macOS)
|
||||
@Default(.closePiPAndOpenPlayerOnEnteringForeground) var closePiPAndOpenPlayerOnEnteringForeground
|
||||
#endif
|
||||
@ -188,6 +193,10 @@ final class PlayerModel: ObservableObject {
|
||||
var rateToRestore: Float?
|
||||
private var remoteCommandCenterConfigured = false
|
||||
|
||||
#if os(macOS)
|
||||
var keyPressMonitor: Any?
|
||||
#endif
|
||||
|
||||
init() {
|
||||
#if !os(macOS)
|
||||
mpvBackend.controller = mpvController
|
||||
@ -212,6 +221,7 @@ final class PlayerModel: ObservableObject {
|
||||
#if os(macOS)
|
||||
if presentingPlayer {
|
||||
Windows.player.focus()
|
||||
assignKeyPressMonitor()
|
||||
return
|
||||
}
|
||||
#endif
|
||||
@ -227,6 +237,7 @@ final class PlayerModel: ObservableObject {
|
||||
#if os(macOS)
|
||||
Windows.player.open()
|
||||
Windows.player.focus()
|
||||
assignKeyPressMonitor()
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -246,6 +257,7 @@ final class PlayerModel: ObservableObject {
|
||||
}
|
||||
|
||||
#if os(macOS)
|
||||
destroyKeyPressMonitor()
|
||||
Windows.player.hide()
|
||||
#endif
|
||||
}
|
||||
@ -1146,4 +1158,46 @@ final class PlayerModel: ObservableObject {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
#if os(macOS)
|
||||
private func assignKeyPressMonitor() {
|
||||
keyPressMonitor = NSEvent.addLocalMonitorForEvents(matching: .keyDown) { keyEvent -> NSEvent? in
|
||||
switch keyEvent.keyCode {
|
||||
case 124:
|
||||
if !self.liveStreamInAVPlayer {
|
||||
let interval = TimeInterval(self.buttonForwardSeekDuration) ?? 10
|
||||
self.backend.seek(
|
||||
relative: .secondsInDefaultTimescale(interval),
|
||||
seekType: .userInteracted
|
||||
)
|
||||
}
|
||||
case 123:
|
||||
if !self.liveStreamInAVPlayer {
|
||||
let interval = TimeInterval(self.buttonBackwardSeekDuration) ?? 10
|
||||
self.backend.seek(
|
||||
relative: .secondsInDefaultTimescale(-interval),
|
||||
seekType: .userInteracted
|
||||
)
|
||||
}
|
||||
case 3:
|
||||
self.toggleFullscreen(
|
||||
self.playingFullScreen,
|
||||
showControls: false
|
||||
)
|
||||
case 49:
|
||||
if !self.controls.isLoadingVideo {
|
||||
self.backend.togglePlay()
|
||||
}
|
||||
default: return keyEvent
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
private func destroyKeyPressMonitor() {
|
||||
if let keyPressMonitor = keyPressMonitor {
|
||||
NSEvent.removeMonitor(keyPressMonitor)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user