upgrade gradle & agp & kotlin & kotlinCompilerExtensionVersion & comp…#9
Open
CMingTseng wants to merge 2 commits intoOpenQuickJS:mainfrom
Open
upgrade gradle & agp & kotlin & kotlinCompilerExtensionVersion & comp…#9CMingTseng wants to merge 2 commits intoOpenQuickJS:mainfrom
CMingTseng wants to merge 2 commits intoOpenQuickJS:mainfrom
Conversation
…ervices
This commit introduces a major architectural refactor of the JavaScript integration, moving from a monolithic, hardcoded approach to a dynamic, modular, and scalable system for handling GATT services.
The previous implementation tightly coupled Kotlin classes (`HrmGattValue`, `BatteryGattValue`) with specific JS files and relied on fragile data access patterns (reading global variables directly). The new architecture addresses these limitations and establishes a robust foundation for future expansion.
### Key Architectural Changes:
1. **Dynamic & Modular JS with `gatt-core.js`:**
* A central `gatt-core.js` now provides a registration pattern (`registerGatt`).
* Individual service files (`hrm.js`, `battery.js`) are now self-contained modules that register themselves upon loading.
* This decouples the Android host from knowing which services exist, enabling true dynamic loading.
2. **Centralized Clock and Scheduler:**
* A new `clock.js` provides a shared sense of time for all JS modules.
* `MainActivity` now acts as a scheduler, driving the JS world by periodically calling `Clock.tick()` and the universal `next(uuid)` function for all registered modules. This aligns with QuickJS's passive execution model and removes the need for `setInterval` from within JS.
3. **On-Demand Script Loading:**
* The app now only loads core scripts (`clock.js`, `gatt-core.js`) on startup.
* Service-specific scripts (`hrm.js`, `battery.js`) are loaded dynamically when the user interacts with new UI buttons, demonstrating the system's extensibility.
4. **Robust Data Fetching ("Two-Step Method"):**
* A critical issue was discovered where `jsContext.evaluate()` returns `null` if the target JS function's definition contains a `console.log`, regardless of whether it's executed.
* This was solved by implementing a robust "two-step" data fetching pattern:
1. **Execute:** Use `evaluate()` to run the JS function and assign its result to a temporary global variable (e.g., `__temp_result = getValue(...)`).
2. **Read:** Use `globalObject.getProperty("__temp_result")` to safely read the value, bypassing the `evaluate()` return value issue.
5. **Integration of Legacy Abstractions:**
* The legacy `HrmGattValue` and `BatteryGattValue` classes were refactored.
* They no longer handle script loading and instead are initialized with a `JSContext`.
* Their internal logic was updated to use the new "two-step" data fetching method, proving the new JS backend can support various Kotlin-side consumer patterns.
### UI and Code Cleanup:
* The `MainScreen` UI was updated to include buttons for on-demand script loading.
* It now displays data fetched via two methods (direct access and through the legacy classes) for side-by-side comparison, validating the refactor.
* Redundant engine classes (`KJsEngine`, `JsEngine.java`) were removed, simplifying the architecture to a single `QuickJsEngine`.
This new architecture is significantly more maintainable, scalable, and decoupled. Adding a new GATT service is now as simple as adding a new JS file to the assets without needing to modify any Kotlin code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
upgrade gradle & agp & kotlin & compose bom & kotlin comipler Ext version