Skip to content

Commit

Permalink
Merge branch 'test-ktor-bug'
Browse files Browse the repository at this point in the history
  • Loading branch information
YairLevi committed Jan 13, 2024
2 parents b8762f7 + f60a9be commit 7743c3f
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 6,721 deletions.
19 changes: 3 additions & 16 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,24 +100,11 @@
</build>

<dependencies>

<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-core-jvm</artifactId>
<version>${ktor_version}</version>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-netty-jvm</artifactId>
<version>${ktor_version}</version>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.9.3</version> <!-- Use the latest version -->
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-tests-jvm</artifactId>
<version>${ktor_version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down
17 changes: 15 additions & 2 deletions src/main/kotlin/org/levi/coffee/Window.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ import org.levi.coffee.internal.util.FileUtil
import org.levi.coffee.internal.MethodBinder
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import spark.Spark.staticFiles
import spark.Spark.init
import spark.Spark.stop
import java.util.Base64
import java.util.function.Consumer
import kotlin.system.exitProcess

class Window (withDevTools: Boolean = true) {
class Window (withDevTools: Boolean = true, val isDev: Boolean = false) {
private val log: Logger = LoggerFactory.getLogger(this::class.java)

private val _webview: Webview = Webview(withDevTools)
Expand Down Expand Up @@ -91,8 +94,18 @@ class Window (withDevTools: Boolean = true) {

_beforeStartCallbacks.forEach(Consumer { it.run() })
Ipc.setWebview(_webview)
_webview.loadURL(_url)

if (isDev) {
_webview.loadURL(_url)
}
else {
staticFiles.location("/dist")
_webview.loadURL("http://localhost:4567")
init()
}

_webview.run()
stop()
_onCloseCallbacks.forEach(Consumer { it.run() })
_webview.close()
}
Expand Down
42 changes: 42 additions & 0 deletions src/test/kotlin/Calculator.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import org.levi.coffee.Ipc
import org.levi.coffee.annotations.BindMethod

class Calculator {
private var calCount = 0

@BindMethod
fun add(a: Double, b: Double): Double {
calCount++
dispatch()
return a + b
}
@BindMethod
fun sub(a: Double, b: Double): Double {
calCount++
dispatch()
return a - b
}
@BindMethod
fun mul(a: Double, b: Double): Double {
calCount++
dispatch()
return a * b
}
@BindMethod
fun div(a: Double, b: Double): Double {
calCount++
dispatch()
return a / b
}

@BindMethod
fun get(): Int {
return this.calCount
}

private fun dispatch() {
if (calCount % 3 == 0) {
Ipc.invoke("count")
}
}
}
27 changes: 2 additions & 25 deletions src/test/kotlin/Main.kt
Original file line number Diff line number Diff line change
@@ -1,37 +1,14 @@
import org.levi.coffee.Ipc
import org.levi.coffee.Window
import org.levi.coffee.annotations.BindMethod
import org.levi.coffee.annotations.BindType

@BindType(ignore = ["age"])
class Person(
val name: String = "",
var age: Int = 0,
val hobbies: List<String> = emptyList(),
val string: Map<Person, List<Person>> = emptyMap(),
) {
@BindMethod
fun addTwoNumbers(a: Int, b: Int): Int {
return a + b;
}

@BindMethod
fun incrementAndPrint() {
// age++;
// println("My age increased to $age")
// println("invoking event...")
Ipc.invoke("event")
}
}

fun main() {
val win = Window()
val win = Window(isDev = true)
win.setSize(700, 700)
win.setTitle("My first Javatron app!")

win.setURL("http://localhost:5173")
win.bind(
Person(),
Calculator(),
)

win.addBeforeStartCallback { println("Started app...") }
Expand Down
32 changes: 16 additions & 16 deletions src/test/kotlin/Serve.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import io.ktor.server.application.*
import io.ktor.server.engine.*
import io.ktor.server.http.content.*
import io.ktor.server.netty.*
import io.ktor.server.routing.*

fun main() {
embeddedServer(Netty, port = 8080, host = "127.0.0.1") {
routing {
staticResources("/", "dist") {
default("index.html")
preCompressed(CompressedFileType.GZIP)
}
}
}.start(wait = true)
}
//import io.ktor.server.engine.*
//import io.ktor.server.http.content.*
//import io.ktor.server.netty.*
//import io.ktor.server.routing.*
//
//fun main() {
// embeddedServer(Netty, port = 8080, host = "127.0.0.1") {
// routing {
// staticResources("/", "dist2") {
// default("index.html")
// preCompressed(CompressedFileType.GZIP)
// }
// }
// }.start(wait = false)
// println("Hello world")
//}
40 changes: 0 additions & 40 deletions src/test/resources/dist/assets/index-_k2OAqGo.js

This file was deleted.

40 changes: 40 additions & 0 deletions src/test/resources/dist/assets/index-p2Tz6Vch.js

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions src/test/resources/dist/build/script.js

This file was deleted.

3 changes: 0 additions & 3 deletions src/test/resources/dist/build/styles.css

This file was deleted.

11 changes: 0 additions & 11 deletions src/test/resources/dist/build/web.html

This file was deleted.

Loading

0 comments on commit 7743c3f

Please sign in to comment.