fix(runtime): harden application service boundaries

This commit is contained in:
edde746
2026-07-24 03:46:46 +02:00
parent 658da37b48
commit e0bf66eea8
309 changed files with 32574 additions and 4369 deletions
+12 -16
View File
@@ -9,7 +9,6 @@ class MpvPlayerCore: MpvPlayerCoreBase {
private var playbackActivity: NSObjectProtocol?
private var layerHiddenForOcclusion = false
private var layerHiddenForScreenSleep = false
private var isDisposed = false
/// True while any reason (occlusion, screen sleep) requires the layer hidden.
private var hasLayerHideReason: Bool {
@@ -102,8 +101,7 @@ class MpvPlayerCore: MpvPlayerCoreBase {
return true
}
override func configurePlatformMpvOptions() {
guard let mpv else { return }
override func configurePlatformMpvOptions(mpv: OpaquePointer) {
checkError(mpv_set_option_string(mpv, "ao", "avfoundation,coreaudio"))
}
@@ -130,7 +128,7 @@ class MpvPlayerCore: MpvPlayerCoreBase {
guard metalLayer != nil, !isPipActive else { return }
if visible && isVisible && !shouldRestoreOnWindowVisible {
isBackgrounded = false
setBackgrounded(false)
if metalLayer?.isHidden == true && !hasLayerHideReason {
setMetalLayerHidden(false)
redrawIfPausedAndVisible()
@@ -142,7 +140,7 @@ class MpvPlayerCore: MpvPlayerCoreBase {
isVisible = visible
shouldRestoreOnWindowVisible = !visible && restoreOnWindowVisible
isBackgrounded = !visible
setBackgrounded(!visible)
if visible {
shouldRestoreOnWindowVisible = false
@@ -212,9 +210,7 @@ class MpvPlayerCore: MpvPlayerCoreBase {
}
func dispose() {
if isDisposed { return }
isDisposed = true
guard beginDisposal() else { return }
endPlaybackActivity()
NotificationCenter.default.removeObserver(self)
NSWorkspace.shared.notificationCenter.removeObserver(self)
@@ -241,14 +237,14 @@ class MpvPlayerCore: MpvPlayerCoreBase {
}
@objc private func windowOcclusionDidChange(_ notification: Notification) {
guard metalLayer != nil, mpv != nil, !isPipActive else { return }
guard metalLayer != nil, hasActiveMpv, !isPipActive else { return }
let windowVisible = window?.occlusionState.contains(.visible) ?? true
if !windowVisible && !layerHiddenForOcclusion {
print("[MpvPlayerCore] Window occluded - hiding Metal layer")
setMetalLayerHidden(true)
layerHiddenForOcclusion = true
isBackgrounded = true
setBackgrounded(true)
endPlaybackActivity()
} else if windowVisible && layerHiddenForOcclusion {
print("[MpvPlayerCore] Window visible - showing Metal layer")
@@ -261,7 +257,7 @@ class MpvPlayerCore: MpvPlayerCoreBase {
}
redrawIfPausedAndVisible()
}
isBackgrounded = false
setBackgrounded(false)
if !pausedState {
beginPlaybackActivity()
}
@@ -269,18 +265,18 @@ class MpvPlayerCore: MpvPlayerCoreBase {
}
@objc private func screensDidSleep(_ notification: Notification) {
guard metalLayer != nil, mpv != nil, !layerHiddenForScreenSleep else { return }
guard metalLayer != nil, hasActiveMpv, !layerHiddenForScreenSleep else { return }
print("[MpvPlayerCore] Screens did sleep - hiding Metal layer")
layerHiddenForScreenSleep = true
// Hide even during PiP: nothing is visible while the displays are dark, and
// the hidden layer is what gates libmpv presentation (MPVKit >= 1.0.10).
setMetalLayerHidden(true)
isBackgrounded = true
setBackgrounded(true)
endPlaybackActivity()
}
@objc private func screensDidWake(_ notification: Notification) {
guard metalLayer != nil, mpv != nil, layerHiddenForScreenSleep else { return }
guard metalLayer != nil, hasActiveMpv, layerHiddenForScreenSleep else { return }
print("[MpvPlayerCore] Screens did wake - restoring Metal layer")
layerHiddenForScreenSleep = false
@@ -288,14 +284,14 @@ class MpvPlayerCore: MpvPlayerCoreBase {
// Layer is hosted by the PiP window; just unhide it there. Attach/frame
// logic is owned by the PiP controller.
setMetalLayerHidden(false)
isBackgrounded = false
setBackgrounded(false)
} else if !layerHiddenForOcclusion {
if shouldRestoreOnWindowVisible {
restoreMetalLayerAfterOcclusion()
} else {
setMetalLayerHidden(!isVisible)
}
isBackgrounded = !isVisible
setBackgrounded(!isVisible)
}
// else: window still occluded; windowOcclusionDidChange owns the restore.
+2 -1
View File
@@ -350,7 +350,8 @@ extension MpvPlayerPlugin: MpvPipDelegate {
func pipSetPlaying(_ playing: Bool) {
guard let playerCore else { return }
playerCore.setPropertyAsync("pause", value: playing ? "no" : "yes") { [weak self] _ in
playerCore.setPropertyAsync("pause", value: playing ? "no" : "yes") { [weak self] propertyResult in
guard case .success = propertyResult else { return }
self?.pipController?.setPlaying(playing)
playerCore.setPaused(!playing)
}