EvilMindDevs / hms-unity-plugin

The HMS Unity Plugin makes it easy to include Huawei Mobile Services into Unity-based games. Authentication, in-app purchases, push alerts, ads, and interaction with gaming services are just a few of the basic capabilities that this formidable tool makes available to your applications.
https://evilminddevs.gitbook.io/hms-unity-plugin/
311 stars 43 forks source link

Built HMSExceptionHandler structure for catch error and redirect FAQ Links #457

Closed Andronovo-bit closed 9 months ago

Andronovo-bit commented 9 months ago

Pull Request: Exception Handling and Manager Refactoring for HMS kit

Summary of Changes

1. HMSManager Handling and Exception Handler

We've created a global exception handler, HMSException, and a common start operation, HMSManagerStart, for all HMSManagers. This establishes a consistent exception handling protocol across the application and mitigates any potential risks associated with differing exception handling strategies.

Along with this, we've slightly edited the HMSSingleton, replacing the IF check for class instance with the Lazy<T> structure. This approach offers a more robust and efficient means of implementing the singleton pattern.

2. Update to HMS kit Managers and Code Refinement

In line with our new common start operation, we updated all 17 HMS kit managers to adhere to this standard. The managers are now more consistent, making them easier to maintain and upgrade in the future.

Moreover, we have added common tags to some managers, which will facilitate better categorization and make the code easier to navigate and understand.

During this update, we also took the opportunity to fix some spelling mistakes in the RemoteConfigDemo file. These changes don't impact functionality, but they do contribute to overall code quality and clarity.

3. Exception Handling Improvements and Fixes

We have made significant enhancement to our HMSExceptionHandler, by standardizing exception names with the new ExceptionName Enum and adding an ExceptionLog inner class to match exceptions and urls. The latter feature enables better tracking and management of exceptions, making debugging a more straightforward process.

In terms of technical improvement, we've also moved towards using Application.logMessageReceivedThreaded over the traditional approach to ensure exception handling operations are properly multi-threaded. Furthermore, to accommodate compatibility with c#8 and earlier versions, we've replaced the Contains function with IndexOf combined with comparisonType.

The Log Listener was not triggering automatically as intended, so we've added new methods for listeners' log to make sure it operates as expected.

To make the code more maintainable and legible, we've included several helper methods. These will increase our codebase's readability and decrease the time it takes for new developers to understand the system.