Add native context menu to delete threads #12
Mergedjuliusmarmingemerged 1 commit into
main fromjuliusmarminge/sidebar-delete-threadmerged by juliusmarminge View on GitHub- apps/desktop/src/main.ts line 6Outdated@@ -43,18 +4,3 @@43- });44- probe.on("error", reject);45- });46-}47-48-function backendEnv(): NodeJS.ProcessEnv {49- return {50- ...process.env,51- T3CODE_MODE: "desktop",52- T3CODE_NO_BROWSER: "1",53- T3CODE_PORT: String(backendPort),54- T3CODE_STATE_DIR: STATE_DIR,55- T3CODE_AUTH_TOKEN: backendAuthToken,56- };57-}58-59-function scheduleBackendRestart(reason: string): void {60- if (isQuitting || restartTimer) return;4+import { spawn } from "node:child_process";5+import path from "node:path";6+import { BrowserWindow, Menu, app, dialog, ipcMain, session, shell } from "electron";@@ -162,0 +92,21 @@92+ ]);93+ if (clicked !== "delete") return;94+95+ const thread = state.threads.find((t) => t.id === threadId);96+ if (!thread) return;97+98+ // Stop active session if running99+ if (thread.session?.sessionId) {100+ try {101+ await api.providers.stopSession({102+ sessionId: thread.session.sessionId,103+ });104+ } catch {105+ // Session may already be stopped106+ }107+ }108+109+ dispatch({ type: "DELETE_THREAD", threadId });110+ },111+ [api, dispatch, state.threads],112+ );@@ -33,4 +42,5 @@3342 | { type: "SET_ERROR"; threadId: string; error: string | null }3443 | { type: "SET_THREAD_TITLE"; threadId: string; title: string }3544 | { type: "SET_THREAD_MODEL"; threadId: string; model: string }36- | { type: "SET_RUNTIME_MODE"; mode: RuntimeMode };45+ | { type: "SET_RUNTIME_MODE"; mode: RuntimeMode }46+ | { type: "DELETE_THREAD"; threadId: string };
- @@ -160,3 +160,12 @@160160 }161161 };162162163+ const handleThreadContextMenu = useCallback(164+ async (threadId: string) => {165+ if (!api) return;166+ const clicked = await api.contextMenu.show([167+ { id: "delete", label: "Delete" },168+ ]);169+ if (clicked !== "delete") return;170+171+ const thread = state.threads.find((t) => t.id === threadId);@@ -290,3 +317,4 @@290317 threadId: thread.id,291318 })292319 }320+ onContextMenu={(e) => {
- packages/contracts/src/ipc.ts lines 28 to 31OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -25,3 +25,7 @@25252626 export type EditorId = (typeof EDITORS)[number]["id"];272728+export interface ContextMenuItem {29+ id: string;30+ label: string;31+}
juliusmarminge merged this169d06f
juliusmarminge closed this
Sign in to join this conversation.
Note
Reviews paused#
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
reviews.auto_review.auto_pause_after_reviewed_commitssetting.Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.Use the checkboxes below for quick actions:
Walkthrough#
Adds a cross-platform context menu: Electron main IPC handler and preload bridge, contract/type additions, web fallback UI, and web UI + store updates to show a thread context menu and delete threads when "Delete" is selected.
Changes#
apps/desktop/src/main.ts,apps/desktop/src/preload.tsCONTEXT_MENU_CHANNEL("desktop:context-menu") and importMenuin main; handle IPC invoke by building a native Menu, showing a popup, and resolving selectedidornull. ExposeshowContextMenu(items)ondesktopBridgein preload.packages/contracts/src/ipc.tsNativeApiwith `contextMenu.show(items: readonly { id: T; label: string }[], position?: { x: number; y: number }) => Promise<Tapps/web/src/wsNativeApi.ts,apps/web/src/contextMenuFallback.ts,apps/web/src/vite-env.d.tsapi.contextMenu.showwhich callswindow.desktopBridge.showContextMenu(items)when available, otherwise usesshowContextMenuFallback(items, position). Implement DOM fallbackshowContextMenuFallbackand addshowContextMenutoDesktopBridgetypes.apps/web/src/components/Sidebar.tsx,apps/web/src/store.tsonContextMenuon thread items to callcontextMenu.show; handle selection of "Delete" by stopping active session (if any) and dispatchingDELETE_THREAD. AddDELETE_THREADaction and reducer case to remove the thread and adjustactiveThreadId.package.jsonSequence Diagram(s)#
Estimated code review effort#
🎯 3 (Moderate) | ⏱️ ~25 minutes
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment `@coderabbitai help` to get the list of available commands and usage tips.