Skip to content
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

feat: keep the computer awake while knitting #698 #699

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mathPi
Copy link
Contributor

@mathPi mathPi commented Aug 19, 2024

Summary by CodeRabbit

  • New Features

    • The interface now keeps the screen awake during knitting operations, enhancing user experience.
  • Dependencies

    • Added a new dependency, wakepy==0.9.1, to improve functionality related to managing the application's operational state.
  • Improvements

    • Enhanced control flow for operations, ensuring the application remains responsive even during failures.
  • Preferences

    • Introduced a new user preference, "keep_awake," allowing users to manage system behavior related to screen timeout.

Copy link
Contributor

coderabbitai bot commented Aug 19, 2024

Walkthrough

The recent updates enhance user experience by implementing a feature that keeps the screen awake during knitting operations in the GUI, utilizing the wakepy library. This change improves operational flow and responsiveness while preserving existing functionalities related to device communication and logging.

Changes

File Change Summary
CHANGELOG.md Added a new feature to keep the screen awake during knitting operations (issue #698).
requirements.build.txt Introduced wakepy==0.9.1 as a new dependency for managing wake timers.
src/main/python/main/ayab/engine/engine.py Integrated wakepy to manage application behavior during operations, enhancing control flow and responsiveness.
src/main/python/main/ayab/preferences.py Added a new preference key "keep_awake" to manage user settings related to screen behavior.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant GUI
    participant Engine
    participant Device

    User->>GUI: Initiate knitting operation
    GUI->>Engine: Start operation
    Engine->>wakepy: Keep screen awake
    Engine->>Device: Communicate with device
    Device-->>Engine: Return status
    Engine->>GUI: Update status
    GUI-->>User: Display feedback
    Engine->>wakepy: Release screen control on completion
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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
Member

@X-sam X-sam left a comment

Choose a reason for hiding this comment

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

We should put this behind a setting, so users can turn it off.

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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a03774e and a9be629.

Files selected for processing (3)
  • CHANGELOG.md (1 hunks)
  • requirements.build.txt (1 hunks)
  • src/main/python/main/ayab/engine/engine.py (2 hunks)
Additional comments not posted (5)
requirements.build.txt (1)

12-12: Dependency Added: Verify Compatibility

The addition of wakepy==0.9.1 seems appropriate for managing wake timers. Ensure compatibility with existing dependencies and the project's environment.

src/main/python/main/ayab/engine/engine.py (3)

170-183: Integration of wakepy: Proper Use of Context Manager

The use of with keep.presenting(on_fail="pass") ensures that the screen stays awake during the operation. This is a good practice for long-running tasks. Verify that the on_fail parameter is set appropriately for your use case.


28-28: Import Added: Ensure Proper Usage

The wakepy library is imported. Ensure that it is used correctly and that any potential exceptions it might raise are handled properly.


185-201: Ensure Proper Logging and Notifications

The logging and notification logic is well-structured. Ensure that all possible states and exceptions are covered, especially when handling cancellations and completions.

CHANGELOG.md (1)

43-43: Changelog Updated: Ensure Consistency

The changelog entry for keeping the screen awake during knitting is clear and informative. Ensure that it is consistent with the actual implementation and follows the project's formatting conventions.

@mathPi
Copy link
Contributor Author

mathPi commented Aug 19, 2024

We should put this behind a setting, so users can turn it off.

Ok, I´ll try to add it. In the preference menu ?

Copy link

@mathPi
Copy link
Contributor Author

mathPi commented Aug 19, 2024

I added the option in the preferences. It tested manually, it is working. I think I´ll need to add a translation for the message ?

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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a9be629 and d5f60f1.

Files selected for processing (2)
  • src/main/python/main/ayab/engine/engine.py (3 hunks)
  • src/main/python/main/ayab/preferences.py (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/main/python/main/ayab/engine/engine.py
Additional comments not posted (3)
src/main/python/main/ayab/preferences.py (3)

70-70: LGTM!

The addition of "keep_awake" to PreferencesDictBoolKeys is consistent with the existing pattern.


94-94: LGTM!

The addition of "keep_awake": type[bool] to PreferencesDict is correctly implemented.


125-125: LGTM!

The addition of "keep_awake": bool to the variables dictionary in the Preferences class is appropriate and ensures proper management of the new preference.

@mathPi mathPi requested a review from X-sam August 25, 2024 09:21
@jonathanperret
Copy link
Contributor

We should put this behind a setting, so users can turn it off.

Are we sure about this needing to be a setting? Who actually wants their computer to go to sleep while knitting?

Personally I'd rather not have the UI cluttered with a toggle no-one is reasonably going to use. Also, it makes the code uglier because the context manager can't be used anymore.

On another note, we just froze features for 1.0.0 so @mathPi your contribution may have to wait until the real release is out before it is integrated. Hopefully that won't be too long 🤞

Comment on lines +171 to +178
keep_mode = None
if self.preferences.value("keep_awake"):
self.__logger.debug("Keeping screen awake activated")
# Activate the keep mode only if the preference is activated
keep_mode = keep.presenting(on_fail="pass")
keep_mode.__enter__()

try:
Copy link
Contributor

Choose a reason for hiding this comment

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

I still think it shouldn't be a preference, but if it has to be one, at least it can be made a bit more palatable with nullcontext that is designed for such cases:

Suggested change
keep_mode = None
if self.preferences.value("keep_awake"):
self.__logger.debug("Keeping screen awake activated")
# Activate the keep mode only if the preference is activated
keep_mode = keep.presenting(on_fail="pass")
keep_mode.__enter__()
try:
from contextlib import nullcontext # at the top
with keep.presenting(on_fail="pass") if self.preferences.value("keep_awake") else nullcontext():

Then you can get rid of the try…finally block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If it is okay for others, I'd prefer removing the settings ...
But if not yes that's a nicer solution.

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.

3 participants