From 08a5b0260b199a21b64a2479d01849178cd9c55d Mon Sep 17 00:00:00 2001 From: Serhiy Mytrovtsiy Date: Sun, 1 Mar 2026 18:11:23 +0100 Subject: [PATCH] fix: cherry-pick changes from #2983 to fix the automatic fan mode after sleep --- Modules/Sensors/main.swift | 2 +- Modules/Sensors/popup.swift | 16 ++++++++-------- Modules/Sensors/readers.swift | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Modules/Sensors/main.swift b/Modules/Sensors/main.swift index 068d3efb..02701c47 100644 --- a/Modules/Sensors/main.swift +++ b/Modules/Sensors/main.swift @@ -92,7 +92,7 @@ public class Sensors: Module { reader.list.sensors.filter({ $0 is Fan }).forEach { (s: Sensor_p) in if let f = s as? Fan, let mode = f.customMode { - if mode != .automatic { + if !mode.isAutomatic { SMCHelper.shared.setFanMode(f.id, mode: FanMode.automatic.rawValue) } } diff --git a/Modules/Sensors/popup.swift b/Modules/Sensors/popup.swift index 63a24730..77710020 100644 --- a/Modules/Sensors/popup.swift +++ b/Modules/Sensors/popup.swift @@ -84,7 +84,7 @@ internal class Popup: PopupWrapper { @objc private func checkFanModesAndResetFtst() { let fanViews = self.list.values.compactMap { $0 as? FanView } guard !fanViews.isEmpty else { return } - guard fanViews.allSatisfy({ $0.fan.mode == .automatic }) else { return } + guard fanViews.allSatisfy({ $0.fan.mode.isAutomatic }) else { return } SMCHelper.shared.resetFanControl() } #endif @@ -855,7 +855,7 @@ internal class FanView: NSStackView { DispatchQueue.main.asyncAfter(deadline: .now() + 3) { SMCHelper.shared.setFanMode(self.fan.id, mode: mode.rawValue) self.modeButtons?.setMode(mode) - if mode != .automatic { + if !mode.isAutomatic { self.setSpeed(value: speed, then: { DispatchQueue.main.async { self.sliderValueField?.textColor = .systemBlue @@ -868,7 +868,7 @@ internal class FanView: NSStackView { self.willSleepSpeed = nil } - if let value = self.fan.customSpeed, self.fan.mode != .automatic { + if let value = self.fan.customSpeed, !self.fan.mode.isAutomatic { self.setSpeed(value: value, then: { DispatchQueue.main.async { self.sliderValueField?.textColor = .systemBlue @@ -878,9 +878,9 @@ internal class FanView: NSStackView { } @objc private func sleepListener(aNotification: NSNotification) { - guard SMCHelper.shared.isActive() && self.fan.customMode != .automatic else { return } + guard SMCHelper.shared.isActive(), let mode = self.fan.customMode, !mode.isAutomatic else { return } - self.willSleepMode = self.fan.customMode + self.willSleepMode = mode self.willSleepSpeed = self.fan.customSpeed SMCHelper.shared.setFanMode(fan.id, mode: FanMode.automatic.rawValue) self.modeButtons?.setMode(.automatic) @@ -925,7 +925,7 @@ internal class FanView: NSStackView { v.setFrameSize(NSSize(width: width, height: v.frame.height)) } - if self.resetModeAfterSleep && value.mode != .automatic { + if self.resetModeAfterSleep && !value.mode.isAutomatic { if self.sliderValueField?.stringValue != "" && self.slider?.doubleValue != value.value { self.slider?.doubleValue = value.value self.sliderValueField?.stringValue = "" @@ -1031,7 +1031,7 @@ private class ModeButtons: NSStackView { self.autoBtn.setButtonType(.toggle) self.autoBtn.isBordered = false self.autoBtn.target = self - self.autoBtn.state = mode == .automatic ? .on : .off + self.autoBtn.state = mode.isAutomatic ? .on : .off self.manualBtn.setButtonType(.toggle) self.manualBtn.isBordered = false @@ -1180,7 +1180,7 @@ private class ModeButtons: NSStackView { } public func setMode(_ mode: FanMode) { - if mode == .automatic { + if mode.isAutomatic { self.autoBtn.state = .on self.manualBtn.state = .off self.offBtn.state = .off diff --git a/Modules/Sensors/readers.swift b/Modules/Sensors/readers.swift index 2495a8a2..e05b8c2b 100644 --- a/Modules/Sensors/readers.swift +++ b/Modules/Sensors/readers.swift @@ -331,8 +331,8 @@ extension SensorsReader { } } - if let md = SMC.shared.getValue("F\(i)Md") { - mode = FanMode(rawValue: Int(md)) ?? .automatic + if let md = SMC.shared.getValue("F\(i)Md"), let parsed = FanMode(rawValue: Int(md)) { + mode = parsed.isAutomatic ? .automatic : parsed } else { mode = self.getFanMode(i) }