From 860e35258ce881d112113e33c51ebba4c859fed8 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 4 Jan 2024 17:52:57 +0600 Subject: [PATCH] update webapp part --- .../dev/inmo/tgbotapi/webapps/SettingsButton.kt | 11 +++++++++++ .../dev/inmo/tgbotapi/webapps/ThemeParams.kt | 13 +++++++++++++ .../kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt | 17 +++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/SettingsButton.kt diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/SettingsButton.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/SettingsButton.kt new file mode 100644 index 0000000000..7ea0c0bd97 --- /dev/null +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/SettingsButton.kt @@ -0,0 +1,11 @@ +package dev.inmo.tgbotapi.webapps + +external interface SettingsButton { + val isVisible: Boolean + + fun onClick(callback: () -> Unit) + fun offClick(callback: () -> Unit) + + fun show() + fun hide() +} \ No newline at end of file diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/ThemeParams.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/ThemeParams.kt index b72c7b5f40..e9d19c273a 100644 --- a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/ThemeParams.kt +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/ThemeParams.kt @@ -30,4 +30,17 @@ external interface ThemeParams { val buttonColorHex: Color.Hex? @JsName("button_text_color") val buttonTextColorHex: Color.Hex? + + @JsName("header_bg_color") + val headerBgColor: Color.Hex? + @JsName("accent_text_color") + val accentTextColor: Color.Hex? + @JsName("section_bg_color") + val sectionBgColor: Color.Hex? + @JsName("section_header_text_color") + val sectionHeaderTextColor: Color.Hex? + @JsName("subtitle_text_color") + val subtitleTextColor: Color.Hex? + @JsName("destructive_text_color") + val destructiveTextColor: Color.Hex? } diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt index af395cd420..d6f4fe7f4e 100644 --- a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt @@ -54,6 +54,9 @@ external class WebApp { @JsName("CloudStorage") val cloudStorage: CloudStorage + @JsName("SettingsButton") + val settingsButton: SettingsButton + internal fun onEvent(type: String, callback: () -> Unit) @JsName("onEvent") internal fun onEventWithViewportChangedData(type: String, callback: (ViewportChangedData) -> Unit) @@ -69,6 +72,8 @@ external class WebApp { internal fun onEventWithWriteAccessRequested(type: String, callback: (RequestStatus) -> Unit) @JsName("onEvent") internal fun onEventWithContactRequested(type: String, callback: (RequestStatus) -> Unit) + @JsName("onEvent") + internal fun onEventWithSettingsButtonClicked(type: String, callback: () -> Unit) fun offEvent(type: String, callback: () -> Unit) @JsName("offEvent") @@ -194,6 +199,18 @@ fun WebApp.onEvent(type: EventType.ContactRequested, eventHandler: ContactReques ) } +/** + * @return The callback which should be used in case you want to turn off events handling + */ +fun WebApp.onEvent(type: EventType.SettingsButtonClicked, eventHandler: EventHandler) = { + eventHandler(js("this").unsafeCast()) +}.also { + onEventWithSettingsButtonClicked( + type.typeName, + callback = it + ) +} + /** * @return The callback which should be used in case you want to turn off events handling */