From adcaffe11561fb26ed3e6a660251880976dd0c11 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 8 Dec 2024 10:26:53 +0600 Subject: [PATCH] add sealed workaround for webapp event type --- gradle/libs.versions.toml | 2 + tgbotapi.webapps/build.gradle | 9 ++++ .../dev/inmo/tgbotapi/webapps/EventHandler.kt | 8 --- .../dev/inmo/tgbotapi/webapps/EventType.kt | 5 ++ .../webapps/EventTypeSealedWorkaround.kt | 53 +++++++++++++++++++ 5 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/EventTypeSealedWorkaround.kt diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 6e921350b1..60fc0aa380 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -57,6 +57,8 @@ microutils-serialization-mapper = { module = "dev.inmo:micro_utils.serialization microutils-languageCodes = { module = "dev.inmo:micro_utils.language_codes", version.ref = "microutils" } microutils-ktor-common = { module = "dev.inmo:micro_utils.ktor.common", version.ref = "microutils" } microutils-fsm-common = { module = "dev.inmo:micro_utils.fsm.common", version.ref = "microutils" } +microutils-ksp-sealed = { module = "dev.inmo:micro_utils.ksp.sealed", version.ref = "microutils" } +microutils-ksp-sealed-generator = { module = "dev.inmo:micro_utils.ksp.sealed.generator", version.ref = "microutils" } kslog = { module = "dev.inmo:kslog", version.ref = "kslog" } diff --git a/tgbotapi.webapps/build.gradle b/tgbotapi.webapps/build.gradle index 9a17703fe8..8a5da2c325 100644 --- a/tgbotapi.webapps/build.gradle +++ b/tgbotapi.webapps/build.gradle @@ -2,6 +2,7 @@ plugins { id "org.jetbrains.kotlin.multiplatform" id "org.jetbrains.kotlin.plugin.serialization" id "org.jetbrains.dokka" + id "com.google.devtools.ksp" } project.description = "Web App bindings for the Telegram Web Apps API" @@ -14,7 +15,15 @@ kotlin { commonMain { dependencies { api project(":tgbotapi.core") + api libs.microutils.ksp.sealed } } } } + +dependencies { + add("kspJs", libs.microutils.ksp.sealed.generator) +} + +ksp {} + diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/EventHandler.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/EventHandler.kt index 584d54221c..dddbc67cf6 100644 --- a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/EventHandler.kt +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/EventHandler.kt @@ -3,11 +3,3 @@ package dev.inmo.tgbotapi.webapps import dev.inmo.tgbotapi.webapps.invoice.InvoiceClosedInfo typealias EventHandler = WebApp.() -> Unit -typealias ViewportChangedEventHandler = WebApp.(ViewportChangedData) -> Unit -typealias InvoiceClosedEventHandler = WebApp.(InvoiceClosedInfo) -> Unit -typealias PopupClosedEventHandler = WebApp.(String?) -> Unit -typealias QRTextReceivedEventHandler = WebApp.(String) -> Boolean -typealias TextReceivedEventHandler = WebApp.(String) -> Unit -typealias WriteAccessRequestedHandler = WebApp.(Boolean) -> Unit -typealias ContactRequestedHandler = WebApp.(Boolean) -> Unit -typealias onScanQRPopupClosedHandler = WebApp.() -> Unit diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/EventType.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/EventType.kt index e0876c8525..5c31ace099 100644 --- a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/EventType.kt +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/EventType.kt @@ -1,5 +1,8 @@ package dev.inmo.tgbotapi.webapps +import dev.inmo.micro_utils.ksp.sealed.GenerateSealedWorkaround + +@GenerateSealedWorkaround sealed class EventType(val typeName: String) { data object EmojiStatusAccessRequested : EventType("emojiStatusAccessRequested") data object AccelerometerChanged : EventType("accelerometerChanged") @@ -45,4 +48,6 @@ sealed class EventType(val typeName: String) { data object GyroscopeStarted : EventType("gyroscopeStarted") data object GyroscopeChanged : EventType("gyroscopeChanged") data object DeviceOrientationChanged : EventType("deviceOrientationChanged") + + companion object } diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/EventTypeSealedWorkaround.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/EventTypeSealedWorkaround.kt new file mode 100644 index 0000000000..1c565e15a4 --- /dev/null +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/EventTypeSealedWorkaround.kt @@ -0,0 +1,53 @@ +// THIS CODE HAVE BEEN GENERATED AUTOMATICALLY +// TO REGENERATE IT JUST DELETE FILE +// ORIGINAL FILE: EventType.kt +package dev.inmo.tgbotapi.webapps + +import kotlin.collections.Set + +private val values: Set = setOf(EventType.EmojiStatusAccessRequested, + EventType.AccelerometerChanged, + EventType.DeviceOrientationStarted, + EventType.EmojiStatusFailed, + EventType.Activated, + EventType.ShareMessageSent, + EventType.LocationManagerUpdated, + EventType.BiometricTokenUpdated, + EventType.DeviceOrientationFailed, + EventType.SafeAreaChanged, + EventType.WriteAccessRequested, + EventType.ContentSafeAreaChanged, + EventType.AccelerometerStarted, + EventType.AccelerometerStopped, + EventType.PopupClosed, + EventType.GyroscopeStopped, + EventType.BackButtonClicked, + EventType.HomeScreenAdded, + EventType.ShareMessageFailed, + EventType.ThemeChanged, + EventType.BiometricManagerUpdated, + EventType.ScanQrPopupClosed, + EventType.BiometricAuthRequested, + EventType.HomeScreenChecked, + EventType.LocationRequested, + EventType.SecondaryButtonClicked, + EventType.QrTextReceived, + EventType.EmojiStatusSet, + EventType.FullscreenFailed, + EventType.GyroscopeFailed, + EventType.SettingsButtonClicked, + EventType.Deactivated, + EventType.DeviceOrientationStopped, + EventType.FullscreenChanged, + EventType.ViewportChanged, + EventType.MainButtonClicked, + EventType.AccelerometerFailed, + EventType.ClipboardTextReceived, + EventType.FileDownloadRequested, + EventType.ContactRequested, + EventType.InvoiceClosed, + EventType.GyroscopeStarted, + EventType.GyroscopeChanged, + EventType.DeviceOrientationChanged) + +public fun EventType.Companion.values(): Set = values