Skip to content

Commit

Permalink
fix: Battery not displayed properly
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeRatcliffe committed Sep 15, 2024
1 parent 60e4e88 commit e1be629
Showing 1 changed file with 20 additions and 24 deletions.
44 changes: 20 additions & 24 deletions tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,26 @@ async function getBatteryInfo() {
return false;
}

return parceOutOptions(res);
const opts = {};
for (const line of res.replace(/ /g, "").split("\n")) {
const splitLine = line.split(":");
const key = splitLine[0];
let value = splitLine[1];

if (value === "true") {
value = true;
}
if (value === "false") {
value = false;
}
if (isFinite(+value)) {
value = +value;
}

opts[key] = value;
}

return opts;
}

async function getUserInfo() {
Expand Down Expand Up @@ -737,29 +756,6 @@ async function adbShell(cmd, deviceId = global.adbDevice, skipRead = false) {
}
}

function parceOutOptions(line) {
const opts = {};
for (let l of line.split("\n")) {
l = l.split(" ").join("");
const [k] = l.split(":");
let [v] = l.split(":");

if (v == "true") {
v = true;
}
if (v == "false") {
v = false;
}
if (!isNaN(+v)) {
v = +v;
}

opts[k] = v;
}

return opts;
}

// on empty dirrectory return false
async function adbFileExists(path) {
const r = await adbShell(`ls "${path}" 1>&1 2> /dev/null`);
Expand Down

0 comments on commit e1be629

Please sign in to comment.