diff --git a/FilesLoaderBot/build.gradle b/FilesLoaderBot/build.gradle index cfae1ab..c270e9d 100644 --- a/FilesLoaderBot/build.gradle +++ b/FilesLoaderBot/build.gradle @@ -1,6 +1,6 @@ buildscript { repositories { - jcenter() + mavenCentral() } dependencies { diff --git a/ForwardInfoSenderBot/build.gradle b/ForwardInfoSenderBot/build.gradle index a0266c8..fd5b770 100644 --- a/ForwardInfoSenderBot/build.gradle +++ b/ForwardInfoSenderBot/build.gradle @@ -1,6 +1,6 @@ buildscript { repositories { - jcenter() + mavenCentral() } dependencies { diff --git a/GetMeBot/build.gradle b/GetMeBot/build.gradle index d987241..0188724 100644 --- a/GetMeBot/build.gradle +++ b/GetMeBot/build.gradle @@ -1,6 +1,6 @@ buildscript { repositories { - jcenter() + mavenCentral() } dependencies { diff --git a/HelloBot/build.gradle b/HelloBot/build.gradle index d987241..0188724 100644 --- a/HelloBot/build.gradle +++ b/HelloBot/build.gradle @@ -1,6 +1,6 @@ buildscript { repositories { - jcenter() + mavenCentral() } dependencies { diff --git a/KeyboardsBot/KeyboardsBotLib/build.gradle b/KeyboardsBot/KeyboardsBotLib/build.gradle index 50db973..bda3692 100644 --- a/KeyboardsBot/KeyboardsBotLib/build.gradle +++ b/KeyboardsBot/KeyboardsBotLib/build.gradle @@ -1,6 +1,6 @@ buildscript { repositories { - jcenter() + mavenCentral() } dependencies { diff --git a/KeyboardsBot/jvm_launcher/build.gradle b/KeyboardsBot/jvm_launcher/build.gradle index 47b4729..7b26cf6 100644 --- a/KeyboardsBot/jvm_launcher/build.gradle +++ b/KeyboardsBot/jvm_launcher/build.gradle @@ -1,6 +1,6 @@ buildscript { repositories { - jcenter() + mavenCentral() } dependencies { diff --git a/RandomFileSenderBot/build.gradle b/RandomFileSenderBot/build.gradle index 204c510..946ccfc 100644 --- a/RandomFileSenderBot/build.gradle +++ b/RandomFileSenderBot/build.gradle @@ -1,6 +1,6 @@ buildscript { repositories { - jcenter() + mavenCentral() } dependencies { diff --git a/ResenderBot/ResenderBotLib/build.gradle b/ResenderBot/ResenderBotLib/build.gradle index c7c78d0..21b03ee 100644 --- a/ResenderBot/ResenderBotLib/build.gradle +++ b/ResenderBot/ResenderBotLib/build.gradle @@ -1,6 +1,6 @@ buildscript { repositories { - jcenter() + mavenCentral() } dependencies { diff --git a/ResenderBot/jvm_launcher/build.gradle b/ResenderBot/jvm_launcher/build.gradle index 07b3351..5fe7ee3 100644 --- a/ResenderBot/jvm_launcher/build.gradle +++ b/ResenderBot/jvm_launcher/build.gradle @@ -1,6 +1,6 @@ buildscript { repositories { - jcenter() + mavenCentral() } dependencies { diff --git a/SlotMachineDetectorBot/build.gradle b/SlotMachineDetectorBot/build.gradle index 9bb1ca1..312e485 100644 --- a/SlotMachineDetectorBot/build.gradle +++ b/SlotMachineDetectorBot/build.gradle @@ -1,6 +1,6 @@ buildscript { repositories { - jcenter() + mavenCentral() } dependencies { diff --git a/WebApp/build.gradle b/WebApp/build.gradle new file mode 100644 index 0000000..7f73e5f --- /dev/null +++ b/WebApp/build.gradle @@ -0,0 +1,55 @@ +buildscript { + repositories { + mavenCentral() + } + + dependencies { + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } +} + +plugins { + id "org.jetbrains.kotlin.multiplatform" version "$kotlin_version" +} + +apply plugin: 'application' + +kotlin { + jvm() + js(IR) { + browser() + binaries.executable() + } + + sourceSets { + commonMain { + dependencies { + implementation kotlin('stdlib') + } + } + + jsMain { + dependencies { + implementation "dev.inmo:tgbotapi.webapps:$telegram_bot_api_version" + } + } + + jvmMain { + dependencies { + implementation "dev.inmo:tgbotapi:$telegram_bot_api_version" + implementation "dev.inmo:micro_utils.ktor.server:$micro_utils_version" + implementation "io.ktor:ktor-server-tomcat:$ktor_version" + } + } + } +} + +application { + mainClassName = "WebAppServerKt" +} + +tasks.getByName("compileKotlinJvm") + .dependsOn(jsBrowserDistribution) +tasks.getByName("compileKotlinJvm").configure { + mustRunAfter jsBrowserDistribution +} diff --git a/WebApp/src/jsMain/kotlin/main.kt b/WebApp/src/jsMain/kotlin/main.kt new file mode 100644 index 0000000..cb4c5bc --- /dev/null +++ b/WebApp/src/jsMain/kotlin/main.kt @@ -0,0 +1,42 @@ +import dev.inmo.tgbotapi.webapps.* +import io.ktor.client.HttpClient +import io.ktor.client.request.get +import io.ktor.client.statement.HttpResponse +import io.ktor.client.statement.readText +import io.ktor.http.encodeURLPath +import kotlinx.browser.document +import kotlinx.browser.window +import kotlinx.coroutines.* +import kotlinx.dom.appendElement +import kotlinx.dom.appendText + +fun main() { + console.log("Web app started") + window.onload = { + val scope = CoroutineScope(Dispatchers.Default) + runCatching { + document.body ?.appendElement("button") { + addEventListener( + "click", + { + webApp.sendData("Clicked") + } + ) + appendText("Example button") + } ?: window.alert("Unable to load body") + webApp.apply { + onThemeChanged { + document.body ?.appendText("Theme changed: ${webApp.themeParams}") + document.body ?.appendElement("p", {}) + } + onViewportChanged { + document.body ?.appendText("Viewport changed: ${it.isStateStable}") + document.body ?.appendElement("p", {}) + } + } + webApp.ready() + }.onFailure { + window.alert(it.stackTraceToString()) + } + } +} diff --git a/WebApp/src/jsMain/resources/index.html b/WebApp/src/jsMain/resources/index.html new file mode 100644 index 0000000..b00362c --- /dev/null +++ b/WebApp/src/jsMain/resources/index.html @@ -0,0 +1,11 @@ + + +
+ +