Skip to content

Commit 84b7f9e

Browse files
feat: Node.js TUI dashboard with real-time monitoring
1 parent e3910b8 commit 84b7f9e

1 file changed

Lines changed: 80 additions & 0 deletions

File tree

dashboard.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/usr/bin/env node
2+
/**
3+
* dashboard.js - Android ADB TUI Dashboard
4+
* Real-time monitoring: battery, CPU, memory, temperature
5+
* Usage: npm install && node dashboard.js
6+
*/
7+
import blessed from 'blessed';
8+
import { execSync } from 'child_process';
9+
import chalk from 'chalk';
10+
11+
const screen = blessed.screen({
12+
mouse: true,
13+
title: 'Android ADB Dashboard',
14+
});
15+
16+
const mainBox = blessed.box({
17+
parent: screen,
18+
top: 0,
19+
left: 0,
20+
width: '100%',
21+
height: '100%',
22+
content: '',
23+
style: { bg: 'black', fg: 'white' },
24+
});
25+
26+
const logBox = blessed.box({
27+
parent: screen,
28+
top: 15,
29+
left: 0,
30+
width: '100%',
31+
height: '100%-15',
32+
scrollable: true,
33+
mouse: true,
34+
keys: true,
35+
style: { bg: 'black', fg: 'green' },
36+
});
37+
38+
function adb(cmd) {
39+
try {
40+
return execSync(`adb shell ${cmd}`, { encoding: 'utf-8' }).trim();
41+
} catch(e) {
42+
return 'ERROR';
43+
}
44+
}
45+
46+
function formatBytes(b) {
47+
if (b < 1024) return b + 'B';
48+
if (b < 1024*1024) return (b/1024).toFixed(1) + 'KB';
49+
return (b/1024/1024).toFixed(1) + 'MB';
50+
}
51+
52+
function update() {
53+
try {
54+
const battery = adb("dumpsys battery | grep level | head -1").match(/\d+/)[0];
55+
const temp = adb("dumpsys battery | grep temperature | head -1").match(/\d+/)[0];
56+
const ram = adb("cat /proc/meminfo | grep MemAvailable").match(/\d+/)[0];
57+
const cpu = adb("top -n 1 | head -3 | tail -1");
58+
const model = adb("getprop ro.product.model");
59+
60+
let header = `\n🤖 Android Dashboard - ${model}\n`;
61+
header += `${'═'.repeat(50)}\n`;
62+
header += `Battery: ${battery}% | Temp: ${temp}°C | RAM: ${formatBytes(ram*1024)}\n`;
63+
header += `CPU: ${cpu.substring(0, 60)}\n`;
64+
header += `${'─'.repeat(50)}\n`;
65+
66+
mainBox.setContent(header);
67+
logBox.log(chalk.green(`[${new Date().toLocaleTimeString()}] Updated`));
68+
69+
setTimeout(update, 3000);
70+
} catch(e) {
71+
logBox.log(chalk.red(`Error: ${e.message}`));
72+
setTimeout(update, 5000);
73+
}
74+
}
75+
76+
screen.key(['escape', 'q', 'C-c'], () => process.exit(0));
77+
logBox.log(chalk.cyan('ADB Dashboard started. Press Q to quit.\n'));
78+
79+
update();
80+
screen.render();

0 commit comments

Comments
 (0)