fix: fixed crashes on some M2 macs caused by frequency reader (#2317)

This commit is contained in:
Serhiy Mytrovtsiy
2025-01-13 18:57:09 +01:00
parent fcbdb666a2
commit 962bf749fa
3 changed files with 7 additions and 5 deletions

View File

@@ -355,13 +355,15 @@ public class FrequencyReader: Reader<[Double]> {
private func calculateFrequencies(dict: CFDictionary, freqs: [Int32]) -> Double {
let items = self.getResidencies(dict: dict)
let offset = items.firstIndex { $0.0 != "IDLE" && $0.0 != "DOWN" && $0.0 != "OFF" }!
guard let offset = items.firstIndex(where: { $0.0 != "IDLE" && $0.0 != "DOWN" && $0.0 != "OFF" }) else { return 0 }
let usage = items.dropFirst(offset).reduce(0.0) { $0 + Double($1.f) }
let count = freqs.count
var avgFreq: Double = 0
for i in 0..<count {
let percent = usage == 0 ? 0 : Double(items[i + offset].f) / usage
let key = i + offset
if !items.indices.contains(key) { continue }
let percent = usage == 0 ? 0 : Double(items[key].f) / usage
avgFreq += percent * Double(freqs[i])
}

View File

@@ -17,7 +17,7 @@
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>657</string>
<string>659</string>
<key>Description</key>
<string>Simple macOS system monitor in your menu bar</string>
<key>LSApplicationCategoryType</key>

View File

@@ -13,7 +13,7 @@
<key>CFBundleShortVersionString</key>
<string>2.11.24</string>
<key>CFBundleVersion</key>
<string>657</string>
<string>659</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>