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:
2026-01-08 16:31:57 +00:00
parent 1435496a1c
commit 3fb8b14e41
9 changed files with 87 additions and 438 deletions

View File

@@ -4,6 +4,8 @@
* Manages spawning and monitoring of Sway and Chromium processes
*/
import { runCommand } from '../utils/command.ts';
export interface SwayConfig {
runtimeDir: string;
backends: string;
@@ -18,6 +20,7 @@ export interface BrowserConfig {
runtimeDir: string;
waylandDisplay: string;
url: string;
kiosk?: boolean;
}
export class ProcessManager {
@@ -70,13 +73,7 @@ focus_follows_mouse yes
# Force all windows fullscreen for kiosk mode
for_window [app_id=".*"] fullscreen enable
# Chromium-specific fullscreen rules
for_window [app_id="chromium-browser"] fullscreen enable
for_window [app_id="Chromium-browser"] fullscreen enable
for_window [app_id="chromium"] fullscreen enable
for_window [class="Chromium-browser"] fullscreen enable
for_window [class="chromium-browser"] fullscreen enable
`;
}
@@ -88,37 +85,19 @@ for_window [class="chromium-browser"] fullscreen enable
const configPath = `${configDir}/config`;
// Create config directory
await this.runCommand('mkdir', ['-p', configDir]);
await this.runCommand('chown', [`${this.user}:${this.user}`, `/home/${this.user}/.config`]);
await this.runCommand('chown', [`${this.user}:${this.user}`, configDir]);
await runCommand('mkdir', ['-p', configDir]);
await runCommand('chown', [`${this.user}:${this.user}`, `/home/${this.user}/.config`]);
await runCommand('chown', [`${this.user}:${this.user}`, configDir]);
// Write config file
const configContent = this.generateSwayConfig(config);
await Deno.writeTextFile(configPath, configContent);
await this.runCommand('chown', [`${this.user}:${this.user}`, configPath]);
await runCommand('chown', [`${this.user}:${this.user}`, configPath]);
console.log(`[sway] Config written to ${configPath}`);
return configPath;
}
private async runCommand(
cmd: string,
args: string[]
): Promise<{ success: boolean; stdout: string; stderr: string }> {
const command = new Deno.Command(cmd, {
args,
stdout: 'piped',
stderr: 'piped',
});
const result = await command.output();
return {
success: result.success,
stdout: new TextDecoder().decode(result.stdout),
stderr: new TextDecoder().decode(result.stderr),
};
}
async startSway(config: SwayConfig): Promise<void> {
// Write sway config before starting
const configPath = await this.writeSwayConfig(config);
@@ -287,10 +266,7 @@ for_window [class="chromium-browser"] fullscreen enable
// Try multiple selectors to ensure we catch the window
const selectors = [
'[app_id="chromium-browser"]',
'[app_id="Chromium-browser"]',
'[app_id="chromium"]',
'[class="Chromium-browser"]',
'[class="chromium-browser"]',
];
for (const selector of selectors) {
@@ -301,11 +277,6 @@ for_window [class="chromium-browser"] fullscreen enable
await this.swaymsg(config, '[app_id="chromium-browser"] focus');
}
// Legacy method name for backwards compatibility
async startChrome(config: BrowserConfig & { kiosk?: boolean }): Promise<void> {
return this.startBrowser(config);
}
isSwayRunning(): boolean {
return this.swayProcess !== null;
}
@@ -314,11 +285,6 @@ for_window [class="chromium-browser"] fullscreen enable
return this.browserProcess !== null;
}
// Legacy method name for backwards compatibility
isChromeRunning(): boolean {
return this.isBrowserRunning();
}
async stopSway(): Promise<void> {
if (this.swayProcess) {
try {
@@ -343,11 +309,6 @@ for_window [class="chromium-browser"] fullscreen enable
}
}
// Legacy method name for backwards compatibility
async stopChrome(): Promise<void> {
return this.stopBrowser();
}
private async pipeOutput(
process: Deno.ChildProcess,
name: string