feat: adapt renderer for browser mode

- App.tsx: Add AutoProjectBootstrap that listens for server welcome
  and auto-creates project + thread from server's cwd
- Sidebar: Conditionalize drag region (Electron only), hide Browse button in browser
- ChatView: Conditionalize drag region, adjust padding for browser
- DiffPanel: Same drag region treatment
- index.html: Update title to 'CodeThing'
- env.ts: isElectron detection utility

Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
Cursor AgentandTheo Browne committed 2026-02-09 21:48:49 +00:00
1 parent f94bbc442d
commit 948947d92b
6 files changed
+76 -10

No files matched your search

+1 -1
View File
@@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Electron Todo</title>
<title>CodeThing</title>
</head>
<body>
<div id="root"></div>
+58 -2
View File
@@ -3,8 +3,10 @@ import { useEffect, useMemo, useRef } from "react";
import ChatView from "./components/ChatView";
import DiffPanel from "./components/DiffPanel";
import Sidebar from "./components/Sidebar";
import { DEFAULT_MODEL } from "./model-logic";
import { readNativeApi } from "./session-logic";
import { StoreProvider, useStore } from "./store";
import { onServerWelcome } from "./wsNativeApi";
function EventRouter() {
const api = useMemo(() => readNativeApi(), []);
@@ -25,6 +27,60 @@ function EventRouter() {
return null;
}
function AutoProjectBootstrap() {
const { state, dispatch } = useStore();
useEffect(() => {
return onServerWelcome((payload) => {
// Don't create duplicate projects for the same cwd
const existing = state.projects.find((p) => p.cwd === payload.cwd);
if (existing) {
// If there are threads, ensure one is active
const existingThread = state.threads.find(
(t) => t.projectId === existing.id,
);
if (existingThread && !state.activeThreadId) {
dispatch({
type: "SET_ACTIVE_THREAD",
threadId: existingThread.id,
});
}
return;
}
// Create project + thread from server cwd
const projectId = crypto.randomUUID();
dispatch({
type: "ADD_PROJECT",
project: {
id: projectId,
name: payload.projectName,
cwd: payload.cwd,
model: DEFAULT_MODEL,
expanded: true,
},
});
dispatch({
type: "ADD_THREAD",
thread: {
id: crypto.randomUUID(),
codexThreadId: null,
projectId,
title: "New thread",
model: DEFAULT_MODEL,
session: null,
messages: [],
events: [],
error: null,
createdAt: new Date().toISOString(),
},
});
});
}, [state.projects, state.threads, state.activeThreadId, dispatch]);
return null;
}
function Layout() {
const api = useMemo(() => readNativeApi(), []);
const { state } = useStore();
@@ -32,10 +88,9 @@ function Layout() {
if (!api) {
return (
<div className="flex h-screen flex-col bg-background text-foreground">
<div className="drag-region h-[52px] shrink-0" />
<div className="flex flex-1 items-center justify-center">
<p className="text-sm text-muted-foreground">
Native bridge unavailable. Launch through Electron.
Connecting to CodeThing server...
</p>
</div>
</div>
@@ -45,6 +100,7 @@ function Layout() {
return (
<div className="flex h-screen overflow-hidden bg-background text-foreground">
<EventRouter />
<AutoProjectBootstrap />
<Sidebar />
<ChatView />
{state.diffOpen && <DiffPanel />}
+3 -2
View File
@@ -14,6 +14,7 @@ import {
} from "react";
import { EDITORS, type EditorId } from "@acme/contracts";
import { isElectron } from "../env";
import { buildBootstrapInput } from "../historyBootstrap";
import {
DEFAULT_MODEL,
@@ -537,7 +538,7 @@ export default function ChatView() {
if (!activeThread) {
return (
<div className="flex flex-1 flex-col bg-background text-muted-foreground/40">
<div className="drag-region h-[52px] shrink-0" />
{isElectron && <div className="drag-region h-[52px] shrink-0" />}
<div className="flex flex-1 items-center justify-center">
<div className="text-center">
<p className="text-sm">Select a thread or create a new one to get started.</p>
@@ -550,7 +551,7 @@ export default function ChatView() {
return (
<div className="flex flex-1 flex-col bg-background">
{/* Top bar */}
<header className="drag-region flex items-center justify-between border-b border-border px-5 pt-[28px] pb-3">
<header className={`flex items-center justify-between border-b border-border px-5 pb-3 ${isElectron ? "drag-region pt-[28px]" : "pt-3"}`}>
<div className="flex items-center gap-3">
<h2 className="text-sm font-medium text-foreground">
{activeThread.title}
+2 -1
View File
@@ -1,3 +1,4 @@
import { isElectron } from "../env";
import { useStore } from "../store";
export default function DiffPanel() {
@@ -6,7 +7,7 @@ export default function DiffPanel() {
return (
<aside className="flex h-full w-[400px] shrink-0 flex-col border-l border-border bg-card">
{/* Header */}
<div className="drag-region flex items-center justify-between border-b border-border px-4 pt-[28px] pb-3">
<div className={`flex items-center justify-between border-b border-border px-4 pb-3 ${isElectron ? "drag-region pt-[28px]" : "pt-3"}`}>
<h3 className="text-xs font-medium text-foreground">Uncommitted changes</h3>
<button
type="button"
+5 -4
View File
@@ -1,5 +1,6 @@
import { MonitorIcon, MoonIcon, SunIcon } from "lucide-react";
import { useCallback, useEffect, useMemo, useState } from "react";
import { isElectron } from "../env";
import { useTheme } from "../hooks/useTheme";
import { DEFAULT_MODEL } from "../model-logic";
import { readNativeApi } from "../session-logic";
@@ -125,10 +126,10 @@ export default function Sidebar() {
return (
<aside className="sidebar flex h-full w-[260px] shrink-0 flex-col border-r border-border bg-card">
{/* Drag region / traffic light space */}
<div className="drag-region h-[52px] shrink-0" />
{/* Drag region / traffic light space (Electron only) */}
{isElectron && <div className="drag-region h-[52px] shrink-0" />}
{/* Branding */}
<div className="flex items-center gap-2 px-4 pb-4">
<div className={`flex items-center gap-2 px-4 pb-4 ${isElectron ? "" : "pt-4"}`}>
<div className="flex h-7 w-7 items-center justify-center rounded-lg bg-primary text-xs font-bold text-primary-foreground">
CT
</div>
@@ -281,7 +282,7 @@ export default function Sidebar() {
if (e.key === "Escape") setAddingProject(false);
}}
/>
{api && (
{isElectron && api && (
<button
type="button"
className="mb-2 flex w-full items-center justify-center rounded-md border border-border px-2 py-1.5 text-xs text-muted-foreground transition-colors duration-150 hover:bg-secondary disabled:cursor-not-allowed disabled:opacity-60"
+7
View File
@@ -0,0 +1,7 @@
/**
* True when running inside the Electron preload bridge, false in a regular browser.
* The preload script sets window.nativeApi via contextBridge before any renderer
* code executes, so this is reliable at module load time.
*/
export const isElectron =
typeof window !== "undefined" && window.nativeApi !== undefined;