Merge pull request #413 from base47/fix-issues-377and410

Fix battery update on UI app startup (#377) and disabled charging (410)
This commit is contained in:
Mentor Palokaj
2025-11-20 16:28:30 +01:00
committed by GitHub
3 changed files with 21 additions and 14 deletions

View File

@@ -139,10 +139,10 @@ const initialize_battery = async () => {
'-k CH0C -r',
'-k CH0I -r',
'-k ACLC -r',
'-k ACLC -w 02',
// Update for Sanoma 26.x
// Apple introduced the following two in 2025.
// It seems to apply to all Apple Silicon MacBooks, regardless of macOS version.
'-k CHTE -r',
'-k CH0J -w 01'
'-k CHIE -r'
]
const [
battery_installed,
@@ -150,21 +150,23 @@ const initialize_battery = async () => {
charging_in_visudo,
discharging_in_visudo,
magsafe_led_in_visudo,
additional_magsafe_led_in_visudo
chte_charging_in_visudo,
chie_discharging_in_visudo,
] = await Promise.all( [
exec_async( `${ path_fix } which battery` ).catch( low_err_return_false ),
exec_async( `${ path_fix } which smc` ).catch( low_err_return_false ),
...smc_commands.map( cmd => exec_async( `${ path_fix } sudo -n /usr/local/bin/smc ${ cmd }` ).catch( low_err_return_false ) )
] )
const visudo_complete = ![ charging_in_visudo, discharging_in_visudo, magsafe_led_in_visudo, additional_magsafe_led_in_visudo ].some( entry => entry === false )
const visudo_complete = ![ charging_in_visudo, discharging_in_visudo, magsafe_led_in_visudo, chte_charging_in_visudo, chie_discharging_in_visudo ].some( entry => entry === false )
const is_installed = battery_installed && smc_installed
log( 'Is installed? ', is_installed )
log( 'Visudo complete? ', {
charging_in_visudo,
discharging_in_visudo,
magsafe_led_in_visudo,
additional_magsafe_led_in_visudo,
chte_charging_in_visudo,
chie_discharging_in_visudo,
visudo_complete
} )

View File

@@ -509,6 +509,14 @@ if [[ "$action" == "update" ]]; then
read
fi
curl -sS https://raw.githubusercontent.com/actuallymentor/battery/main/update.sh | bash
if [[ ! "$setting" == "silent" ]]; then
# The setting "silent" is always passed when `battery update` is invoked from the UI app,
# which decides whether to invoke `battery visudo` as well. But for Terminal-only users
# there is no UI app. So it's either we invoke `battery visudo` here, or assume that users
# remember to do it themselves, which did not work in the past.
echo "Runnig $battery_binary visudo"
$battery_binary visudo
fi
fi
exit 0
fi
@@ -667,9 +675,9 @@ if [[ "$action" == "maintain_synchronous" ]]; then
fi
# Parse setting - could be single value or range
local lower_bound=""
local upper_bound=""
local is_range=false
lower_bound=""
upper_bound=""
is_range=false
if valid_percentage_range "$setting"; then
# Range format: lower-upper
@@ -689,7 +697,7 @@ if [[ "$action" == "maintain_synchronous" ]]; then
# Check if the user requested that the battery maintenance first discharge to the desired level
if [[ "$subsetting" == "--force-discharge" ]]; then
# Before we start maintaining the battery level, first discharge to the target level
local discharge_target="$lower_bound"
discharge_target="$lower_bound"
log "Triggering discharge to $discharge_target before enabling charging limiter"
$battery_binary discharge "$discharge_target"
log "Discharge pre battery-maintenance complete, continuing to battery maintenance loop"

View File

@@ -24,12 +24,9 @@ chown $USER $binfolder/battery
chmod 755 $binfolder/battery
chmod u+x $binfolder/battery
echo "[ 3 ] Updating visudo declarations"
$binfolder/battery visudo
# Remove tempfiles
cd
rm -rf $tempfolder
echo "[ 4 ] Removed temporary folder"
echo "[ 3 ] Removed temporary folder"
echo -e "\n🎉 Battery tool updated.\n"