@@ -194,14 +194,20 @@ export function Viewport() {
|
||||
addressRef.current?.blur();
|
||||
|
||||
const target = normalizeUrl(addressValue);
|
||||
const previousUrl = url;
|
||||
setAddressValue(target);
|
||||
setNavigating(true);
|
||||
try {
|
||||
await runCmd("navigate", target);
|
||||
const result = await runCmd("navigate", target);
|
||||
if (!result.success) {
|
||||
setAddressValue(previousUrl || "about:blank");
|
||||
}
|
||||
} catch {
|
||||
setAddressValue(previousUrl || "about:blank");
|
||||
} finally {
|
||||
setNavigating(false);
|
||||
}
|
||||
}, [addressValue, navigating, runCmd]);
|
||||
}, [addressValue, navigating, runCmd, url]);
|
||||
|
||||
const drawFrame = useCallback((base64: string) => {
|
||||
const canvas = canvasRef.current;
|
||||
|
||||
@@ -8,12 +8,21 @@ export interface ExecResult {
|
||||
}
|
||||
|
||||
export async function execCommand(args: string[]): Promise<ExecResult> {
|
||||
const resp = await fetch(`http://localhost:${DASHBOARD_PORT}/api/exec`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ args }),
|
||||
});
|
||||
return resp.json();
|
||||
try {
|
||||
const resp = await fetch(`http://localhost:${DASHBOARD_PORT}/api/exec`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ args }),
|
||||
});
|
||||
return resp.json();
|
||||
} catch {
|
||||
return {
|
||||
success: false,
|
||||
exit_code: null,
|
||||
stdout: "",
|
||||
stderr: "Network error: dashboard server unreachable",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export function sessionArgs(session: string, ...args: string[]): string[] {
|
||||
@@ -21,10 +30,14 @@ export function sessionArgs(session: string, ...args: string[]): string[] {
|
||||
}
|
||||
|
||||
export async function killSession(session: string): Promise<{ success: boolean; killed_pid?: number }> {
|
||||
const resp = await fetch(`http://localhost:${DASHBOARD_PORT}/api/kill`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ session }),
|
||||
});
|
||||
return resp.json();
|
||||
try {
|
||||
const resp = await fetch(`http://localhost:${DASHBOARD_PORT}/api/kill`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ session }),
|
||||
});
|
||||
return resp.json();
|
||||
} catch {
|
||||
return { success: false };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user