1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-02-21 05:29:13 +00:00

Take advantage of persistence flag for more intelligent LED presentation.

This commit is contained in:
Thomas Harte 2021-07-15 21:49:11 -04:00
parent ea63415d0e
commit d35c7ad127

View File

@ -632,11 +632,13 @@ class MachineDocument:
private class LED { private class LED {
let levelIndicator: NSLevelIndicator let levelIndicator: NSLevelIndicator
init(levelIndicator: NSLevelIndicator) { init(levelIndicator: NSLevelIndicator, isPersistent: Bool) {
self.levelIndicator = levelIndicator self.levelIndicator = levelIndicator
self.isPersistent = isPersistent
} }
var isLit = false var isLit = false
var isBlinking = false var isBlinking = false
var isPersistent = false
} }
private var leds: [String: LED] = [:] private var leds: [String: LED] = [:]
private var activityFader: ViewFader! = nil private var activityFader: ViewFader! = nil
@ -675,7 +677,7 @@ class MachineDocument:
// Apply labels and create leds entries. // Apply labels and create leds entries.
for c in 0 ..< leds.count { for c in 0 ..< leds.count {
textFields[c].stringValue = leds[c].name textFields[c].stringValue = leds[c].name
self.leds[leds[c].name] = LED(levelIndicator: activityIndicators[c]) self.leds[leds[c].name] = LED(levelIndicator: activityIndicators[c], isPersistent: leds[c].isPersisent)
} }
// Create a fader. // Create a fader.
@ -719,10 +721,6 @@ class MachineDocument:
led.levelIndicator.floatValue = led.isLit ? 1.0 : 0.0 led.levelIndicator.floatValue = led.isLit ? 1.0 : 0.0
led.isBlinking = false led.isBlinking = false
} }
// Treat a new blink as potentially re-showing the activity
// indicators, given windowed-mode behaviour.
self.updateActivityViewVisibility()
} }
} }
} }
@ -741,32 +739,35 @@ class MachineDocument:
led.isLit = isLit led.isLit = isLit
// Possibly show or hide the activity subview. // Possibly show or hide the activity subview.
self.updateActivityViewVisibility() self.updateActivityViewVisibility(false, changed: ledName)
} }
} }
} }
private func updateActivityViewVisibility(_ isAppLaunch : Bool = false) { private func updateActivityViewVisibility(_ isAppLaunch : Bool = false, changed: String? = nil) {
if let window = self.windowControllers.first?.window, let activityFader = self.activityFader { if let window = self.windowControllers.first?.window, let activityFader = self.activityFader {
// If in a window, show the activity view transiently to // Rules applied below:
// acknowledge changes of state. In full screen show it //
// permanently as long as at least one LED is lit. // Fullscreen:
if window.styleMask.contains(.fullScreen) { // (i) always show activity view if any persistent LEDs are present;
let litLEDs = self.leds.filter { $0.value.isLit } // (ii) otherwise, show activity view only while at least one LED is lit.
if litLEDs.isEmpty{ //
activityFader.animateOut(delay: 0.2) // Windowed:
} else { // (i) show while any non-persistent LED is lit;
activityFader.animateIn() // (ii) show transiently to indicate a change of state in any persistent LED.
} //
} else if !isAppLaunch { let hasLitLEDs = !self.leds.filter {
activityFader.showTransiently(for: 1.0) $0.value.isLit && (!$0.value.isPersistent || window.styleMask.contains(.fullScreen)) ||
} ($0.value.isPersistent && window.styleMask.contains(.fullScreen))
}.isEmpty
let shouldShowTransient = !window.styleMask.contains(.fullScreen) && changed != nil && self.leds[changed!]!.isPersistent
let litLEDs = self.leds.filter { $0.value.isLit } if hasLitLEDs {
if litLEDs.isEmpty || !window.styleMask.contains(.fullScreen) {
activityFader.animateOut(delay: window.styleMask.contains(.fullScreen) ? 0.2 : 0.0)
} else {
activityFader.animateIn() activityFader.animateIn()
} else if shouldShowTransient {
activityFader.showTransiently(for: 1.0)
} else {
activityFader.animateOut(delay: 0.2)
} }
} }
} }