2026-04-24 10:18:46 -07:00
|
|
|
|
import { useEffect, useState } from "react";
|
2026-02-28 20:42:40 +00:00
|
|
|
|
import { useShallow } from "zustand/react/shallow";
|
2026-02-27 04:29:51 +00:00
|
|
|
|
import Sidebar from "./components/layout/Sidebar";
|
|
|
|
|
|
import TopBar from "./components/layout/TopBar";
|
|
|
|
|
|
import StatusBar from "./components/layout/StatusBar";
|
|
|
|
|
|
import TerminalView from "./components/terminal/TerminalView";
|
2026-04-24 10:18:46 -07:00
|
|
|
|
import DockerInstallDialog from "./components/DockerInstallDialog";
|
2026-08-09 11:35:42 -07:00
|
|
|
|
import ProjectHome from "./components/projects/home/ProjectHome";
|
|
|
|
|
|
import AddProjectDialog from "./components/projects/AddProjectDialog";
|
|
|
|
|
|
import ToastHost from "./components/ui/ToastHost";
|
|
|
|
|
|
import StatusIndicator from "./components/ui/StatusIndicator";
|
|
|
|
|
|
import Button from "./components/ui/Button";
|
2026-02-27 04:29:51 +00:00
|
|
|
|
import { useDocker } from "./hooks/useDocker";
|
|
|
|
|
|
import { useSettings } from "./hooks/useSettings";
|
|
|
|
|
|
import { useProjects } from "./hooks/useProjects";
|
2026-02-28 21:18:33 +00:00
|
|
|
|
import { useUpdates } from "./hooks/useUpdates";
|
2026-06-28 19:26:05 -07:00
|
|
|
|
import { useTerminal } from "./hooks/useTerminal";
|
|
|
|
|
|
import { useSTT } from "./hooks/useSTT";
|
2026-08-09 11:35:42 -07:00
|
|
|
|
import { useContainerProgress } from "./hooks/useContainerProgress";
|
|
|
|
|
|
import { useKeyboardShortcuts } from "./hooks/useKeyboardShortcuts";
|
|
|
|
|
|
import { useAppState, isHomeTab, tabKeyId, homeTabKey } from "./store/appState";
|
2026-03-10 08:29:06 -07:00
|
|
|
|
import { reconcileProjectStatuses } from "./lib/tauri-commands";
|
2026-02-27 04:29:51 +00:00
|
|
|
|
|
|
|
|
|
|
export default function App() {
|
2026-03-03 14:46:59 -08:00
|
|
|
|
const { checkDocker, checkImage, startDockerPolling } = useDocker();
|
2026-03-01 03:59:58 +00:00
|
|
|
|
const { loadSettings } = useSettings();
|
2026-02-27 04:29:51 +00:00
|
|
|
|
const { refresh } = useProjects();
|
2026-03-12 09:26:58 -07:00
|
|
|
|
const { loadVersion, checkForUpdates, checkImageUpdate, startPeriodicCheck } = useUpdates();
|
2026-08-09 11:35:42 -07:00
|
|
|
|
const { sessions, activeSessionId, tabOrder, activeTabKey, setProjects, setSttToggle } =
|
|
|
|
|
|
useAppState(
|
|
|
|
|
|
useShallow(s => ({
|
|
|
|
|
|
sessions: s.sessions,
|
|
|
|
|
|
activeSessionId: s.activeSessionId,
|
|
|
|
|
|
tabOrder: s.tabOrder,
|
|
|
|
|
|
activeTabKey: s.activeTabKey,
|
|
|
|
|
|
setProjects: s.setProjects,
|
|
|
|
|
|
setSttToggle: s.setSttToggle,
|
|
|
|
|
|
}))
|
|
|
|
|
|
);
|
2026-04-24 10:18:46 -07:00
|
|
|
|
const [showInstallDialog, setShowInstallDialog] = useState(false);
|
2026-02-27 04:29:51 +00:00
|
|
|
|
|
2026-06-28 19:26:05 -07:00
|
|
|
|
// Single STT instance bound to the active session. The mic lives in the
|
|
|
|
|
|
// StatusBar; the terminal's Ctrl+Shift+M shortcut calls stt.toggle via the
|
|
|
|
|
|
// store (registered below).
|
|
|
|
|
|
const { sendInput } = useTerminal();
|
|
|
|
|
|
const stt = useSTT(activeSessionId ?? "", sendInput);
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
setSttToggle(stt.toggle);
|
|
|
|
|
|
}, [stt.toggle, setSttToggle]);
|
|
|
|
|
|
|
2026-08-09 11:35:42 -07:00
|
|
|
|
useContainerProgress();
|
|
|
|
|
|
useKeyboardShortcuts();
|
|
|
|
|
|
|
2026-02-27 04:29:51 +00:00
|
|
|
|
// Initialize on mount
|
|
|
|
|
|
useEffect(() => {
|
2026-02-27 15:22:49 +00:00
|
|
|
|
loadSettings();
|
2026-03-03 14:46:59 -08:00
|
|
|
|
let stopPolling: (() => void) | undefined;
|
2026-02-28 20:42:40 +00:00
|
|
|
|
checkDocker().then((available) => {
|
2026-03-03 14:46:59 -08:00
|
|
|
|
if (available) {
|
|
|
|
|
|
checkImage();
|
2026-03-10 08:29:06 -07:00
|
|
|
|
// Reconcile project statuses against actual Docker container state,
|
|
|
|
|
|
// then refresh the project list so the UI reflects reality.
|
|
|
|
|
|
reconcileProjectStatuses().then((projects) => {
|
|
|
|
|
|
setProjects(projects);
|
|
|
|
|
|
}).catch(() => {
|
|
|
|
|
|
// If reconciliation fails (e.g. Docker hiccup), just load from store
|
|
|
|
|
|
refresh();
|
|
|
|
|
|
});
|
2026-03-03 14:46:59 -08:00
|
|
|
|
} else {
|
2026-04-24 10:18:46 -07:00
|
|
|
|
setShowInstallDialog(true);
|
2026-03-03 14:46:59 -08:00
|
|
|
|
stopPolling = startDockerPolling();
|
|
|
|
|
|
}
|
2026-02-28 20:42:40 +00:00
|
|
|
|
});
|
2026-02-27 04:29:51 +00:00
|
|
|
|
refresh();
|
2026-02-28 21:18:33 +00:00
|
|
|
|
|
|
|
|
|
|
// Update detection
|
|
|
|
|
|
loadVersion();
|
2026-03-12 09:26:58 -07:00
|
|
|
|
const updateTimer = setTimeout(() => {
|
|
|
|
|
|
checkForUpdates();
|
|
|
|
|
|
checkImageUpdate();
|
|
|
|
|
|
}, 3000);
|
2026-02-28 21:18:33 +00:00
|
|
|
|
const cleanup = startPeriodicCheck();
|
|
|
|
|
|
return () => {
|
|
|
|
|
|
clearTimeout(updateTimer);
|
|
|
|
|
|
cleanup?.();
|
2026-03-03 14:46:59 -08:00
|
|
|
|
stopPolling?.();
|
2026-02-28 21:18:33 +00:00
|
|
|
|
};
|
2026-02-27 04:29:51 +00:00
|
|
|
|
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
|
|
|
|
|
|
2026-08-09 11:35:42 -07:00
|
|
|
|
const homeProjectIds = tabOrder.filter(isHomeTab).map(tabKeyId);
|
|
|
|
|
|
|
2026-02-27 04:29:51 +00:00
|
|
|
|
return (
|
2026-08-09 11:35:42 -07:00
|
|
|
|
<div className="flex flex-col h-screen p-3 gap-3 bg-[var(--bg-primary)]">
|
2026-02-27 04:29:51 +00:00
|
|
|
|
<TopBar />
|
2026-08-09 11:35:42 -07:00
|
|
|
|
<div className="flex flex-1 min-h-0 gap-3">
|
2026-02-27 04:29:51 +00:00
|
|
|
|
<Sidebar />
|
2026-08-09 11:35:42 -07:00
|
|
|
|
<main className="flex-1 bg-[var(--bg-secondary)] border border-[var(--border-color)] rounded-[var(--radius-panel)] min-w-0 overflow-hidden">
|
|
|
|
|
|
{tabOrder.length === 0 ? (
|
2026-02-27 04:29:51 +00:00
|
|
|
|
<WelcomeScreen />
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<div className="w-full h-full">
|
2026-08-09 11:35:42 -07:00
|
|
|
|
{homeProjectIds.map((projectId) => (
|
|
|
|
|
|
<ProjectHome
|
|
|
|
|
|
key={projectId}
|
|
|
|
|
|
projectId={projectId}
|
|
|
|
|
|
active={activeTabKey === homeTabKey(projectId)}
|
|
|
|
|
|
/>
|
|
|
|
|
|
))}
|
2026-02-27 04:29:51 +00:00
|
|
|
|
{sessions.map((session) => (
|
|
|
|
|
|
<TerminalView
|
|
|
|
|
|
key={session.id}
|
|
|
|
|
|
sessionId={session.id}
|
|
|
|
|
|
active={session.id === activeSessionId}
|
|
|
|
|
|
/>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</main>
|
|
|
|
|
|
</div>
|
2026-06-28 19:26:05 -07:00
|
|
|
|
<StatusBar stt={stt} />
|
2026-08-09 11:35:42 -07:00
|
|
|
|
<ToastHost />
|
2026-04-24 10:18:46 -07:00
|
|
|
|
{showInstallDialog && (
|
|
|
|
|
|
<DockerInstallDialog onClose={() => setShowInstallDialog(false)} />
|
|
|
|
|
|
)}
|
2026-02-27 04:29:51 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-08-09 11:35:42 -07:00
|
|
|
|
/**
|
|
|
|
|
|
* First run is a checklist, not a paragraph: it reuses state the app already
|
|
|
|
|
|
* tracks and ends in a real button.
|
|
|
|
|
|
*/
|
2026-02-27 04:29:51 +00:00
|
|
|
|
function WelcomeScreen() {
|
2026-08-09 11:35:42 -07:00
|
|
|
|
const { dockerAvailable, imageExists, projects, openProjectHome } = useAppState(
|
|
|
|
|
|
useShallow((s) => ({
|
|
|
|
|
|
dockerAvailable: s.dockerAvailable,
|
|
|
|
|
|
imageExists: s.imageExists,
|
|
|
|
|
|
projects: s.projects,
|
|
|
|
|
|
openProjectHome: s.openProjectHome,
|
|
|
|
|
|
})),
|
|
|
|
|
|
);
|
|
|
|
|
|
const [showAdd, setShowAdd] = useState(false);
|
|
|
|
|
|
|
|
|
|
|
|
const steps: {
|
|
|
|
|
|
label: string;
|
|
|
|
|
|
state: boolean | null;
|
|
|
|
|
|
pendingLabel: string;
|
|
|
|
|
|
failLabel: string;
|
|
|
|
|
|
}[] = [
|
|
|
|
|
|
{
|
|
|
|
|
|
label: "Docker detected",
|
|
|
|
|
|
state: dockerAvailable,
|
|
|
|
|
|
pendingLabel: "Checking for Docker…",
|
|
|
|
|
|
failLabel: "Docker not available",
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
label: "Container image ready",
|
|
|
|
|
|
state: imageExists,
|
|
|
|
|
|
pendingLabel: "Checking for the image…",
|
|
|
|
|
|
failLabel: "Image not pulled yet — see Settings › Container",
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
label: `${projects.length} project${projects.length === 1 ? "" : "s"} configured`,
|
|
|
|
|
|
state: projects.length > 0 ? true : false,
|
|
|
|
|
|
pendingLabel: "",
|
|
|
|
|
|
failLabel: "No projects yet",
|
|
|
|
|
|
},
|
|
|
|
|
|
];
|
|
|
|
|
|
|
2026-02-27 04:29:51 +00:00
|
|
|
|
return (
|
2026-08-09 11:35:42 -07:00
|
|
|
|
<div className="flex items-center justify-center h-full p-6">
|
|
|
|
|
|
<div className="w-full max-w-md">
|
|
|
|
|
|
<h1 className="text-xl font-semibold text-[var(--text-primary)]">Triple-C</h1>
|
|
|
|
|
|
<p className="text-[13px] text-[var(--text-secondary)] mb-5">
|
|
|
|
|
|
Claude Code, sandboxed in a container.
|
2026-02-27 04:29:51 +00:00
|
|
|
|
</p>
|
2026-08-09 11:35:42 -07:00
|
|
|
|
|
|
|
|
|
|
<ol className="space-y-2 mb-5">
|
|
|
|
|
|
{steps.map((step) => (
|
|
|
|
|
|
<li
|
|
|
|
|
|
key={step.label}
|
|
|
|
|
|
className="flex items-center gap-2 px-3 py-2 bg-[var(--bg-primary)] border border-[var(--border-color)] rounded-[var(--radius-control)]"
|
|
|
|
|
|
>
|
|
|
|
|
|
<StatusIndicator
|
|
|
|
|
|
tone={step.state === true ? "ok" : step.state === false ? "error" : "unknown"}
|
|
|
|
|
|
label={
|
|
|
|
|
|
step.state === true
|
|
|
|
|
|
? step.label
|
|
|
|
|
|
: step.state === false
|
|
|
|
|
|
? step.failLabel
|
|
|
|
|
|
: step.pendingLabel
|
|
|
|
|
|
}
|
|
|
|
|
|
className="text-[13px]"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</li>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</ol>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
|
<Button size="md" variant="primary" onClick={() => setShowAdd(true)}>
|
|
|
|
|
|
{projects.length === 0 ? "Add your first project" : "Add a project"}
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
{projects.length > 0 && (
|
|
|
|
|
|
<Button size="md" onClick={() => openProjectHome(projects[0].id)}>
|
|
|
|
|
|
Open {projects[0].name}
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<p className="mt-4 text-xs text-[var(--text-secondary)]">
|
|
|
|
|
|
Then start its container and press{" "}
|
|
|
|
|
|
<kbd className="px-1 py-0.5 font-mono bg-[var(--bg-tertiary)] border border-[var(--border-color)] rounded-[4px]">
|
|
|
|
|
|
Ctrl+T
|
|
|
|
|
|
</kbd>{" "}
|
|
|
|
|
|
to open a Claude terminal.
|
|
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
{showAdd && <AddProjectDialog onClose={() => setShowAdd(false)} />}
|
2026-02-27 04:29:51 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|