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

Add 80% battery charge limit for Legion Go #1074

Merged
merged 2 commits into from
Jun 4, 2024
Merged

Conversation

moyogii
Copy link
Contributor

@moyogii moyogii commented Jun 2, 2024

Adds 80% battery charge limit toggle for the Legion Go.

Initially, I was trying to do this through a function located in the SapientiaUSB.dll but I was unable to find anything of use. I did however find out through another project (LegionGoRemapper) that 0x03010001 handles the enabling or disabling of the 80% battery charge limit.

If there is an alternative way of doing this that makes more sense, please let me know!

image

Summary by CodeRabbit

  • New Features

    • Introduced a battery charge limit setting for Lenovo Legion devices, allowing users to cap battery charge at 80% to extend battery lifespan.
    • Added a toggle switch in the device settings page to enable or disable the battery charge limit feature.
  • UI Enhancements

    • Added a new section in the device settings page for managing the battery charge limit, including descriptive text and icons.
  • Acknowledgements

    • Added "PlasmidEve" to the list of contributors on the About page.

Copy link
Contributor

coderabbitai bot commented Jun 2, 2024

Walkthrough

The recent changes introduce a new feature to set a battery charge limit for Lenovo Legion devices within the HandheldCompanion application. This involves adding a new setting, UI components, and methods to handle the battery charge limit functionality. Additionally, a new name "PlasmidEve" was added to the AboutPage.

Changes

Files Change Summary
HandheldCompanion/App.config, HandheldCompanion/Properties/Settings.settings Added LegionBatteryChargeLimit setting with default False.
HandheldCompanion/Devices/Lenovo/LegionGo.cs Added methods SetBatteryChargeLimit, UpdateSettings, and event handler SettingsManager_SettingValueChanged.
HandheldCompanion/Properties/Resources.Designer.cs, HandheldCompanion/Properties/Resources.resx Added localized strings for battery charge limit settings.
HandheldCompanion/Properties/Settings.Designer.cs Added public boolean property LegionBatteryChargeLimit with getter and setter.
HandheldCompanion/Views/Pages/AboutPage.xaml Added "PlasmidEve" to the list of names.
HandheldCompanion/Views/Pages/DevicePage.xaml Added Border element for battery charge limit feature with child elements.
HandheldCompanion/Views/Pages/DevicePage.xaml.cs Added method Toggle_LegionBatteryChargeLimit_Toggled to handle toggle switch state.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant User
    participant DevicePage
    participant LegionGo
    participant SettingsManager

    User ->> DevicePage: Toggle Battery Charge Limit
    DevicePage ->> SettingsManager: Update Setting (LegionBatteryChargeLimit)
    SettingsManager ->> LegionGo: Notify Setting Changed
    LegionGo ->> LegionGo: UpdateSettings()
    LegionGo ->> LegionGo: SetBatteryChargeLimit(enabled)
Loading

Poem

In the land of code, a change took flight,
For Legion's charge, a limit set just right.
Eighty percent, the battery's goal,
To keep it healthy, to keep it whole.
With toggles and switches, the settings align,
HandheldCompanion, for a longer battery time.
And PlasmidEve joins the hall of fame,
In the AboutPage, forever in name. 🌟


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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9655ffd and ec81827.

Files selected for processing (9)
  • HandheldCompanion/App.config (1 hunks)
  • HandheldCompanion/Devices/Lenovo/LegionGo.cs (3 hunks)
  • HandheldCompanion/Properties/Resources.Designer.cs (1 hunks)
  • HandheldCompanion/Properties/Resources.resx (1 hunks)
  • HandheldCompanion/Properties/Settings.Designer.cs (1 hunks)
  • HandheldCompanion/Properties/Settings.settings (1 hunks)
  • HandheldCompanion/Views/Pages/AboutPage.xaml (1 hunks)
  • HandheldCompanion/Views/Pages/DevicePage.xaml (1 hunks)
  • HandheldCompanion/Views/Pages/DevicePage.xaml.cs (1 hunks)
Files skipped from review due to trivial changes (2)
  • HandheldCompanion/App.config
  • HandheldCompanion/Properties/Resources.resx
Additional comments not posted (9)
HandheldCompanion/Properties/Settings.settings (1)

275-277: The addition of the LegionBatteryChargeLimit setting is correctly implemented with the appropriate default value.

HandheldCompanion/Views/Pages/AboutPage.xaml (1)

196-196: The addition of "PlasmidEve" to the contributors list accurately reflects their contribution to the project.

HandheldCompanion/Devices/Lenovo/LegionGo.cs (2)

100-110: The implementation of the SetBatteryChargeLimit method correctly utilizes the CapabilityID.InstantBootAc to control the 80% battery charge limit. The reference to the LegionGoRemapper project provides a good context for this implementation.


446-459: The UpdateSettings method and the SettingsManager_SettingValueChanged event handler are correctly implemented to handle the new LegionBatteryChargeLimit setting. This ensures that the setting is dynamically applied based on user preferences.

HandheldCompanion/Views/Pages/DevicePage.xaml.cs (1)

508-514: Proper implementation of the battery charge limit toggle.

Verification successful

The integration of the LegionBatteryChargeLimit setting appears to be properly handled in the codebase. The setting is referenced in multiple relevant files, including Settings.Designer.cs, Resources.Designer.cs, and LegionGo.cs, indicating that it is correctly managed and utilized.

  • HandheldCompanion/Views/Pages/DevicePage.xaml.cs: The toggle method updates the setting.
  • HandheldCompanion/Properties/Settings.Designer.cs: The setting is defined and accessed.
  • HandheldCompanion/Properties/Resources.Designer.cs: The setting's resources are defined.
  • HandheldCompanion/Devices/Lenovo/LegionGo.cs: The setting is used to set the battery charge limit.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the integration of the `LegionBatteryChargeLimit` setting with the SettingsManager.

# Test: Search for the usage of `LegionBatteryChargeLimit` in the settings manager. Expect: Proper handling and updates.
rg --type csharp $'LegionBatteryChargeLimit' --exec cat {}

Length of output: 468



Script:

#!/bin/bash
# Description: Verify the integration of the `LegionBatteryChargeLimit` setting with the SettingsManager.

# Test: Search for the usage of `LegionBatteryChargeLimit` in the settings manager. Expect: Proper handling and updates.
rg --type csharp 'LegionBatteryChargeLimit'

Length of output: 1455

HandheldCompanion/Properties/Settings.Designer.cs (1)

1107-1120: Correct definition of the LegionBatteryChargeLimit setting.

HandheldCompanion/Views/Pages/DevicePage.xaml (1)

865-901: The implementation of the battery charge limit toggle in the UI appears correct and well-integrated within the existing structure.

HandheldCompanion/Properties/Resources.Designer.cs (2)

1072-1079: LGTM! The property for the battery charge limit label is well implemented.


1081-1088: LGTM! The property for the battery charge limit description is well implemented.

not needed, SettingsManager will iterate through all settings on startup anyway
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 ec81827 and 4ea9570.

Files selected for processing (1)
  • HandheldCompanion/Devices/Lenovo/LegionGo.cs (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • HandheldCompanion/Devices/Lenovo/LegionGo.cs

@Valkirie Valkirie merged commit 9022c50 into Valkirie:main Jun 4, 2024
1 check passed
@Valkirie
Copy link
Owner

Valkirie commented Jun 4, 2024

Good job, merged

CasperH2O pushed a commit to CasperH2O/HandheldCompanion that referenced this pull request Jun 21, 2024
* Add 80% battery charge limit for Legion Go

* removed UpdateSettings()

not needed, SettingsManager will iterate through all settings on startup anyway

---------

Co-authored-by: Lesueur Benjamin <[email protected]>
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.

2 participants