-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔨 Refactor code to prepare for subsequent feature development (#13)
- Loading branch information
1 parent
f53981b
commit 18dd599
Showing
13 changed files
with
136 additions
and
131 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package com.clipevery | ||
|
||
data class AppConfig(val bindingState: Boolean = false) |
75 changes: 38 additions & 37 deletions
75
composeApp/src/commonMain/kotlin/com/clipevery/ClipeveryApp.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,56 @@ | ||
package com.clipevery | ||
|
||
import androidx.compose.animation.AnimatedVisibility | ||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.material.Button | ||
import androidx.compose.material.MaterialTheme | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.MutableState | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.CompositionLocalProvider | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.toComposeImageBitmap | ||
import com.clipevery.clip.AbstractClipboard | ||
import org.jetbrains.compose.resources.ExperimentalResourceApi | ||
import java.awt.image.BufferedImage | ||
|
||
@OptIn(ExperimentalResourceApi::class) | ||
@Composable | ||
fun ClipeveryApp(clipboard: AbstractClipboard, copyText: MutableState<String>, generateQRCode: BufferedImage) { | ||
fun ClipeveryApp(dependencies: Dependencies) { | ||
MaterialTheme { | ||
val pid: Long = ProcessHandle.current().pid() | ||
var showImage by remember { mutableStateOf(false) } | ||
var start by remember { mutableStateOf(true) } | ||
Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) { | ||
Button(onClick = { | ||
showImage = !showImage | ||
}) { | ||
Text(copyText.value) | ||
} | ||
Button(onClick = { | ||
if (start) { | ||
clipboard.stop() | ||
} else { | ||
clipboard.start() | ||
} | ||
start = !start | ||
}) { | ||
Text(start.toString() + " " + pid) | ||
} | ||
AnimatedVisibility(showImage) { | ||
Image( | ||
generateQRCode.toComposeImageBitmap(), | ||
// painterResource("compose-multiplatform.xml"), | ||
null | ||
) | ||
} | ||
ClipeveryCommon(dependencies) | ||
} | ||
} | ||
} | ||
|
||
|
||
@Composable | ||
fun ClipeveryCommon(dependencies: Dependencies) { | ||
CompositionLocalProvider( | ||
LocalClipeveryServer provides dependencies.clipServer, | ||
LocalConfigManager provides dependencies.configManager | ||
) { | ||
ClipeveryWithProvidedDependencies() | ||
} | ||
} | ||
|
||
@Composable | ||
fun ClipeveryWithProvidedDependencies() { | ||
val configManager = LocalConfigManager.current | ||
|
||
val config = remember { mutableStateOf(configManager.config) } | ||
|
||
if (!config.value.bindingState) { | ||
bindingQRCode() | ||
} else { | ||
mainUI() | ||
} | ||
} | ||
|
||
|
||
@Composable | ||
fun bindingQRCode() { | ||
Text("bindingQRCode") | ||
} | ||
|
||
@Composable | ||
fun mainUI() { | ||
Text("mainUI") | ||
} |
22 changes: 22 additions & 0 deletions
22
composeApp/src/commonMain/kotlin/com/clipevery/Dependencies.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.clipevery | ||
|
||
import androidx.compose.runtime.staticCompositionLocalOf | ||
import com.clipevery.net.ClipServer | ||
import com.clipevery.net.ConfigManager | ||
|
||
abstract class Dependencies { | ||
abstract val clipServer: ClipServer | ||
abstract val configManager: ConfigManager | ||
} | ||
|
||
internal val LocalClipeveryServer = staticCompositionLocalOf<ClipServer> { | ||
noLocalProvidedFor("ClipeveryServer") | ||
} | ||
|
||
internal val LocalConfigManager = staticCompositionLocalOf<ConfigManager> { | ||
noLocalProvidedFor("ConfigManager") | ||
} | ||
|
||
private fun noLocalProvidedFor(name: String): Nothing { | ||
error("CompositionLocal $name not present") | ||
} |
12 changes: 0 additions & 12 deletions
12
composeApp/src/commonMain/kotlin/com/clipevery/clip/ClipboardEvent.kt
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
composeApp/src/commonMain/kotlin/com/clipevery/clip/ClipboardListener.kt
This file was deleted.
Oops, something went wrong.
This file contains 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
10 changes: 10 additions & 0 deletions
10
composeApp/src/commonMain/kotlin/com/clipevery/net/ClipServer.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.clipevery.net | ||
|
||
import com.clipevery.AppConfig | ||
|
||
interface ClipServer { | ||
} | ||
|
||
interface ConfigManager { | ||
val config: AppConfig | ||
} |
5 changes: 5 additions & 0 deletions
5
composeApp/src/commonMain/kotlin/com/clipevery/utils/PlatformUtils.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.clipevery.utils | ||
|
||
import kotlinx.coroutines.CoroutineDispatcher | ||
|
||
expect val ioDispatcher: CoroutineDispatcher |
24 changes: 14 additions & 10 deletions
24
composeApp/src/desktopMain/kotlin/com/clipevery/PlatformClipboard.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,23 @@ | ||
package com.clipevery | ||
|
||
import com.clipevery.clip.AbstractClipboard | ||
import com.clipevery.macos.MacosClipboard | ||
import com.clipevery.clip.ClipboardService | ||
import com.clipevery.macos.MacosClipboardService | ||
import com.clipevery.platform.currentPlatform | ||
import com.clipevery.windows.WindowsClipboard | ||
import com.clipevery.windows.WindowsClipboardService | ||
import java.awt.datatransfer.Transferable | ||
import java.util.function.Consumer | ||
|
||
fun getClipboard(clipConsumer: Consumer<Transferable>): AbstractClipboard { | ||
fun getClipboard(clipConsumer: Consumer<Transferable>): ClipboardService { | ||
val platform = currentPlatform() | ||
return if (platform.name == "Macos") { | ||
MacosClipboard(clipConsumer) | ||
} else if (platform.name == "Windows") { | ||
WindowsClipboard(clipConsumer) | ||
} else { | ||
throw Exception("Unknown platform: ${platform.name}") | ||
return when (platform.name) { | ||
"Macos" -> { | ||
MacosClipboardService(clipConsumer) | ||
} | ||
"Windows" -> { | ||
WindowsClipboardService(clipConsumer) | ||
} | ||
else -> { | ||
throw Exception("Unknown platform: ${platform.name}") | ||
} | ||
} | ||
} |
This file contains 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
6 changes: 6 additions & 0 deletions
6
composeApp/src/desktopMain/kotlin/com/clipevery/utils/PlatformUtils.desktop.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.clipevery.utils | ||
|
||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.Dispatchers | ||
|
||
actual val ioDispatcher: CoroutineDispatcher = Dispatchers.IO |
This file contains 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
This file contains 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