summaryrefslogtreecommitdiff
path: root/src/renderer/src
diff options
context:
space:
mode:
authorhaoyuren <13851610112@163.com>2026-09-04 22:26:49 -0500
committerhaoyuren <13851610112@163.com>2026-09-04 22:26:49 -0500
commit34f22876ab9e15e9f14300a8c21cd7109800d1ab (patch)
treef9599f631c38773666c747f41e97752cfafc8e19 /src/renderer/src
parent1251d9208caadce626fd0706dfd34ba3e022fb2a (diff)
Fix main-document switching end to end; stable project-independent MCP pathHEADmain
Main document: the app never called Overleaf's official settings endpoint, so "Set as main document" only changed renderer state and agents had no way to switch at all — compiles kept using the old root. Now: - Right-click Set as main and the new set_main_file MCP tool both POST /project/:id/settings {rootDocId} (web parity, persists project-wide) - Handle the rootDocUpdated broadcast: update the project snapshot, the renderer state, and rewrite CLAUDE.md/AGENTS.md — the guide's stale "Main file" line was teaching agents to compile the old root via main_file overrides - Compile root resolution uses the sync bridge's live maps, so docs created mid-session resolve correctly (agent guide too) MCP server location: Codex stores its MCP registration globally, and the per-project path went stale when the project temp dir was cleaned up ("connection closed" on handshake). The bundled server now installs to ~/.lattex/lattex-mcp.mjs (project-independent, refreshed on connect; the esbuild bundle since the raw source can't resolve node_modules from there) and resolves the project at runtime: $LATTEX_PROJECT_DIR, cwd + ancestors, legacy script location, then single live project in tmpdir. Register once, works for every project. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Diffstat (limited to 'src/renderer/src')
-rw-r--r--src/renderer/src/App.tsx12
-rw-r--r--src/renderer/src/components/FileTree.tsx23
2 files changed, 30 insertions, 5 deletions
diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx
index f3f9f79..0f48a3c 100644
--- a/src/renderer/src/App.tsx
+++ b/src/renderer/src/App.tsx
@@ -309,6 +309,17 @@ export default function App() {
setStatusMessage('Overleaf session expired — please sign in again')
})
+ // Main document changed (by us or a collaborator) — track it
+ const unsubRootDoc = window.api.onProjectRootDocUpdated?.((docId) => {
+ const store = useAppStore.getState()
+ store.setMainDocument(docId)
+ if (store.overleafProject) {
+ store.setOverleafProject({ ...store.overleafProject, rootDocId: docId })
+ }
+ const name = store.docPathMap[docId]?.split('/').pop()
+ if (name) setStatusMessage(`Main document: ${name}`)
+ })
+
// Keep the file tree in sync with Overleaf project-entity socket events.
const unsubEntityCreated = window.api.onSyncEntityCreated((data) => {
applyEntityCreated(data)
@@ -427,6 +438,7 @@ export default function App() {
unsubCursorDisconnected()
unsubFileStatus?.()
unsubAuthExpired?.()
+ unsubRootDoc?.()
remoteCursors.clear()
stopAutocompleteSync()
}
diff --git a/src/renderer/src/components/FileTree.tsx b/src/renderer/src/components/FileTree.tsx
index 5486f20..f53ae2f 100644
--- a/src/renderer/src/components/FileTree.tsx
+++ b/src/renderer/src/components/FileTree.tsx
@@ -212,14 +212,27 @@ export default function FileTree() {
// ── Project view actions (Overleaf entities) ──
- const handleSetMainDoc = () => {
+ const handleSetMainDoc = async () => {
if (!ctxMenu) return
const node = ctxMenu.node
- if (node.docId) {
- useAppStore.getState().setMainDocument(node.docId)
- useAppStore.getState().setStatusMessage(`Main document set to ${node.name}`)
- }
closeMenu()
+ if (!node.docId) return
+ const store = useAppStore.getState()
+ // Optimistic local update; the official settings endpoint persists it
+ // project-wide (and broadcasts rootDocUpdated to collaborators)
+ store.setMainDocument(node.docId)
+ const projectId = store.overleafProjectId
+ if (!projectId) return
+ const r = await window.api.overleafSetRootDoc(projectId, node.docId)
+ if (r.success) {
+ const st = useAppStore.getState()
+ if (st.overleafProject) {
+ st.setOverleafProject({ ...st.overleafProject, rootDocId: node.docId })
+ }
+ st.setStatusMessage(`Main document set to ${node.name}`)
+ } else {
+ useAppStore.getState().setStatusMessage(`Failed to set main document (${r.message || 'error'})`)
+ }
}
const handleCopyPath = () => {