Skip to content

Commit

Permalink
fixed crashing on mac mini
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryQuan committed Dec 14, 2021
1 parent 2ee0d58 commit 661b11a
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions Battery/Core/Battery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ class Battery {
let output = Utils.runCommand(cmd: "/usr/bin/pmset", args: "-g", "batt").output

// Find string with format 1:23
let matches = Utils.matches(for: "[0-9]+:[0-9]+", in: output[1])
if matches.count > 0 {
remain = matches[0]
if output.count > 1 {
let matches = Utils.matches(for: "[0-9]+:[0-9]+", in: output[1])
if matches.count > 0 {
remain = matches[0]
}
}

// Add different emoji to distinguish different mode
if output.joined().contains("discharg") {
remain += "🔋"
Expand Down Expand Up @@ -71,8 +73,10 @@ class Battery {
finalResult += "Cycle count: \(cycle)/1000\n"
let percentage = max * 100 / design
finalResult += "Battery health: \(max)/\(design) (\(percentage)%)\n"
finalResult += "Uptime: \(self.getUpTime())\n"
} else {
finalResult += "No battery information\n"
}
finalResult += "Uptime: \(self.getUpTime())\n"
return finalResult
}

Expand Down

0 comments on commit 661b11a

Please sign in to comment.