diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..74a78db Binary files /dev/null and b/.DS_Store differ diff --git a/.vscode/settings.json b/.vscode/settings.json index eccda49..febebe8 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,17 +1,19 @@ { - "i18n-ally.localesPaths": ["public/locales"], - "i18n-ally.keystyle": "nested", - "eslint.validate": [ - "javascript", - "javascriptreact", - "typescript", - "typescriptreact" - ], - "editor.codeActionsOnSave": { - "source.fixAll.eslint": "explicit" - }, - "editor.renderWhitespace": "all", - "editor.formatOnSave": true, - "eslint.format.enable": true, - "eslint.run": "onType" -} + "i18n-ally.localesPaths": [ + "public/locales" + ], + "i18n-ally.keystyle": "nested", + "eslint.validate": [ + "javascript", + "javascriptreact", + "typescript", + "typescriptreact" + ], + "editor.codeActionsOnSave": { + "source.fixAll.eslint": "explicit" + }, + "editor.renderWhitespace": "all", + "editor.formatOnSave": true, + "eslint.format.enable": true, + "eslint.run": "onType" +} \ No newline at end of file diff --git a/app/.DS_Store b/app/.DS_Store new file mode 100644 index 0000000..563238f Binary files /dev/null and b/app/.DS_Store differ diff --git a/battery.sh b/battery.sh index be07e23..3d0fd50 100755 --- a/battery.sh +++ b/battery.sh @@ -4,7 +4,7 @@ ## Update management ## variables are used by this binary as well at the update script ## ############### -BATTERY_CLI_VERSION="v1.1.6" +BATTERY_CLI_VERSION="v1.1.5" # Path fixes for unexpected environments PATH=/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin @@ -21,6 +21,7 @@ logfile=$configfolder/battery.log maintain_percentage_tracker_file=$configfolder/maintain.percentage maintain_voltage_tracker_file=$configfolder/maintain.voltage daemon_path=$HOME/Library/LaunchAgents/battery.plist +calibrate_pidfile=$configfolder/calibrate.pid # Voltage limits voltage_min="10.5" @@ -78,6 +79,9 @@ Usage: manually set the adapter to (not) charge even when plugged in eg: battery adapter off + battery calibrate + calibrate the battery by discharging it to 15%, then recharging it to 100%, and keeping it there for 1 hour + battery charge LEVEL[1-100] charge the battery to a certain percentage, and disable charging when that percentage is reached eg: battery charge 90 @@ -385,9 +389,9 @@ if [[ "$action" == "adapter" ]]; then # Set charging to on and off if [[ "$setting" == "on" ]]; then - disable_discharging - elif [[ "$setting" == "off" ]]; then enable_discharging + elif [[ "$setting" == "off" ]]; then + disable_discharging fi exit 0 @@ -454,6 +458,13 @@ fi # Maintain at level if [[ "$action" == "maintain_synchronous" ]]; then + + # Checking if the calibration process is running + if test -f "$calibrate_pidfile"; then + pid=$(cat "$calibrate_pidfile" 2>/dev/null) + kill $calibrate_pidfile &>/dev/null + log "🚨 Calibration process have been stopped" + fi # Recover old maintain status if old setting is found if [[ "$setting" == "recover" ]]; then @@ -576,6 +587,12 @@ if [[ "$action" == "maintain" ]]; then kill $pid &>/dev/null fi + if test -f "$calibrate_pidfile"; then + pid=$(cat "$calibrate_pidfile" 2>/dev/null) + kill $calibrate_pidfile &>/dev/null + log "🚨 Calibration process have been stopped" + fi + if [[ "$setting" == "stop" ]]; then log "Killing running maintain daemons & enabling charging as default state" rm $pidfile 2>/dev/null @@ -656,6 +673,64 @@ if [[ "$action" == "maintain" ]]; then fi +# Battery calibration +if [[ "$action" == "calibrate_synchronous" ]]; then + log "Starting calibration" + + # Stop the maintaining + battery maintain stop + + # Discharge battery to 15% + battery discharge 15 + + while true; do + log "checking if at 100%" + # Check if battery level has reached 100% + if battery status | head -n 1 | grep -q "Battery at 100%"; then + break + else + sleep 300 + continue + fi + done + + # Wait before discharging to target level + log "reached 100%, maintaining for 1 hour" + sleep 3600 + + # Discharge battery to 80% + battery discharge 80 + + # Recover old maintain status + battery maintain recover + exit 0 +fi + +# Asynchronous battery level maintenance +if [[ "$action" == "calibrate" ]]; then + # Kill old process silently + if test -f "$calibrate_pidfile"; then + pid=$(cat "$calibrate_pidfile" 2>/dev/null) + kill $pid &>/dev/null + fi + + if [[ "$setting" == "stop" ]]; then + log "Killing running calibration daemon" + kill $calibrate_pidfile &>/dev/null + rm $calibrate_pidfile 2>/dev/null + + exit 0 + fi + + # Start calibration script + log "Starting calibration script" + nohup battery calibrate_synchronous >>$logfile & + + # Store pid of calibration process and setting + echo $! >$calibrate_pidfile + pid=$(cat "$calibrate_pidfile" 2>/dev/null) +fi + # Status logger if [[ "$action" == "status" ]]; then @@ -779,4 +854,4 @@ if [[ "$action" == "logs" ]]; then exit 0 -fi +fi \ No newline at end of file