summaryrefslogtreecommitdiffstats
path: root/osdep/mac
diff options
context:
space:
mode:
authorder richter <der.richter@gmx.de>2024-04-27 17:47:19 +0200
committerder richter <der.richter@gmx.de>2024-04-28 20:21:18 +0200
commit6df06e5dc59b01902592b2bf624ced548310d0bf (patch)
treee363fed1aa417535a0c9b64e9070db5012c69df4 /osdep/mac
parent69d70148c782f82598b2cae4fcc8d2c47a98822d (diff)
downloadmpv-6df06e5dc59b01902592b2bf624ced548310d0bf.tar.bz2
mpv-6df06e5dc59b01902592b2bf624ced548310d0bf.tar.xz
mac/touchbar: use KVO block API instead of old obj-c instance method
Diffstat (limited to 'osdep/mac')
-rw-r--r--osdep/mac/touch_bar.swift15
1 files changed, 5 insertions, 10 deletions
diff --git a/osdep/mac/touch_bar.swift b/osdep/mac/touch_bar.swift
index 8e64c51b22..89c52702f4 100644
--- a/osdep/mac/touch_bar.swift
+++ b/osdep/mac/touch_bar.swift
@@ -75,6 +75,7 @@ class TouchBar: NSTouchBar, NSTouchBarDelegate, EventSubscriber {
var event: EventHelper? { get { return appHub.event } }
var input: InputHelper { get { return appHub.input } }
var configs: [NSTouchBarItem.Identifier:Config] = [:]
+ var observers: [NSKeyValueObservation] = []
var isPaused: Bool = false { didSet { updatePlayButton() } }
var position: Double = 0 { didSet { updateTouchBarTimeItems() } }
var duration: Double = 0 { didSet { updateTouchBarTimeItems() } }
@@ -138,7 +139,7 @@ class TouchBar: NSTouchBar, NSTouchBarDelegate, EventSubscriber {
defaultItemIdentifiers = [.play, .previousItem, .nextItem, .seekBar]
customizationAllowedItemIdentifiers = [.play, .seekBar, .previousItem, .nextItem,
.previousChapter, .nextChapter, .cycleAudio, .cycleSubtitle, .currentPosition, .timeLeft]
- addObserver(self, forKeyPath: "visible", options: [.new], context: nil)
+ observers += [observe(\.isVisible, options: [.new]) { object, change in self.changed(visibility: change.newValue) }]
event?.subscribe(self, event: .init(name: "duration", format: MPV_FORMAT_DOUBLE))
event?.subscribe(self, event: .init(name: "time-pos", format: MPV_FORMAT_DOUBLE))
@@ -158,7 +159,7 @@ class TouchBar: NSTouchBar, NSTouchBarDelegate, EventSubscriber {
item.view = config.handler(config)
item.customizationLabel = config.name
configs[identifier]?.item = item
- item.addObserver(self, forKeyPath: "visible", options: [.new], context: nil)
+ observers += [item.observe(\.isVisible, options: [.new]) { object, change in self.changed(visibility: change.newValue) }]
return item
}
@@ -179,14 +180,8 @@ class TouchBar: NSTouchBar, NSTouchBarDelegate, EventSubscriber {
return slider
}
- override func observeValue(
- forKeyPath keyPath: String?,
- of object: Any?,
- change: [NSKeyValueChangeKey:Any]?,
- context: UnsafeMutableRawPointer?
- ) {
- guard let visible = change?[.newKey] as? Bool else { return }
- if keyPath == "isVisible" && visible {
+ func changed(visibility: Bool?) {
+ if let visible = visibility, visible {
updateTouchBarTimeItems()
updatePlayButton()
}