Conversation
WalkthroughThis update introduces a new IPC-driven context menu for browser tabs, accessible via right-click in the sidebar. It adds backend event handling, a preload bridge, and interface updates to support the menu, while also refactoring the sidebar tab components to remove multi-mode complexity and streamline tab rendering and event handling. Changes
Sequence Diagram(s)sequenceDiagram
participant Renderer
participant Preload
participant Main
Renderer->>Preload: tabsAPI.showContextMenu(tabId)
Preload->>Main: ipcRenderer.send("tabs:show-context-menu", tabId)
Main->>Main: Handle "tabs:show-context-menu" event
Main->>Main: Retrieve tab and window
Main->>Main: Build context menu (Copy URL, Sleep/Wake, Close)
Main->>Main: Show context menu anchored to tab window
Possibly related PRs
Poem
Tip ⚡️ Faster reviews with caching
Enjoy the performance boost—your workflow just got faster. ✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (3)
src/main/ipc/browser/tabs.ts (1)
232-276: Minor readability & maintenance improvementThe context-menu items are built imperatively. Using
Menu.buildFromTemplatekeeps the code shorter, declarative, and easier to reorder/extend:-const contextMenu = new Menu(); - -contextMenu.append(new MenuItem({ /* Copy URL */ })); -… -contextMenu.append(new MenuItem({ /* separator */ })); -… -contextMenu.append(new MenuItem({ /* Sleep / Wake */ })); -… -contextMenu.append(new MenuItem({ /* Close */ })); - -contextMenu.popup({ window: tabbedWindow.window }); +const contextMenu = Menu.buildFromTemplate([ + { + label: "Copy URL", + enabled: hasURL, + click: () => hasURL && clipboard.writeText(tab.url!) + }, + { type: "separator" }, + { + label: isTabVisible + ? "Cannot put active tab to sleep" + : tab.asleep + ? "Wake Tab" + : "Put Tab to Sleep", + enabled: !isTabVisible, + click: () => { + tab.asleep ? (tab.wakeUp(), tabManager.setActiveTab(tab)) : tab.putToSleep(); + } + }, + { + label: "Close Tab", + click: () => tab.destroy() + } +]); + +contextMenu.popup({ window: tabbedWindow.window });No functional change – only easier to scan and less error-prone when items are added later.
src/renderer/src/components/browser-ui/sidebar/content/sidebar-tab-groups.tsx (2)
44-49: Guard against accidental right/middle clicks triggering “pressed” state
setIsPressed(true)runs for every mouse button, but the visual “pressed” effect is probably only intended for the primary button.
Add an early return for buttons!== 0and!== 1, or move the state update inside the left-button branch:if (e.button === 0) { handleClick(); + setIsPressed(true); } // Middle mouse button if (e.button === 1) { handleCloseTab(e); + setIsPressed(true); } - -setIsPressed(true);This prevents the pill-shrink animation from flashing when the user right-clicks to open the context menu.
64-77: Clean-up listener on dependency changeThe
useEffecthook installs a globalmouseuplistener but only removes it on unmount.
IfSidebarTabever re-mounts (e.g., key prop changes) the previous listener remains, leading to multiple handlers.Simplest safeguard – declare the effect with no dependencies so it only runs once:
-useEffect(() => { +useEffect(() => { … -}, []); +}, []); // empty deps – run onceIf the component really must update the listener, ensure you remove the old listener before adding a new one.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
src/main/ipc/browser/tabs.ts(2 hunks)src/preload/index.ts(1 hunks)src/renderer/src/components/browser-ui/sidebar/content/sidebar-tab-groups.tsx(4 hunks)src/shared/flow/interfaces/browser/tabs.ts(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/main/ipc/browser/tabs.ts (1)
src/main/index.ts (1)
browser(13-13)
There was a problem hiding this comment.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/preload/index.ts(1 hunks)src/renderer/src/components/browser-ui/sidebar/content/sidebar-tab-groups.tsx(4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- src/preload/index.ts
🔇 Additional comments (7)
src/renderer/src/components/browser-ui/sidebar/content/sidebar-tab-groups.tsx (7)
12-12: Function signature simplified appropriately.The removal of the
modeandfrontTabprops simplifies the component interface, making it more focused and easier to maintain. This aligns well with the removal of multi-mode support described in the summary.
44-48: Good refinement of mouse button handling.Clearly distinguishing left-click behavior with explicit comments and conditionals improves code readability and maintainability. This change ensures tab switching only happens on left mouse button clicks.
64-67: Context menu implementation looks good.The context menu handler correctly prevents the default browser context menu and integrates with the new IPC-based
showContextMenuAPI.
69-77: Proper event listener cleanup.Adding a global mouseup event listener with proper cleanup in the useEffect hook is a good practice to ensure the
isPressedstate is reset correctly even when the mouse is released outside the component.
83-90: Styling logic significantly simplified.The conditional styling based solely on focus state rather than multiple modes makes the code more maintainable and easier to understand.
107-157: UI structure well-organized with clear section comments.The simplified rendering logic with clear section comments ("Left side", "Right side") improves code readability. The removal of mode-dependent rendering makes the component more maintainable.
178-182: Tab rendering simplified appropriately.The tab rendering logic has been streamlined by removing mode-dependent styling and rendering, which aligns with the overall goal of simplifying the sidebar tab components.
Summary by CodeRabbit
New Features
Refactor