Skip to content

Comments

Add Sleep Tabs Functionality#23

Merged
iamEvanYT merged 2 commits intomainfrom
evan/sleep-tabs
Apr 18, 2025
Merged

Add Sleep Tabs Functionality#23
iamEvanYT merged 2 commits intomainfrom
evan/sleep-tabs

Conversation

@iamEvanYT
Copy link
Member

@iamEvanYT iamEvanYT commented Apr 18, 2025

  • Introduced navHistory and asleep properties to the Tab class.
  • Updated tab creation options to include navigation history and sleep state.
  • Implemented methods to manage tab sleep state, including putToSleep and wakeUp.
  • Enhanced tab data retrieval to include new properties.
  • Updated tab state management to account for sleep state and navigation history changes.

Summary by CodeRabbit

  • New Features
    • Introduced a sleep/wake functionality for tabs, allowing tabs to be put to sleep to save resources and later woken up.
    • Tabs now preserve and restore their navigation history when sleeping or waking.
  • Improvements
    • Tab information now includes sleep state and navigation history, providing more detailed tab data.

- Introduced `navHistory` and `asleep` properties to the Tab class.
- Updated tab creation options to include navigation history and sleep state.
- Implemented methods to manage tab sleep state, including `putToSleep` and `wakeUp`.
- Enhanced tab data retrieval to include new properties.
- Updated tab state management to account for sleep state and navigation history changes.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 18, 2025

Walkthrough

The changes introduce a new "asleep" state for browser tabs, allowing tabs to be put to sleep and later woken up. This includes tracking and restoring navigation history, updating tab state management, and modifying the tab creation process to support these new behaviors. The Tab class is extended with new properties and methods for sleep/wake lifecycle management, and related data structures and IPC data serialization are updated to include the new state and navigation history information.

Changes

File(s) Change Summary
electron/browser/tabs/tab.ts Extended Tab class with "asleep" state, navigation history tracking, and new methods for sleep/wake lifecycle. Updated state management and tab creation logic to support these features.
electron/ipc/browser/tabs.ts Modified getTabData to include asleep and navHistory properties in the returned tab data.
shared/types/tabs.ts Added NavigationEntry type and extended TabData with asleep (boolean) and navHistory (array).

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Tab
    participant WebContents

    User->>Tab: Show tab (tab is asleep)
    Tab->>Tab: wakeUp()
    Tab->>WebContents: Restore URL and navigation history

    User->>Tab: Put tab to sleep
    Tab->>Tab: putToSleep()
    Tab->>WebContents: Save state, load about:blank
Loading

Suggested labels

enhancement

Poem

💤
A rabbit hops from tab to tab,
Now some can nap, no need to gab!
With memories saved, they rest their head,
And wake refreshed when they're unshed.
Navigation trails are safely kept,
While sleeping tabs have softly slept.
Hooray for tabs that dream and wake—
More hops to make, less RAM to take!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bdefaf5 and e31a3cb.

📒 Files selected for processing (1)
  • electron/browser/tabs/tab.ts (11 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • electron/browser/tabs/tab.ts

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🔭 Outside diff range comments (1)
electron/browser/tabs/tab.ts (1)

157-177: ⚠️ Potential issue

Putting a tab to sleep before its first real navigation loses the URL

When a tab is constructed with asleep: true, putToSleep() is executed before loadURL(NEW_TAB_URL).

Consequences

  1. updateTabState() runs while webContents.getURL() is still "", so this.url is never initialised.
  2. putToSleep() then loads about:blank.
  3. wakeUp() later calls restoreTabState()loadURL(this.url, true) which is now "", so the tab never restores.

Deferred sleeping fixes the issue:

-    // Put to sleep if requested
-    if (asleep) {
-      this.putToSleep();
-    }
+    // Defer sleeping until the initial navigation finished so we capture the
+    // real URL first.
+    if (asleep) {
+      process.nextTick(() => this.putToSleep());
+    }

Alternatively, capture the intended URL before replacing it with about:blank.

🧹 Nitpick comments (2)
shared/types/tabs.ts (1)

3-6: Unify navigation‑history typings across renderer & main process

NavigationEntry is introduced as a project‑local alias.
In electron/browser/tabs/tab.ts a different NavigationEntry is imported from the Electron types, so the same identifier now refers to two structurally similar but distinct interfaces. This can easily lead to subtle type‑mismatch errors (e.g. excess‑property checks or future Electron upgrades that change the built‑in shape).

Consider standardising on one of the two below:

  1. Re‑export Electron’s NavigationHistoryEntry (if that is the actual type you rely on) from shared/types/tabs.ts and use a project alias such as BrowserNavigationEntry, or
  2. Keep this local definition but remove the import from electron and instead import it from ~/types/tabs everywhere.

Either way, ensure you only have a single source‑of‑truth for the navigation‑history entry shape.

Also applies to: 20-22

electron/ipc/browser/tabs.ts (1)

21-23: Large navHistory payload may bloat every IPC frame

navHistory can easily contain hundreds of entries. Serialising and transferring the entire array on every tabs:on-data-changed broadcast will noticeably increase IPC traffic and JSON serialisation costs.

Two low‑effort mitigations to consider:

-    navHistory: tab.navHistory
+    // Send *only* what the consumer needs.
+    navHistory: tab.navHistory.slice(-10) // last 10 entries

or gate it behind a flag:

navHistory: includeHistory ? tab.navHistory : []

Optimising here keeps UI updates snappy, especially when many tabs change state simultaneously.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8719545 and bdefaf5.

📒 Files selected for processing (3)
  • electron/browser/tabs/tab.ts (11 hunks)
  • electron/ipc/browser/tabs.ts (1 hunks)
  • shared/types/tabs.ts (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
electron/browser/tabs/tab.ts (1)
shared/types/tabs.ts (1)
  • NavigationEntry (3-6)

@iamEvanYT iamEvanYT merged commit cb678a2 into main Apr 18, 2025
1 check passed
@iamEvanYT iamEvanYT deleted the evan/sleep-tabs branch April 18, 2025 12:23
@coderabbitai coderabbitai bot mentioned this pull request May 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant