mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
feat(desktop): implement DI auto-wiring and validation (#4782)
Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
parent
8bb1e86511
commit
f45993ede2
11 changed files with 160 additions and 28 deletions
|
|
@ -76,7 +76,7 @@ When contributing to `core` modules, adhere to the following KMP standards:
|
|||
* **Resources:** Use Compose Multiplatform Resources (`core:resources`) for all strings and drawables. Never use Android `strings.xml` in `commonMain`.
|
||||
* **Coroutines & Flows:** Use `StateFlow` and `SharedFlow` for all asynchronous state management across the domain layer.
|
||||
* **Persistence:** Use `androidx.datastore` for preferences and Room KMP for complex relational data.
|
||||
* **Dependency Injection:** We use **Koin Annotations + KSP**. Per 2026 KMP industry standards, it is recommended to push Koin `@Module`, `@ComponentScan`, and `@KoinViewModel` annotations into `commonMain`. This encapsulates dependency graphs per feature, providing a Hilt-like experience (compile-time validation) while remaining fully multiplatform-compatible.
|
||||
* **Dependency Injection:** We use **Koin Annotations + K2 Compiler Plugin**. Per 2026 KMP industry standards, it is recommended to push Koin `@Module`, `@ComponentScan`, and `@KoinViewModel` annotations into `commonMain`. This encapsulates dependency graphs per feature, providing a Hilt-like experience (compile-time validation) while remaining fully multiplatform-compatible.
|
||||
|
||||
---
|
||||
*Document refreshed on 2026-03-10 as a historical companion to `docs/kmp-progress-review-2026.md`.*
|
||||
|
|
|
|||
|
|
@ -128,27 +128,15 @@ Vico chart screens (DeviceMetrics, EnvironmentMetrics, SignalMetrics, PowerMetri
|
|||
|
||||
## C. DI Improvements
|
||||
|
||||
### C1. Desktop manual ViewModel wiring
|
||||
### C1. ~~Desktop manual ViewModel wiring~~ *(resolved 2026-03-13)*
|
||||
|
||||
`DesktopKoinModule.kt` has ~120 lines of hand-written `viewModel { Constructor(get(), get(), ...) }` with 8–17 parameters each. These will drift from the annotation-generated Android wiring.
|
||||
`DesktopKoinModule.kt` originally had ~120 lines of hand-written `viewModel { ... }` blocks. These have been successfully replaced by including Koin modules from `commonMain` generated via the Koin K2 Compiler Plugin for automatic wiring.
|
||||
|
||||
**Fix:** Ensure `@KoinViewModel` annotations on shared ViewModels in `feature/*/commonMain` generate KSP modules for the JVM target. Desktop's `desktopModule()` should then `includes()` generated modules — zero manual ViewModel wiring.
|
||||
### C2. ~~Desktop stubs lack compile-time validation~~ *(resolved 2026-03-13)*
|
||||
|
||||
**Validation:** If KSP already processes JVM targets (check `meshtastic.koin` convention plugin), this may only need import wiring. If not, configure `ksp(libs.koin.annotations)` for the JVM source set.
|
||||
`desktopPlatformStubsModule()` previously had stubs that were only validated at runtime.
|
||||
|
||||
### C2. Desktop stubs lack compile-time validation
|
||||
|
||||
`desktopPlatformStubsModule()` has 12 `single<Interface> { Noop() }` bindings. Adding a new interface to `core:repository` won't cause a build failure — it fails at runtime.
|
||||
|
||||
**Fix:** Add `checkModules()` test:
|
||||
```kotlin
|
||||
@Test fun `all Koin bindings resolve`() {
|
||||
koinApplication {
|
||||
modules(desktopModule(), desktopPlatformModule())
|
||||
checkModules()
|
||||
}
|
||||
}
|
||||
```
|
||||
**Outcome:** Added `DesktopKoinTest.kt` using Koin's `verify()` API. This test validates the entire Desktop DI graph (including platform stubs and DataStores) during the build. Discovered and fixed missing stubs for `CompassHeadingProvider`, `PhoneLocationProvider`, and `MagneticFieldProvider`.
|
||||
|
||||
### C3. DI module naming convention
|
||||
|
||||
|
|
@ -187,10 +175,9 @@ Android uses `@Module`-annotated classes (`CoreDataModule`, `CoreBleAndroidModul
|
|||
- `core:ble` (connection state machine)
|
||||
- `core:ui` (utility functions)
|
||||
|
||||
### D4. Desktop has 5 tests
|
||||
### D4. Desktop has 6 tests
|
||||
|
||||
`desktop/src/test/` contains `DemoScenarioTest.kt` with 5 test cases. Still needs:
|
||||
- Koin module validation (`checkModules()`)
|
||||
`desktop/src/test/` contains `DemoScenarioTest.kt` and `DesktopKoinTest.kt`. Still needs:
|
||||
- `DesktopRadioInterfaceService` connection state tests
|
||||
- Navigation graph coverage
|
||||
|
||||
|
|
@ -208,7 +195,7 @@ Ordered by impact × effort:
|
|||
| 4 | Feature `commonTest` (D1) | Medium | Medium | KMP test coverage |
|
||||
| 5 | `feature:connections` (A3) | High | Medium | ~~Desktop connections~~ ✅ Done |
|
||||
| 6 | Service/worker extraction from `app` (A1) | Medium | Medium | Thin app module |
|
||||
| 7 | Desktop Koin auto-wiring (C1) | Medium | Low | DI parity |
|
||||
| 7 | ~~Desktop Koin auto-wiring (C1, C2)~~ | Medium | Low | ✅ Resolved 2026-03-13 |
|
||||
| 8 | MQTT KMP (B3) | Medium | High | Desktop/iOS MQTT |
|
||||
| 9 | KMP charts (B4) | Medium | High | Desktop metrics |
|
||||
| 10 | iOS target declaration | High | Low | CI purity gate |
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@ These items address structural gaps identified in the March 2026 architecture re
|
|||
| Replace `ConcurrentHashMap` in `commonMain` (3 files) | High | Low | ✅ |
|
||||
| Create `core:testing` shared test fixtures | Medium | Low | ✅ |
|
||||
| Add feature module `commonTest` (settings, node, messaging) | Medium | Medium | ✅ |
|
||||
| Desktop Koin `checkModules()` integration test | Medium | Low | ❌ |
|
||||
| Auto-wire Desktop ViewModels via KSP (eliminate manual wiring) | Medium | Low | ❌ |
|
||||
| Desktop Koin `checkModules()` integration test | Medium | Low | ✅ |
|
||||
| Auto-wire Desktop ViewModels via K2 Compiler (eliminate manual wiring) | Medium | Low | ✅ |
|
||||
|
||||
## Active Work
|
||||
|
||||
|
|
@ -86,7 +86,7 @@ These items address structural gaps identified in the March 2026 architecture re
|
|||
1. **App module thinning** — 63 files remaining (down from 90). Extracted ChannelViewModel, NodeMapViewModel, NodeContextMenu, EmptyDetailPlaceholder to shared modules. Remaining: extract service/worker/radio files from `app` to `core:service/androidMain` and `core:network/androidMain`
|
||||
2. **Serial/USB transport** — direct radio connection on Desktop via jSerialComm
|
||||
3. **MQTT transport** — cloud relay operation (KMP, benefits all targets)
|
||||
4. **Desktop ViewModel auto-wiring** — ensure Koin KSP generates ViewModel modules for JVM target; eliminate manual wiring in `DesktopKoinModule`
|
||||
4. **Desktop ViewModel auto-wiring** — ✅ Done: ensured Koin K2 Compiler Plugin generates ViewModel modules for JVM target; eliminated manual wiring in `DesktopKoinModule`
|
||||
5. **KMP charting** — ✅ Done: Vico charts migrated to `feature:node/commonMain` using KMP artifacts; desktop wires them directly
|
||||
6. **Navigation contract extraction** — ✅ Done: shared `TopLevelDestination` enum in `core:navigation`; icon mapping in `core:ui`; parity tests in place. Both shells derive from the same source of truth.
|
||||
7. **Dependency stabilization** — track stable releases for CMP, Koin, Lifecycle, Nav3
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue