History

mac/touchbar: simplify update items logic

der richter committed 2 years ago

Commit be49f4f1 parent 647bf5d1 file · +8 −27Browse files

Unified · Split

osdep/mac/touch_bar.swift+8−27
@@ -208,14 +208,9 @@ class TouchBar: NSTouchBar, NSTouchBarDelegate { · 207 unmodified lines
208208 guard let config = configs[.seekBar], let slider = config.view as? NSSlider else { return }
209209 if !(config.item?.isVisible ?? false) { return }
210210
211− if duration <= 0 {
212− slider.isEnabled = false
213− slider.doubleValue = 0
214− } else {
215− slider.isEnabled = true
216− if (!slider.isHighlighted) {
217− slider.doubleValue = (position / duration) * 100
218− }
211+ slider.isEnabled = duration > 0
212+ if !slider.isHighlighted {
213+ slider.doubleValue = slider.isEnabled ? (position / duration) * 100 : 0
219214 }
220215 }
221216
@@ -224,14 +219,9 @@ class TouchBar: NSTouchBar, NSTouchBarDelegate { · 2 unmodified lines
224219 if !(config.item?.isVisible ?? false) { return }
225220
226221 removeConstraintFor(identifier: .timeLeft)
227− if duration <= 0 {
228− text.stringValue = ""
229− } else {
230− let left = Int(floor(duration) - floor(position))
231− let leftFormat = format(time: left)
232− let durationFormat = format(time: Int(duration))
233− text.stringValue = "-\(leftFormat)"
234− applyConstraintFrom(string: "-\(durationFormat)", identifier: .timeLeft)
222+ text.stringValue = duration > 0 ? "-" + format(time: Int(floor(duration) - floor(position))) : ""
223+ if !text.stringValue.isEmpty {
224+ applyConstraintFrom(string: "-" + format(time: Int(duration)), identifier: .timeLeft)
235225 }
236226 }
237227
@@ -241,22 +231,13 @@ class TouchBar: NSTouchBar, NSTouchBarDelegate { · 3 unmodified lines
241231
242232 text.stringValue = format(time: Int(floor(position)))
243233 removeConstraintFor(identifier: .currentPosition)
244− if duration <= 0 {
245− applyConstraintFrom(string: format(time: Int(position)), identifier: .currentPosition)
246− } else {
247− applyConstraintFrom(string: format(time: Int(duration)), identifier: .currentPosition)
248− }
234+ applyConstraintFrom(string: format(time: Int(duration > 0 ? duration : position)), identifier: .currentPosition)
249235 }
250236
251237 func updatePlayButton() {
252238 guard let config = configs[.play], let button = config.view as? NSButton else { return }
253239 if !isVisible || !(config.item?.isVisible ?? false) { return }
254−
255− if isPaused {
256− button.image = configs[.play]?.imageAlt
257− } else {
258− button.image = configs[.play]?.image
259− }
240+ button.image = isPaused ? configs[.play]?.imageAlt : configs[.play]?.image
260241 }
261242
262243 @objc func buttonAction(_ button: NSButton) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t