refactor: extract shared runCommand utility and cleanup codebase
- Create shared command utility in ts/utils/command.ts - Update index.ts, process-manager.ts, system-info.ts to use shared utility - Remove duplicate runCommand implementations from all files - Remove legacy Chrome wrapper methods (startChrome, stopChrome, isChromeRunning) - Consolidate Sway window selectors from 5 to 2 - Remove unused isobuild TypeScript files (mod.ts, deno.json, ts/index.ts) - Make getStatus() async to properly await system info - Add disk and system info sections to UI
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
* Gathers CPU, RAM, disk, network, and GPU information
|
||||
*/
|
||||
|
||||
import { runCommand } from '../utils/command.ts';
|
||||
|
||||
export interface CpuInfo {
|
||||
model: string;
|
||||
cores: number;
|
||||
@@ -66,8 +68,9 @@ export class SystemInfo {
|
||||
|
||||
private async getHostname(): Promise<string> {
|
||||
try {
|
||||
const result = await this.runCommand('hostname');
|
||||
return result.trim();
|
||||
const result = await runCommand('hostname', []);
|
||||
if (!result.success) return 'unknown';
|
||||
return result.stdout.trim();
|
||||
} catch {
|
||||
return 'unknown';
|
||||
}
|
||||
@@ -120,8 +123,9 @@ export class SystemInfo {
|
||||
|
||||
private async getDiskInfo(): Promise<DiskInfo[]> {
|
||||
try {
|
||||
const output = await this.runCommand('df', ['-B1', '--output=source,target,size,used,avail']);
|
||||
const lines = output.trim().split('\n').slice(1);
|
||||
const result = await runCommand('df', ['-B1', '--output=source,target,size,used,avail']);
|
||||
if (!result.success) return [];
|
||||
const lines = result.stdout.trim().split('\n').slice(1);
|
||||
const disks: DiskInfo[] = [];
|
||||
|
||||
for (const line of lines) {
|
||||
@@ -150,8 +154,9 @@ export class SystemInfo {
|
||||
|
||||
private async getNetworkInfo(): Promise<NetworkInterface[]> {
|
||||
try {
|
||||
const output = await this.runCommand('ip', ['-j', 'addr']);
|
||||
const interfaces = JSON.parse(output);
|
||||
const cmdResult = await runCommand('ip', ['-j', 'addr']);
|
||||
if (!cmdResult.success) return [];
|
||||
const interfaces = JSON.parse(cmdResult.stdout);
|
||||
const result: NetworkInterface[] = [];
|
||||
|
||||
for (const iface of interfaces) {
|
||||
@@ -183,8 +188,9 @@ export class SystemInfo {
|
||||
|
||||
private async getGpuInfo(): Promise<GpuInfo[]> {
|
||||
try {
|
||||
const output = await this.runCommand('lspci', ['-mm']);
|
||||
const lines = output.split('\n');
|
||||
const result = await runCommand('lspci', ['-mm']);
|
||||
if (!result.success) return [];
|
||||
const lines = result.stdout.split('\n');
|
||||
const gpus: GpuInfo[] = [];
|
||||
|
||||
for (const line of lines) {
|
||||
@@ -213,19 +219,4 @@ export class SystemInfo {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private async runCommand(cmd: string, args: string[] = []): Promise<string> {
|
||||
const command = new Deno.Command(cmd, {
|
||||
args,
|
||||
stdout: 'piped',
|
||||
stderr: 'piped',
|
||||
});
|
||||
|
||||
const result = await command.output();
|
||||
if (!result.success) {
|
||||
throw new Error('Command failed');
|
||||
}
|
||||
|
||||
return new TextDecoder().decode(result.stdout);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user