🔨 Use dependency injection for Platform to facilitate unit testing#2740
Merged
guiyanakuang merged 2 commits intomainfrom May 17, 2025
Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR refactors desktop modules to inject Platform via DI rather than calling getPlatform(), enabling easier unit testing.
- Added
Platformconstructor parameters and removed directgetPlatform()calls across desktop services and utilities - Updated Koin DI bindings to provide
Platformand wire it through factories - Introduced
PlatformProviderinterface and consolidatedPlatformdata class
Reviewed Changes
Copilot reviewed 50 out of 50 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| DesktopPasteboardService.kt | Inject Platform into factory and replace getPlatform() |
| DesktopShortcutKeysLoader.kt | Pass Platform to getDesktopKeyboardKeys |
| DesktopShortcutKeysListener.kt | Pass Platform to getDesktopKeyboardKeys |
| DesktopShortcutKeys.kt | Accept Platform and AppPathProvider in constructor |
| DesktopKeyboardKeys.kt | Change getDesktopKeyboardKeys() signature to take Platform |
| DesktopThumbnailLoader.kt | Inject Platform and remove getPlatform() |
| DesktopFileExtLoader.kt | Inject Platform and remove getPlatform() |
| DesktopSimpleConfigFactory.kt | Inject AppPathProvider |
| DesktopAppWindowManager.kt | Inject Platform and remove direct call |
| DesktopAppStartUpService.kt | Inject Platform and update platform checks |
| DesktopAppRestartService.kt | Convert from object to class with DI for Platform and AppPathProvider |
| DesktopAppLaunch.kt | Convert from object to class with DI for Platform and AppPathProvider |
| DesktopCrossPasteModule.kt | Provide Platform in DI graph and update bindings |
| CrossPaste.kt | Bootstrap Platform via DesktopPlatformProvider |
| MarketingSyncManager.kt | Import Platform.Companion.MACOS/WINDOWS |
| MarketingNearbyDeviceManager.kt | Import Platform.Companion.LINUX |
| PlatformProvider.kt | Add PlatformProvider interface |
| Platform.kt | Define serializable Platform data class |
| EndpointInfoFactory.kt | Inject Platform and remove getPlatform() |
| build.gradle.kts | Add kotlinx.coroutines.test dependency |
Comments suppressed due to low confidence (1)
app/src/desktopMain/kotlin/com/crosspaste/paste/DesktopPasteboardService.kt:21
- Add unit tests for each branch of getDesktopPasteboardService (macOS, Windows, Linux, fallback) to verify correct service is instantiated based on the injected Platform.
return if (platform.isMacos()) {
app/src/desktopMain/kotlin/com/crosspaste/paste/DesktopPasteboardService.kt
Outdated
Show resolved
Hide resolved
…ardService.kt Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.
close #2739