Skip to content

🔨 Use dependency injection for Platform to facilitate unit testing#2740

Merged
guiyanakuang merged 2 commits intomainfrom
2739-use-dependency-injection-for-platform-to-facilitate-unit-testing
May 17, 2025
Merged

🔨 Use dependency injection for Platform to facilitate unit testing#2740
guiyanakuang merged 2 commits intomainfrom
2739-use-dependency-injection-for-platform-to-facilitate-unit-testing

Conversation

@guiyanakuang
Copy link
Copy Markdown
Member

close #2739

@guiyanakuang guiyanakuang added this to the CrossPaste 1.2.0 milestone May 17, 2025
@guiyanakuang guiyanakuang self-assigned this May 17, 2025
@guiyanakuang guiyanakuang requested a review from Copilot May 17, 2025 10:08
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors desktop modules to inject Platform via DI rather than calling getPlatform(), enabling easier unit testing.

  • Added Platform constructor parameters and removed direct getPlatform() calls across desktop services and utilities
  • Updated Koin DI bindings to provide Platform and wire it through factories
  • Introduced PlatformProvider interface and consolidated Platform data 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()) {

…ardService.kt

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@guiyanakuang guiyanakuang merged commit 9e7c448 into main May 17, 2025
2 checks passed
@guiyanakuang guiyanakuang deleted the 2739-use-dependency-injection-for-platform-to-facilitate-unit-testing branch July 12, 2025 12:27
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.

Use dependency injection for Platform to facilitate unit testing

2 participants