Skip to content

Commit

Permalink
Increment CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
actuallymentor committed Mar 13, 2023
1 parent 0abd636 commit eabf3a9
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 17 deletions.
19 changes: 19 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"i18n-ally.localesPaths": [
"public/locales"
],
"i18n-ally.keystyle": "nested",
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact"
],
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"editor.renderWhitespace": "all",
"editor.formatOnSave": true,
"eslint.format.enable": true,
"eslint.run": "onType"
}
26 changes: 21 additions & 5 deletions app/modules/interface.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const { shell, app, Tray, Menu, powerMonitor, nativeTheme } = require( 'electron' )
const { enable_battery_limiter, disable_battery_limiter, initialize_battery, is_limiter_enabled, get_battery_status, uninstall_battery } = require( './battery' )
const { log, wait, confirm } = require( "./helpers" )
const { log } = require( "./helpers" )
const { get_logo_template } = require( './theme' )
const { get_force_discharge_setting, toggle_force_discharge, update_force_discharge_setting } = require( './settings' )
const { get_force_discharge_setting, update_force_discharge_setting } = require( './settings' )

/* ///////////////////////////////
// Menu helpers
Expand Down Expand Up @@ -57,7 +57,10 @@ const generate_app_menu = async () => {
label: `Allow force-discharging`,
type: 'checkbox',
checked: allow_discharge,
click: update_force_discharge_setting
click: async () => {
const success = await update_force_discharge_setting()
if( limiter_on && success ) await restart_limiter()
}
},
{
type: 'separator'
Expand Down Expand Up @@ -235,8 +238,21 @@ async function disable_limiter() {

}

async function restart_limiter() {

try {
log( 'Restart limiter' )
const percent_left = await disable_battery_limiter()
await enable_battery_limiter()
await refresh_logo( percent_left, 'active' )
await refresh_tray()
} catch ( e ) {
log( `Error in restart_limiter: `, e )
}

}


module.exports = {
set_initial_interface,
refresh_tray
set_initial_interface
}
14 changes: 3 additions & 11 deletions app/modules/settings.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const Store = require( 'electron-store' )
const { is_limiter_enabled, disable_battery_limiter, enable_battery_limiter } = require( './battery' )
const { log } = require( './helpers' )
const { refresh_tray } = require( './interface' )
const { log, confirm } = require( './helpers' )
const store = new Store( {
force_discharge_if_needed: {
type: 'boolean'
Expand Down Expand Up @@ -29,19 +27,13 @@ const update_force_discharge_setting = async () => {
const currently_allowed = get_force_discharge_setting()
if( !currently_allowed ) {
const proceed = await confirm( `This setting allows your battery to drain to the desired maintenance level while plugged in. This does not work well in Clamshell mode (laptop closed with an external monitor).\n\nAllow force-discharging?` )
if( !proceed ) return
if( !proceed ) return false
}

// Toggle setting and refresh tray
toggle_force_discharge()
await refresh_tray()
return true

// Restart battery if needed
const limiter_on = await is_limiter_enabled()
if( limiter_on ) {
await disable_battery_limiter()
await enable_battery_limiter()
}

} catch ( e ) {
log( `Error updating force discharge: `, e )
Expand Down
2 changes: 1 addition & 1 deletion battery.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
## Update management
## variables are used by this binary as well at the update script
## ###############
BATTERY_CLI_VERSION="v1.0.8"
BATTERY_CLI_VERSION="v1.0.9"

# Path fixes for unexpected environments
PATH=/bin:/usr/bin:/usr/local/bin:/usr/sbin:/opt/homebrew
Expand Down

0 comments on commit eabf3a9

Please sign in to comment.