Skip to content

Commit

Permalink
fixed tokenresponse on distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
Protoxy22 committed Apr 29, 2022
1 parent 1d2130b commit 6e99ec8
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 25 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import org.jetbrains.compose.compose
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.gradle.jvm.tasks.Jar
import java.io.*
import java.util.spi.*

plugins {
val kotlinVersion = "1.5.31"
Expand Down Expand Up @@ -36,8 +39,10 @@ dependencies {
implementation("io.ktor:ktor-client-core:2.0.0")
implementation("io.ktor:ktor-client-cio:2.0.0")
implementation("io.ktor:ktor-client-auth:2.0.0")
implementation("io.ktor:ktor-serialization-gson-jvm:2.0.0")

implementation("io.ktor:ktor-serialization-gson:2.0.0")
implementation("io.ktor:ktor-client-content-negotiation:2.0.0")

// Module dependencies
// Dagger : A fast dependency injector for Android and Java.
api("com.google.dagger:dagger:$daggerVersion")
Expand Down Expand Up @@ -73,6 +78,8 @@ compose.desktop {
application {
mainClass = "net.volachat.AppKt"
nativeDistributions {
modules("jdk.crypto.ec")

targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
packageName = "volachat"
packageVersion = "1.0.0"
Expand All @@ -92,4 +99,21 @@ compose.desktop {
}
}
}
}

val printModuleDeps by tasks.creating {
doLast {
val uberJar = tasks.named("packageUberJarForCurrentOS", Jar::class)
val jarFile = uberJar.get().archiveFile.get().asFile

val jdeps = ToolProvider.findFirst("jdeps").orElseGet { error("Can't find jdeps tool in JDK") }
val out = StringWriter()
val pw = PrintWriter(out)
jdeps.run(pw, pw, "--print-module-deps", "--ignore-missing-deps", jarFile.absolutePath)

val modules = out.toString()
println(modules)
// compose.desktop.application.nativeDistributions.modules.addAll(modules.split(","))
}
dependsOn("packageUberJarForCurrentOS")
}
4 changes: 4 additions & 0 deletions src/main/kotlin/net/volachat/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class App(
var token: TokenResponse? = null

val client = HttpClient() {
engine {
threadsCount = 4
pipelining = true
}
install(ContentNegotiation) {
gson()
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/net/volachat/models/token/TokenResponse.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package net.volachat.models.token


data class TokenResponse(
val username: String,
val accessToken: String,
val expiresIn: Long
)
){ constructor() : this("", "", 0) }
20 changes: 12 additions & 8 deletions src/main/kotlin/net/volachat/ui/feature/main/LoginViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import io.ktor.client.call.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.http.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import net.volachat.util.ViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import net.volachat.App
import net.volachat.models.auth.UserCredentials
Expand All @@ -24,16 +27,17 @@ class LoginViewModel @Inject constructor() : ViewModel() {

fun onLogin(username: String, password: String) {
System.out.println("Attempt login for ($username, $password)")

runBlocking {
val response: HttpResponse = App.client.post("http://${App.volachat_server_ip}:${App.volachat_server_port}/login") {
contentType(ContentType.Application.Json)
setBody(UserCredentials(username, password))
}
if(response.status == HttpStatusCode.Unauthorized){
GlobalScope.launch(Dispatchers.IO) {
val response: HttpResponse =
App.client.post("http://${App.volachat_server_ip}:${App.volachat_server_port}/login") {
contentType(ContentType.Application.Json)
setBody(UserCredentials(username, password))
}
if (response.status == HttpStatusCode.Unauthorized) {
isBadLogin = true
println("User error login")
} else if (response.status == HttpStatusCode.OK){
} else if (response.status == HttpStatusCode.OK) {
println(response)
val token: TokenResponse = response.body()
App.token = token
println("Logged as ${App.token!!.username}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ fun PanelScreen (viewModel: PanelViewModel) {
) {

val state = rememberLazyListState()
val itemCount = 100

LazyColumn(Modifier.fillMaxSize().padding(start = 12.dp, end = 12.dp, top = 55.dp, bottom = 65.dp), state) {
items(viewModel.messages) { x ->
Expand Down

0 comments on commit 6e99ec8

Please sign in to comment.