-
Notifications
You must be signed in to change notification settings - Fork 40
Tab auto sleep feature #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThis update introduces a new "Sleep Tab After" setting, allowing users to specify when inactive tabs should be put to sleep. The Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant TabManager
participant Settings
participant Tab
loop Every 10 seconds
TabManager->Tab: Check visibility and state
TabManager->Settings: Get "sleepTabAfter" setting
TabManager->Tab: Get lastActiveAt
TabManager->Tab: shouldSleepTab(lastActiveAt)
alt Tab should sleep
TabManager->Tab: putToSleep()
end
TabManager->Tab: shouldArchiveTab(lastActiveAt)
alt Tab should archive
TabManager->Tab: destroy()
end
end
Poem
Note ⚡️ AI Code Reviews for VS Code, Cursor, WindsurfCodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback. Note ⚡️ Faster reviews with cachingCodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (2)
✨ 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/main/saving/tabs.ts (1)
64-73: Well-implemented shouldSleepTab function with proper error handling.The
shouldSleepTabfunction follows the same structure as the existingshouldArchiveTabfunction, which is good for consistency. The function:
- Retrieves the user's preference for the sleep tab timeout
- Maps it to seconds using the
SleepTabValueMap- Includes proper error handling (returning false if the mapping is invalid)
- Calculates the elapsed time since last activity
- Returns a boolean indicating whether the tab should be put to sleep
One suggestion: Consider adding a JSDoc comment to describe the function's purpose and parameters, similar to documentation elsewhere in the codebase.
+/** + * Determines if a tab should be put to sleep based on its last active time + * and the user's sleep tab preference. + * + * @param lastActiveAt Unix timestamp in seconds of when the tab was last active + * @returns Boolean indicating whether the tab should be put to sleep + */ export function shouldSleepTab(lastActiveAt: number) { const sleepTabAfter = getSettingValueById("sleepTabAfter"); const sleepTabAfterSeconds = SleepTabValueMap[sleepTabAfter as keyof typeof SleepTabValueMap];
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting
📒 Files selected for processing (3)
src/main/browser/tabs/tab-manager.ts(2 hunks)src/main/modules/basic-settings.ts(3 hunks)src/main/saving/tabs.ts(2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/main/browser/tabs/tab-manager.ts (1)
src/main/saving/tabs.ts (1)
shouldSleepTab(64-73)
src/main/saving/tabs.ts (2)
src/main/saving/settings.ts (1)
getSettingValueById(54-56)src/main/modules/basic-settings.ts (1)
SleepTabValueMap(22-33)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: build (ubuntu-latest)
- GitHub Check: build (windows-latest)
- GitHub Check: build (macos-latest)
🔇 Additional comments (6)
src/main/modules/basic-settings.ts (3)
18-33: Well-structured implementation of Sleep Tab Value Map.The new
SleepTabValueMapobject is implemented correctly and follows the same pattern as the existingArchiveTabValueMap. It provides a comprehensive range of time intervals from 5 minutes to 24 hours, giving users flexible options for tab sleeping behavior.
160-209: Clear and consistent implementation of the sleep tab settings.The implementation of the
sleepTabAftersetting follows the same structure as other settings in the file. The default value of "never" is a good choice as it ensures users have to explicitly opt-in to the automatic sleep functionality.
257-262: Good integration of Sleep Tab settings card.The settings card for "Sleep Tab After" is properly implemented and follows the same pattern as the existing "Archive Tab After" card. The subtitle clearly explains the purpose of this setting.
src/main/browser/tabs/tab-manager.ts (2)
9-9: Import updated to include the new function.The import statement has been updated to include the new
shouldSleepTabfunction alongside the existingshouldArchiveTabfunction.
86-88: Effective implementation of tab sleep functionality.The tab sleep functionality is well integrated into the existing periodic tab lifecycle management. The conditions for sleeping a tab are clearly defined:
- The tab must not be visible
- The tab must not already be asleep
- The tab must meet the time-based criteria defined in
shouldSleepTabThis implementation follows the same pattern as the existing archive logic, ensuring consistency in behavior.
src/main/saving/tabs.ts (1)
5-5: Import properly updated to include SleepTabValueMap.The import statement has been updated to include the new
SleepTabValueMapalongside the existingArchiveTabValueMap.
Summary by CodeRabbit
New Features
Settings