mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
- fix crash when GPU module is enabled (#74)
This commit is contained in:
@@ -35,7 +35,7 @@ public struct GPUs: value_t {
|
||||
|
||||
public var widget_value: Double {
|
||||
get {
|
||||
return list[0].utilization
|
||||
return list.isEmpty ? 0 : list[0].utilization
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -87,7 +87,7 @@ public class GPU: Module {
|
||||
}
|
||||
|
||||
private func infoCallback(_ value: GPUs?) {
|
||||
guard value != nil else {
|
||||
guard value != nil && !value!.list.isEmpty else {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -39,8 +39,8 @@ internal class InfoReader: Reader<GPUs> {
|
||||
return false
|
||||
}
|
||||
|
||||
let pciMatch = "0x" + Data([deviceID[1], deviceID[0], vendorID[1], vendorID[0]]).map { String(format: "%02hhX", $0) }.joined()
|
||||
let accMatch = accelerator["IOPCIMatch"] as? String ?? accelerator["IOPCIPrimaryMatch"] as? String ?? ""
|
||||
let pciMatch = "0x" + Data([deviceID[1], deviceID[0], vendorID[1], vendorID[0]]).map { String(format: "%02hhX", $0) }.joined().lowercased()
|
||||
let accMatch = (accelerator["IOPCIMatch"] as? String ?? accelerator["IOPCIPrimaryMatch"] as? String ?? "").lowercased()
|
||||
|
||||
return accMatch.range(of: pciMatch) != nil
|
||||
}) else { return }
|
||||
@@ -53,10 +53,10 @@ internal class InfoReader: Reader<GPUs> {
|
||||
return
|
||||
}
|
||||
|
||||
guard let model = matchedGPU.object(forKey: "model") as? Data else {
|
||||
guard let model = matchedGPU.object(forKey: "model") as? Data, var modelName = String(data: model, encoding: .ascii) else {
|
||||
return
|
||||
}
|
||||
let modelName = String(data: model, encoding: .ascii)!.replacingOccurrences(of: "\0", with: "")
|
||||
modelName = modelName.replacingOccurrences(of: "\0", with: "")
|
||||
|
||||
guard let IOClass = accelerator.object(forKey: "IOClass") as? String else {
|
||||
return
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>$(MARKETING_VERSION)</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>39</string>
|
||||
<string>44</string>
|
||||
<key>Description</key>
|
||||
<string>Simple macOS system monitor in your menu bar</string>
|
||||
<key>LSApplicationCategoryType</key>
|
||||
|
||||
@@ -938,3 +938,17 @@ public class ColorView: NSView {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public struct Log: TextOutputStream {
|
||||
public func write(_ string: String) {
|
||||
let fm = FileManager.default
|
||||
let log = fm.urls(for: .documentDirectory, in: .userDomainMask)[0].appendingPathComponent("log.txt")
|
||||
if let handle = try? FileHandle(forWritingTo: log) {
|
||||
handle.seekToEndOfFile()
|
||||
handle.write(string.data(using: .utf8)!)
|
||||
handle.closeFile()
|
||||
} else {
|
||||
try? string.data(using: .utf8)?.write(to: log)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user