Refactor error handling and localDb structure, and fix usage tracking bug.

This commit is contained in:
decolua
2026-04-17 12:15:10 +07:00
parent 3badf1cbb6
commit 75ad0bef8e
13 changed files with 162 additions and 109 deletions
@@ -217,7 +217,7 @@ export default function ClaudeToolCard({
return [
{
filename: "~/.claude/settings.json",
content: JSON.stringify({ env }, null, 2),
content: JSON.stringify({ hasCompletedOnboarding: true, env }, null, 2),
},
];
};
@@ -226,8 +226,30 @@ export default function APIPageClient({ machineId }) {
setTunnelLoading(true);
setTunnelStatus(null);
setTunnelProgress("Creating tunnel...");
// Poll download progress while enable request is pending
let polling = true;
const pollProgress = async () => {
while (polling) {
try {
const r = await fetch("/api/tunnel/status");
if (r.ok) {
const s = await r.json();
if (s.download?.downloading) {
setTunnelProgress(`Downloading cloudflared... ${s.download.progress}%`);
} else if (polling) {
setTunnelProgress("Creating tunnel...");
}
}
} catch { /* ignore */ }
await new Promise((r) => setTimeout(r, 1000));
}
};
pollProgress();
try {
const res = await fetch("/api/tunnel/enable", { method: "POST" });
polling = false;
const data = await res.json();
if (!res.ok) {
setTunnelStatus({ type: "error", message: data.error || "Failed to enable tunnel" });
@@ -246,6 +268,7 @@ export default function APIPageClient({ machineId }) {
} catch (error) {
setTunnelStatus({ type: "error", message: error.message });
} finally {
polling = false;
setTunnelLoading(false);
setTunnelProgress("");
}