-
Notifications
You must be signed in to change notification settings - Fork 9.2k
feat: Implement Ctrl+C double-press delay for exit #12766
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
base: main
Are you sure you want to change the base?
Conversation
Introduces a configurable delay for the Ctrl+C exit mechanism to prevent accidental application termination due to rapid, unintended double-presses. - Adds to define the minimum time between two Ctrl+C presses for a deliberate exit. - Modifies the hook in to check this interval before triggering a quit. - Updates with new tests to verify the delay logic and removes an obsolete test case.
Adds `vi.resetAllMocks()` and `vi.restoreAllMocks()` to the test setup for `AppContainer.test.tsx`. This ensures the tests are run in a clean environment, resolving intermittent failures that occurred when run as part of the full `preflight` suite.
Summary of ChangesHello @medic-code, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the application's exit mechanism by introducing a configurable delay for the Ctrl+C double-press action. The change aims to improve user experience and prevent unintentional application shutdowns that could occur due to rapid or accidental key presses. By requiring a minimum time interval between successive Ctrl+C signals, the system ensures that only deliberate attempts to quit the application are successful, making the overall behavior more robust and predictable. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request introduces a delay to the Ctrl+C exit mechanism to prevent accidental termination, which is a great improvement for the user experience. The implementation is logical and the accompanying tests correctly verify the new timing behavior. I have one suggestion to enhance the robustness of the timing logic by using a monotonic clock, which will make the feature more resilient to system time changes.
| clearTimeout(ctrlCTimerRef.current); | ||
| ctrlCTimerRef.current = null; | ||
| } | ||
| const now = Date.now(); |
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.
Date.now() is not guaranteed to be monotonic, meaning it can go backwards or jump if the system clock is adjusted. This could lead to unpredictable behavior in the double-press logic, such as preventing an exit even with a correct delay or causing an exit unexpectedly. For time interval measurements, it's safer to use a monotonic clock like performance.now() from Node's perf_hooks module. This ensures that time measurements always move forward, making the exit logic more robust.
You will need to add import { performance } from 'node:perf_hooks'; at the top of the file.
| const now = Date.now(); | |
| const now = performance.now(); |
TLDR
This PR introduces a configurable delay to the
Ctrl+Cexit mechanism. This prevents the application from accidentally terminating due to rapid, unintended double-presses or lag that interprets a single Ctrl + c as a double press, making the exit behaviour more robust and improving the user experience.Dive Deeper
The root cause of the issue is that rapid, successive
Ctrl+Cpresses can be registered as a valid double-press, causing an immediate and sometimes unintentional shutdown. This can be frustrating for users who did not intend to exit the application.This change modifies the core process exit hook to check the time interval between two
Ctrl+Csignals. A new constant is introduced to define this minimum delay, ensuring that only deliberate double-presses trigger an exit. The implementation also includes updated tests to verify the new timing logic.Specific code changes
MIN_CTRL_C_INTERVAL_MSto define the minimum time (400ms) between two Ctrl+C presses for a deliberate exit.AppContainer.tsxto check this interval before triggering a quit.AppContainer.test.tsxwith new tests to verify the delay logic and removes an obsolete test case.Reviewer Test Plan
Verify all checks pass:
Test the delay logic:
Ctrl+Conce. The "press again to exit" message should appear.Ctrl+Cagain (faster than the configured delay). The application should not exit.Ctrl+Conce, wait a moment (longer than the delay), and pressCtrl+Cagain. The application should exit as expected.Testing Matrix
Related Issues
Fixes #12421
Pre-Merge Checklist
npm run preflightwithout errors