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

Update ControllerManager.cs #872

Merged
merged 1 commit into from
Dec 11, 2023
Merged

Update ControllerManager.cs #872

merged 1 commit into from
Dec 11, 2023

Conversation

Valkirie
Copy link
Owner

@Valkirie Valkirie commented Dec 11, 2023

Summary by CodeRabbit

  • Refactor
    • Improved the initialization process of the controller manager to be asynchronous, enhancing the app's startup performance.
  • Bug Fixes
    • Refined device connection handling to ensure more reliable recognition and configuration of connected devices.

@Valkirie Valkirie merged commit 2b48336 into main Dec 11, 2023
Copy link
Contributor

coderabbitai bot commented Dec 11, 2023

Walkthrough

The update involves modifying the Start method in the ControllerManager class to return a Task, indicating a shift towards an asynchronous pattern. Additionally, the HidDeviceArrived method has been refactored, with changes to how joyShockId and settings are managed, suggesting improvements in device connection handling.

Changes

File Path Change Summary
.../Managers/ControllerManager.cs Start method now returns Task; refactored HidDeviceArrived method.

🐇✨
In the code where rabbits hop,
Start now awaits atop.
With joyShockId in its burrow,
The HidDevice follows, narrow. 🎮🔧

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 X ?


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

@Valkirie Valkirie deleted the ControllerHotfix branch December 11, 2023 14:04
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.

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between aad9748 and babdc22.
Files selected for processing (1)
  • HandheldCompanion/Managers/ControllerManager.cs (5 hunks)
Additional comments: 3
HandheldCompanion/Managers/ControllerManager.cs (3)
  • 59-62: The Start method has been updated to return a Task. Ensure that all invocations of Start are updated to handle the new return type, especially if they are awaited.

  • 371-386: The block of code that sets settings.playerNumber and joyShockType is only executed if joyShockId is not -1. This is a good use of a guard clause to prevent further execution if no JoyShock device is found. However, ensure that there is appropriate handling or logging if no device is found (joyShockId remains -1).

  • 388-407: The creation of controller instances based on joyShockType is done within the UI thread using Application.Current.Dispatcher.Invoke. This is a good practice as it ensures that UI-related operations are performed on the UI thread. However, ensure that the controller variable is correctly updated and accessible outside the dispatcher invoke block.

Comment on lines 332 to 336
int connectedJoys = -1;
int joyShockId = -1;
JOY_SETTINGS settings = new();

DateTime timeout = DateTime.Now.Add(TimeSpan.FromSeconds(4));
Copy link
Contributor

Choose a reason for hiding this comment

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

Initialization of connectedJoys to -1 and the subsequent loop to connect devices may result in an infinite loop if JslConnectDevices() throws an exception that is not caught. Ensure that exceptions are handled properly to avoid an infinite loop.

Comment on lines 347 to 358
}
}

if (connectedJoys >= 0)
if (connectedJoys > 0)
{
int[] joysHandle = new int[connectedJoys];
JslGetConnectedDeviceHandles(joysHandle, connectedJoys);

// scroll handles until we find matching device path
int joyShockId = -1;
JOY_SETTINGS settings = new();

foreach (int i in joysHandle)
{
settings = JslGetControllerInfoAndSettings(i);
Copy link
Contributor

Choose a reason for hiding this comment

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

Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [350-369]

The check if (connectedJoys > 0) ensures that the following logic is only executed if there are connected devices. However, there is no else block to handle the case when there are no connected devices. Consider adding logic to handle this case appropriately.

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