refactor: split up core into multiple modules
This commit is contained in:
parent
2725342c3f
commit
0d84411f14
38 changed files with 344 additions and 149 deletions
|
|
@ -31,6 +31,7 @@ kotlin {
|
|||
implementation(libs.ktor.client.okhttp)
|
||||
}
|
||||
commonMain.dependencies {
|
||||
implementation(project(":common"))
|
||||
implementation(project(":core"))
|
||||
implementation(libs.compose.components.resources)
|
||||
implementation(libs.compose.foundation)
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ import com.hcaptcha.sdk.HCaptchaVerifyParams
|
|||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.launch
|
||||
import moe.lava.neon.core.api.ApiClient
|
||||
import moe.lava.neon.core.api.captcha.CaptchaResponse
|
||||
import moe.lava.neon.common.captcha.CaptchaRequest
|
||||
import moe.lava.neon.common.captcha.CaptchaResponse
|
||||
|
||||
private val logger = Logger.withTag("neon.ui.app/captcha")
|
||||
|
||||
|
|
@ -31,7 +31,7 @@ private const val EXTRA_RESULT_TOKEN = "extra_result_token"
|
|||
private const val EXTRA_RESULT_ERROR = "extra_result_error"
|
||||
|
||||
@Composable
|
||||
actual fun CaptchaBinder(api: ApiClient) {
|
||||
actual fun getCaptchaHandler(): suspend (CaptchaRequest) -> CaptchaResponse {
|
||||
val context = LocalContext.current
|
||||
val queue = MutableSharedFlow<Pair<String, CaptchaResponse>>()
|
||||
val scope = rememberCoroutineScope()
|
||||
|
|
@ -67,7 +67,7 @@ actual fun CaptchaBinder(api: ApiClient) {
|
|||
}
|
||||
}
|
||||
|
||||
api.setCaptchaHandler { captcha ->
|
||||
return { captcha ->
|
||||
val intent = Intent(context, HCaptchaActivity::class.java).apply {
|
||||
putExtra(EXTRA_SITE_KEY, captcha.captchaSitekey)
|
||||
putExtra(EXTRA_RQ_DATA, captcha.captchaRqdata)
|
||||
|
|
@ -17,6 +17,7 @@ import kotlinx.serialization.Serializable
|
|||
import kotlinx.serialization.modules.SerializersModule
|
||||
import kotlinx.serialization.modules.polymorphic
|
||||
import moe.lava.neon.core.repository.AuthRepository
|
||||
import moe.lava.neon.core.repository.CaptchaRepository
|
||||
import moe.lava.neon.ui.screens.Login
|
||||
import moe.lava.neon.ui.screens.Sample
|
||||
import moe.lava.neon.ui.screens.chat.Chat
|
||||
|
|
@ -67,12 +68,15 @@ fun App() {
|
|||
}
|
||||
|
||||
val auth: AuthRepository = koinInject()
|
||||
CaptchaBinder(koinInject())
|
||||
val captcha: CaptchaRepository = koinInject()
|
||||
captcha.setHandler(getCaptchaHandler())
|
||||
|
||||
MaterialExpressiveTheme(
|
||||
colorScheme = getColorScheme(),
|
||||
motionScheme = MotionScheme.expressive(),
|
||||
) {
|
||||
val init = if (auth.token != null) Route.Sample else Route.Login
|
||||
val init = if (auth.loggedIn) Route.Sample else Route.Login
|
||||
// val backStack = rememberNavBackStack(config, init)
|
||||
val backStack = rememberNavBackStack(config, Route.Sample)
|
||||
val threePaneStrategy = rememberThreePaneSceneStrategy<NavKey>()
|
||||
NavDisplay(
|
||||
|
|
|
|||
|
|
@ -1,7 +0,0 @@
|
|||
package moe.lava.neon.ui
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import moe.lava.neon.core.api.ApiClient
|
||||
|
||||
@Composable
|
||||
expect fun CaptchaBinder(api: ApiClient)
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
package moe.lava.neon.ui
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import moe.lava.neon.common.captcha.CaptchaRequest
|
||||
import moe.lava.neon.common.captcha.CaptchaResponse
|
||||
|
||||
@Composable
|
||||
expect fun getCaptchaHandler(): suspend (CaptchaRequest) -> CaptchaResponse
|
||||
|
|
@ -21,8 +21,8 @@ import androidx.lifecycle.ViewModel
|
|||
import androidx.lifecycle.viewModelScope
|
||||
import co.touchlab.kermit.Logger
|
||||
import kotlinx.coroutines.launch
|
||||
import moe.lava.neon.core.api.gateway.GatewayHandler
|
||||
import moe.lava.neon.core.repository.AuthRepository
|
||||
import moe.lava.neon.core.repository.GatewayRepository
|
||||
import moe.lava.neon.resources.Res
|
||||
import moe.lava.neon.resources.compose_multiplatform
|
||||
import moe.lava.neon.ui.Greeting
|
||||
|
|
@ -84,26 +84,24 @@ fun Sample(
|
|||
|
||||
class SampleViewModel(
|
||||
private val auth: AuthRepository,
|
||||
private val gateway: GatewayHandler,
|
||||
private val gateway: GatewayRepository,
|
||||
) : ViewModel() {
|
||||
private val logger = Logger.withTag("neon.ui.screens/Sample")
|
||||
val token get() = auth.token
|
||||
|
||||
fun connect() {
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
gateway.connect()
|
||||
} catch(e: Throwable) {
|
||||
logger.e(e) { "Failed to connect to gateway: ${e.stackTraceToString()}" }
|
||||
val exception = gateway.start().exceptionOrNull()
|
||||
if (exception != null) {
|
||||
logger.e(exception) { "Failed to connect to gateway: ${exception.stackTraceToString()}" }
|
||||
}
|
||||
}
|
||||
}
|
||||
fun disconnect() {
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
gateway.disconnect()
|
||||
} catch(e: Throwable) {
|
||||
logger.e(e) { "Failed to connect to gateway: ${e.stackTraceToString()}" }
|
||||
val exception = gateway.pause().exceptionOrNull()
|
||||
if (exception != null) {
|
||||
logger.e(exception) { "Failed to disconnect from gateway: ${exception.stackTraceToString()}" }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
package moe.lava.neon.ui
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import moe.lava.neon.core.api.ApiClient
|
||||
import moe.lava.neon.core.api.captcha.CaptchaResponse
|
||||
|
||||
@Composable
|
||||
// TODO
|
||||
actual fun CaptchaBinder(api: ApiClient) {
|
||||
api.setCaptchaHandler {
|
||||
CaptchaResponse.Failed(NotImplementedError())
|
||||
}
|
||||
}
|
||||
13
ui/src/jvmMain/kotlin/moe/lava/neon/ui/CaptchaHandler.jvm.kt
Normal file
13
ui/src/jvmMain/kotlin/moe/lava/neon/ui/CaptchaHandler.jvm.kt
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
package moe.lava.neon.ui
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import moe.lava.neon.common.captcha.CaptchaRequest
|
||||
import moe.lava.neon.common.captcha.CaptchaResponse
|
||||
|
||||
@Composable
|
||||
// TODO
|
||||
actual fun getCaptchaHandler(): suspend (CaptchaRequest) -> CaptchaResponse {
|
||||
return {
|
||||
CaptchaResponse.Failed(NotImplementedError())
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue