Skip to content

Commit

Permalink
Removed logging, defaulted to JCEF and chose available port
Browse files Browse the repository at this point in the history
  • Loading branch information
smilefx committed Jul 24, 2024
1 parent a76218a commit 2ea66d5
Show file tree
Hide file tree
Showing 20 changed files with 69 additions and 171 deletions.
46 changes: 40 additions & 6 deletions bgw-gui/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import okhttp3.internal.notifyAll
import org.jetbrains.kotlin.cli.common.ExitCode
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilerExecutionStrategy
import org.jetbrains.kotlin.gradle.tasks.throwExceptionIfCompilationFailed
import java.lang.management.ManagementFactory
import java.io.File

plugins {
val kotlinVersion = "2.0.0"
kotlin("multiplatform") //version kotlinVersion
kotlin("plugin.serialization") version kotlinVersion
application
id("org.openjfx.javafxplugin") version "0.0.14"
//id("org.openjfx.javafxplugin") version "0.0.14"
`maven-publish`
}

Expand Down Expand Up @@ -53,7 +60,7 @@ kotlin {
implementation("io.ktor:ktor-server-html-builder-jvm:2.3.11")
implementation("org.jetbrains.kotlinx:kotlinx-html-jvm:0.7.2")
implementation("me.friwi:jcefmaven:122.1.10")
implementation("com.jfoenix:jfoenix:9.0.1")
//implementation("com.jfoenix:jfoenix:9.0.1")
}
}
val jvmTest by getting
Expand All @@ -78,8 +85,16 @@ tasks.named<Copy>("jvmProcessResources") {
}

tasks.named<JavaExec>("run") {
doFirst {

}

dependsOn(tasks.named<Jar>("jvmJar"))
classpath(tasks.named<Jar>("jvmJar"))

doLast {

}
}

publishing {
Expand All @@ -93,7 +108,26 @@ publishing {
}
}

javafx {
version = "18.0.2"
modules = listOf("javafx.controls", "javafx.web")
}
gradle.buildFinished {
// println("Message: ${this.failure?.message}")
// println("Exception: ${this.failure?.cause}")
// val stacktrace = this.failure?.stackTraceToString()
// val wasCancelled = stacktrace?.indexOf("Build cancelled") != -1
// println("Build cancelled: ${wasCancelled}")

if (wasCancelled) {
// ProcessHandle.allProcesses().forEach {
// if (it.info().command().orElse("").contains("jcef_helper.exe")) {
// println("Chrome Process: ${it.pid()}")
// it.destroy()
// }
// }
ExitCode.OK
}
ExitCode.OK
}

//javafx {
// version = "18.0.2"
// modules = listOf("javafx.controls", "javafx.web")
//}
2 changes: 1 addition & 1 deletion bgw-gui/src/commonMain/kotlin/Constants.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

enum class WebViewType {
JCEF, JAVAFX
JCEF
}

val webViewType = WebViewType.JCEF
12 changes: 0 additions & 12 deletions bgw-gui/src/jsMain/kotlin/tools/aqua/bgw/Animator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ class Animator {
private fun startComponentAnimation(type : String, animation: ComponentAnimationData, parallelAnimation : List<AnimationData> = listOf(), callback: (ID) -> Unit) {
// Get animation properties from data
val componentId = animation.componentView?.id.toString()
println("Starting $type Animation on ${componentId}")
val duration = animation.duration

// Get matching component element
Expand Down Expand Up @@ -161,7 +160,6 @@ class Animator {
val type = "flip"
// Get animation properties from data
val componentId = animation.componentView?.id.toString()
println("Starting $type Animation on ${componentId}")
val duration = animation.duration

// Get matching component element
Expand Down Expand Up @@ -189,14 +187,12 @@ class Animator {

val oldVisuals = document.querySelector("#${componentId} > bgw_visuals") as Element?
if (oldVisuals != null) {
println("Rendering start visual for flip")
render(VisualBuilder.build(animation.fromVisual), oldVisuals)
}

setTimeout({
val oldVisuals = document.querySelector("#${componentId} > bgw_visuals") as Element?
if (oldVisuals != null) {
println("Rendering end visual for flip")
render(VisualBuilder.build(animation.toVisual), oldVisuals)
}
}, duration / 2)
Expand All @@ -213,13 +209,11 @@ class Animator {
val type = "random"
// Get animation properties from data
val componentId = animation.componentView?.id.toString()
println("Starting $type Animation on ${componentId}")
val duration = animation.duration

val interval = setInterval({
val oldVisuals = document.querySelector("#${componentId} > bgw_visuals") as Element?
if (oldVisuals != null) {
println("Rendering new visual for random")
render(VisualBuilder.build(animation.visuals.random()), oldVisuals)
}
}, duration / animation.speed)
Expand All @@ -228,10 +222,8 @@ class Animator {
clearInterval(interval)
val oldVisuals = document.querySelector("#${componentId} > bgw_visuals") as Element?
if (oldVisuals != null) {
println("Rendering end visual for random")
render(VisualBuilder.build(animation.toVisual), oldVisuals)
}
println("Stopping $type Animation on ${componentId}")
callback.invoke(animation.id)
}, duration)
}
Expand All @@ -241,13 +233,11 @@ class Animator {
// Get animation properties from data
val componentId = animation.componentView?.id.toString()
val dice = animation.componentView as? DiceViewData ?: return
println("Starting $type Animation on ${componentId}")
val duration = animation.duration

val interval = setInterval({
val oldVisuals = document.querySelector("#${componentId} > bgw_visuals") as Element?
if (oldVisuals != null) {
println("Rendering new visual for dice")
render(VisualBuilder.build(dice.visuals.random()), oldVisuals)
}
}, duration / animation.speed)
Expand All @@ -256,10 +246,8 @@ class Animator {
clearInterval(interval)
val oldVisuals = document.querySelector("#${componentId} > bgw_visuals") as Element?
if (oldVisuals != null) {
println("Rendering end visual for dice")
render(VisualBuilder.build(dice.visuals[animation.toSide]), oldVisuals)
}
println("Stopping $type Animation on ${componentId}")
callback.invoke(animation.id)
}, duration)
}
Expand Down
13 changes: 3 additions & 10 deletions bgw-gui/src/jsMain/kotlin/tools/aqua/bgw/Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@ val container = document.createElement("div")
fun main() {
container.id = "root"
document.body!!.appendChild(container)
webSocket = WebSocket("ws://localhost:8080/ws")
webSocket?.onopen = { //println("Connected to Server via WebSocket!")
}
webSocket = WebSocket("ws://${document.location?.host}/ws")
webSocket?.onopen = { }
webSocket?.onmessage = { event ->
println("Received: ${event.data}")
val receivedData = jsonMapper.decodeFromString<PropData>(event.data.toString()).data
when(receivedData) {
is AppData -> {
Expand Down Expand Up @@ -107,12 +105,7 @@ fun main() {

fun renderApp(appData : AppData) {
render(App.create { data = appData }, container as Element, callback = {
println("Rendered App to DOM!")
when(webViewType) {
WebViewType.JCEF -> { JCEFEventDispatcher.dispatchEvent(LoadEventData()) }
WebViewType.JAVAFX -> container.dispatchEvent(Event("bgwLoaded"))
}
Unit
JCEFEventDispatcher.dispatchEvent(LoadEventData())
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ object VisualBuilder {
}
}
is CompoundVisualData -> {
//println("Building CompoundVisual ${visual.id}")
return CompoundVisual.create {
data = visual
}
Expand Down
16 changes: 0 additions & 16 deletions bgw-gui/src/jsMain/kotlin/tools/aqua/bgw/elements/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ val App = FC<AppProps> { props ->
backgroundColor = rgb(0, 0, 0, 0.0)
overflow = Overflow.hidden
}

"#root" {
backgroundColor = important(rgb(0, 0, 255))
}
}

// RED
Expand All @@ -78,10 +74,6 @@ val App = FC<AppProps> { props ->
backgroundColor = rgb(0, 0, 0, 0.0)
overflow = Overflow.hidden
}

"#root" {
backgroundColor = important(rgb(255, 0, 0))
}
}

// GREEN
Expand All @@ -102,10 +94,6 @@ val App = FC<AppProps> { props ->
backgroundColor = rgb(0, 0, 0, 0.0)
overflow = Overflow.hidden
}

"#root" {
backgroundColor = important(rgb(0, 255, 0))
}
}

// YELLOW
Expand All @@ -126,10 +114,6 @@ val App = FC<AppProps> { props ->
backgroundColor = rgb(0, 0, 0, 0.0)
overflow = Overflow.hidden
}

"#root" {
backgroundColor = important(rgb(255, 255, 0))
}
}

"body" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ val ComboBox = FC<ComboBoxProps> { props ->
}
onChange = {
val value = it.target.value.toInt()
println("Selection changed $value")
JCEFEventDispatcher.dispatchEvent(SelectionChangedEventData(value).apply { id = props.data.id })
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ val Label = FC<LabelProps> { props ->
it.preventDefault()
JCEFEventDispatcher.dispatchEvent(it.toMouseEventData(id))
}
onClick = { console.log("Clicked"); JCEFEventDispatcher.dispatchEvent(it.toMouseEventData(id)) }
onClick = { JCEFEventDispatcher.dispatchEvent(it.toMouseEventData(id)) }
onKeyDown = { JCEFEventDispatcher.dispatchEvent(it.toKeyEventData(id, KeyEventAction.PRESS)) }
onKeyUp = { JCEFEventDispatcher.dispatchEvent(it.toKeyEventData(id, KeyEventAction.RELEASE)) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ val ProgressBar = FC<ProgressBarProps> { props ->
onKeyDown = { JCEFEventDispatcher.dispatchEvent(it.toKeyEventData(id, KeyEventAction.PRESS)) }
onKeyUp = { JCEFEventDispatcher.dispatchEvent(it.toKeyEventData(id, KeyEventAction.RELEASE)) }
onDragStart = {
println("onDragStart Progress")
val element = it.target as HTMLElement
it.dataTransfer.setData("text", element.id)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ val TextField = FC<TextFieldProps> { props ->
}
onChange = {
val value = it.target.value
//println("Text changed $value")
JCEFEventDispatcher.dispatchEvent(TextInputChangedEventData(value).apply { id = props.data.id })
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ object JCEFEventDispatcher : EventDispatcher {

override fun dispatchEvent(event: AnimationFinishedEventData) {
val json = jsonMapper.encodeToString(event)
println("Dispatching event: $json (AnimationFinishedEventData)")
try {
window.asDynamic().bgwAnimationQuery(Base64.encode(json))
} catch (e: Throwable) {
Expand All @@ -22,7 +21,6 @@ object JCEFEventDispatcher : EventDispatcher {

override fun dispatchEvent(event: EventData) {
val json = jsonMapper.encodeToString(event)
println("Dispatching event: $json (EventData)")
try {
window.asDynamic().bgwQuery(Base64.encode(json))
} catch (e: Throwable) {
Expand Down

This file was deleted.

Loading

0 comments on commit 2ea66d5

Please sign in to comment.