Skip to content

Commit 962bf74

Browse files
committed
fix: fixed crashes on some M2 macs caused by frequency reader (#2317)
1 parent fcbdb66 commit 962bf74

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

Modules/CPU/readers.swift

+5-3
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ internal class LoadReader: Reader<CPU_Load> {
7070
}
7171
self.CPUUsageLock.unlock()
7272

73-
let showHyperthratedCores = Store.shared.bool(key: "CPU_hyperhreading", defaultValue: false)
73+
let showHyperthratedCores = Store.shared.bool(key: "CPU_hyperhreading", defaultValue: false)
7474
if showHyperthratedCores || !self.hasHyperthreadingCores {
7575
self.response.usagePerCore = self.usagePerCore
7676
} else {
@@ -355,13 +355,15 @@ public class FrequencyReader: Reader<[Double]> {
355355

356356
private func calculateFrequencies(dict: CFDictionary, freqs: [Int32]) -> Double {
357357
let items = self.getResidencies(dict: dict)
358-
let offset = items.firstIndex { $0.0 != "IDLE" && $0.0 != "DOWN" && $0.0 != "OFF" }!
358+
guard let offset = items.firstIndex(where: { $0.0 != "IDLE" && $0.0 != "DOWN" && $0.0 != "OFF" }) else { return 0 }
359359
let usage = items.dropFirst(offset).reduce(0.0) { $0 + Double($1.f) }
360360
let count = freqs.count
361361
var avgFreq: Double = 0
362362

363363
for i in 0..<count {
364-
let percent = usage == 0 ? 0 : Double(items[i + offset].f) / usage
364+
let key = i + offset
365+
if !items.indices.contains(key) { continue }
366+
let percent = usage == 0 ? 0 : Double(items[key].f) / usage
365367
avgFreq += percent * Double(freqs[i])
366368
}
367369

Stats/Supporting Files/Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<key>CFBundleShortVersionString</key>
1818
<string>$(MARKETING_VERSION)</string>
1919
<key>CFBundleVersion</key>
20-
<string>657</string>
20+
<string>659</string>
2121
<key>Description</key>
2222
<string>Simple macOS system monitor in your menu bar</string>
2323
<key>LSApplicationCategoryType</key>

Widgets/Supporting Files/Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<key>CFBundleShortVersionString</key>
1414
<string>2.11.24</string>
1515
<key>CFBundleVersion</key>
16-
<string>657</string>
16+
<string>659</string>
1717
<key>NSExtension</key>
1818
<dict>
1919
<key>NSExtensionPointIdentifier</key>

0 commit comments

Comments
 (0)