Skip to content

Commit

Permalink
version 1.2 and fix capacity on M1
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryQuan committed Mar 10, 2022
1 parent 661b11a commit 5086d32
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
15 changes: 15 additions & 0 deletions Battery/Core/Battery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Battery {
/// Returns a string like 2:12 remaning
func getTimeRemaining() -> String {
var remain = Constant.Estimate
var batteryPercentage = ""
// pmset -g batt
let output = Utils.runCommand(cmd: "/usr/bin/pmset", args: "-g", "batt").output

Expand All @@ -25,6 +26,11 @@ class Battery {
if matches.count > 0 {
remain = matches[0]
}

let percentMatches = Utils.matches(for: "[0-9]+%", in: output[1])
if percentMatches.count > 0 {
batteryPercentage = percentMatches[0]
}
}

// Add different emoji to distinguish different mode
Expand All @@ -34,6 +40,9 @@ class Battery {
remain += "⚡️"
}

// Add the percentage
remain += batteryPercentage

return remain
}

Expand All @@ -57,6 +66,12 @@ class Battery {
let curr = IORegString(output: m)
switch curr.description {
case "MaxCapacity":
let capacity = curr.convertValue() as! Int
if (capacity > 1000) {
#warning("This is 100 on M1")
max = capacity
}
case "AppleRawMaxCapacity":
max = curr.convertValue() as! Int
case "CycleCount":
cycle = curr.convertValue() as! Int
Expand Down
8 changes: 4 additions & 4 deletions BatteryBar.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,15 @@
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 6;
CURRENT_PROJECT_VERSION = 7;
DEVELOPMENT_TEAM = 4YSG3SYMLE;
INFOPLIST_FILE = Battery/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.12;
MARKETING_VERSION = 1.1;
MARKETING_VERSION = 1.2;
PRODUCT_BUNDLE_IDENTIFIER = com.yihengquan.batterybar;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand All @@ -318,15 +318,15 @@
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 6;
CURRENT_PROJECT_VERSION = 7;
DEVELOPMENT_TEAM = 4YSG3SYMLE;
INFOPLIST_FILE = Battery/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.12;
MARKETING_VERSION = 1.1;
MARKETING_VERSION = 1.2;
PRODUCT_BUNDLE_IDENTIFIER = com.yihengquan.batterybar;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand Down

0 comments on commit 5086d32

Please sign in to comment.