diff --git a/autoload/battery.vim b/autoload/battery.vim index 4f99ed1..9d0cc88 100644 --- a/autoload/battery.vim +++ b/autoload/battery.vim @@ -93,10 +93,10 @@ function! s:get_available_backend() abort return 'powershell' elseif battery#backend#linux#is_available() return 'linux' - elseif battery#backend#freebsd#is_available() - return 'freebsd' elseif battery#backend#termux#is_available() return 'termux' + elseif battery#backend#freebsd#is_available() + return 'freebsd' endif return 'dummy' endfunction diff --git a/autoload/battery/backend/termux.vim b/autoload/battery/backend/termux.vim index cbd157f..fed6511 100644 --- a/autoload/battery/backend/termux.vim +++ b/autoload/battery/backend/termux.vim @@ -18,9 +18,10 @@ function! s:on_stdout(buffer, data) abort endfunction function! s:on_exit(backend, buffer, exitval) abort - let content = join(a:buffer, '') - let a:backend.is_charging = json_decode(content).status !=# 'NOT_CHARGING' - let a:backend.value = json_decode(content).percentage + 0 + let obj = json_decode(join(a:buffer, '')) + let status = get(obj, 'status', '') + let a:backend.is_charging = !(status ==# 'NOT_CHARGING' || status ==# 'DISCHARGING') + let a:backend.value = get(obj, 'percentage', 0) + 0 endfunction function! battery#backend#termux#define() abort