From 41a142addb2c873d0d306c51a904a1d92b9bb3f2 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 5 Dec 2024 15:49:07 +0600 Subject: [PATCH] support of accelerometer, gyroscope, location and orientation data --- .../tgbotapi/webapps/ContentSafeAreaInset.kt | 3 +++ .../inmo/tgbotapi/webapps/SafeAreaInset.kt | 9 +++++++++ .../dev/inmo/tgbotapi/webapps/WebApp.kt | 19 ++++++++++++++++++- .../webapps/accelerometer/Accelerometer.kt | 12 ++++++++++++ .../accelerometer/AccelerometerStartParams.kt | 13 +++++++++++++ .../tgbotapi/webapps/gyroscope/Gyroscope.kt | 12 ++++++++++++ .../webapps/gyroscope/GyroscopeStartParams.kt | 13 +++++++++++++ .../tgbotapi/webapps/location/LocationData.kt | 17 +++++++++++++++++ .../webapps/location/LocationManager.kt | 15 +++++++++++++++ .../webapps/orientation/DeviceOrientation.kt | 13 +++++++++++++ .../DeviceOrientationStartParams.kt | 19 +++++++++++++++++++ 11 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/ContentSafeAreaInset.kt create mode 100644 tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/SafeAreaInset.kt create mode 100644 tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/accelerometer/Accelerometer.kt create mode 100644 tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/accelerometer/AccelerometerStartParams.kt create mode 100644 tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/gyroscope/Gyroscope.kt create mode 100644 tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/gyroscope/GyroscopeStartParams.kt create mode 100644 tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/location/LocationData.kt create mode 100644 tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/location/LocationManager.kt create mode 100644 tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/orientation/DeviceOrientation.kt create mode 100644 tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/orientation/DeviceOrientationStartParams.kt diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/ContentSafeAreaInset.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/ContentSafeAreaInset.kt new file mode 100644 index 0000000000..8a12d22e36 --- /dev/null +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/ContentSafeAreaInset.kt @@ -0,0 +1,3 @@ +package dev.inmo.tgbotapi.webapps + +external interface ContentSafeAreaInset : SafeAreaInset {} \ No newline at end of file diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/SafeAreaInset.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/SafeAreaInset.kt new file mode 100644 index 0000000000..f02eddc4c0 --- /dev/null +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/SafeAreaInset.kt @@ -0,0 +1,9 @@ +package dev.inmo.tgbotapi.webapps + +external interface SafeAreaInset { + val top: Int + val bottom: Int + val left: Int + val right: Int +} + 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 b327b43694..4d6c659b0f 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 @@ -1,12 +1,15 @@ package dev.inmo.tgbotapi.webapps -import dev.inmo.tgbotapi.types.MessageId import dev.inmo.tgbotapi.types.PreparedMessageId import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper +import dev.inmo.tgbotapi.webapps.accelerometer.Accelerometer import dev.inmo.tgbotapi.webapps.biometric.BiometricManager import dev.inmo.tgbotapi.webapps.cloud.CloudStorage +import dev.inmo.tgbotapi.webapps.gyroscope.Gyroscope import dev.inmo.tgbotapi.webapps.haptic.HapticFeedback import dev.inmo.tgbotapi.webapps.invoice.InvoiceClosedInfo +import dev.inmo.tgbotapi.webapps.location.LocationManager +import dev.inmo.tgbotapi.webapps.orientation.DeviceOrientation import dev.inmo.tgbotapi.webapps.popup.* import dev.inmo.tgbotapi.webapps.stories.StoryShareParams @@ -56,6 +59,8 @@ external class WebApp { val isActive: Boolean val isFullscreen: Boolean + val safeAreaInset: SafeAreaInset + val contentSafeAreaInset: ContentSafeAreaInset fun requestFullscreen() fun exitFullscreen() @@ -85,6 +90,18 @@ external class WebApp { @JsName("BiometricManager") val biometricManager: BiometricManager + @JsName("Accelerometer") + val accelerometer: Accelerometer + + @JsName("DeviceOrientation") + val deviceOrientation: DeviceOrientation + + @JsName("Gyroscope") + val gyroscope: Gyroscope + + @JsName("LocationManager") + val locationManager: LocationManager + @JsName("SettingsButton") val settingsButton: SettingsButton diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/accelerometer/Accelerometer.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/accelerometer/Accelerometer.kt new file mode 100644 index 0000000000..f23a4f75d9 --- /dev/null +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/accelerometer/Accelerometer.kt @@ -0,0 +1,12 @@ +package dev.inmo.tgbotapi.webapps.accelerometer + +external interface Accelerometer { + val isStarted: Boolean + val x: Double + val y: Double + val z: Double + + fun start(params: AccelerometerStartParams, callback: (Boolean) -> Unit = definedExternally) + fun stop(callback: (Boolean) -> Unit) +} + diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/accelerometer/AccelerometerStartParams.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/accelerometer/AccelerometerStartParams.kt new file mode 100644 index 0000000000..81baae99e9 --- /dev/null +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/accelerometer/AccelerometerStartParams.kt @@ -0,0 +1,13 @@ +package dev.inmo.tgbotapi.webapps.accelerometer + +import dev.inmo.tgbotapi.types.MilliSeconds +import kotlin.js.json + +external interface AccelerometerStartParams { + @JsName("refresh_rate") + val refreshRate: MilliSeconds +} + +fun AccelerometerStartParams(refreshRate: MilliSeconds = 1000): AccelerometerStartParams = json( + "refresh_rate" to refreshRate +).unsafeCast() \ No newline at end of file diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/gyroscope/Gyroscope.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/gyroscope/Gyroscope.kt new file mode 100644 index 0000000000..45ba27a4cf --- /dev/null +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/gyroscope/Gyroscope.kt @@ -0,0 +1,12 @@ +package dev.inmo.tgbotapi.webapps.gyroscope + +external interface Gyroscope { + val isStarted: Boolean + val x: Double + val y: Double + val z: Double + + fun start(params: GyroscopeStartParams, callback: (Boolean) -> Unit = definedExternally) + fun stop(callback: (Boolean) -> Unit) +} + diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/gyroscope/GyroscopeStartParams.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/gyroscope/GyroscopeStartParams.kt new file mode 100644 index 0000000000..abacf779c7 --- /dev/null +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/gyroscope/GyroscopeStartParams.kt @@ -0,0 +1,13 @@ +package dev.inmo.tgbotapi.webapps.gyroscope + +import dev.inmo.tgbotapi.types.MilliSeconds +import kotlin.js.json + +external interface GyroscopeStartParams { + @JsName("refresh_rate") + val refreshRate: MilliSeconds +} + +fun GyroscopeStartParams(refreshRate: MilliSeconds = 1000): GyroscopeStartParams = json( + "refresh_rate" to refreshRate +).unsafeCast() \ No newline at end of file diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/location/LocationData.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/location/LocationData.kt new file mode 100644 index 0000000000..39a3c1984d --- /dev/null +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/location/LocationData.kt @@ -0,0 +1,17 @@ +package dev.inmo.tgbotapi.webapps.location + +external interface LocationData { + val latitude: Double + val longitude: Double + val altitude: Double? + val course: Double? + val speed: Double? + @JsName("horizontal_accuracy") + val horizontalAccuracy: Double? + @JsName("vertical_accuracy") + val verticalAccuracy: Double? + @JsName("course_accuracy") + val courseAccuracy: Double? + @JsName("speed_accuracy") + val speedAccuracy: Double? +} \ No newline at end of file diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/location/LocationManager.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/location/LocationManager.kt new file mode 100644 index 0000000000..47c94bfb0e --- /dev/null +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/location/LocationManager.kt @@ -0,0 +1,15 @@ +package dev.inmo.tgbotapi.webapps.location + +external interface LocationManager { + val isInited: Boolean + + val isLocationAvailable: Boolean + val isAccessRequested: Boolean + val isAccessGranted: Boolean + + fun init(callback: () -> Unit = definedExternally) + + fun getLocation(callback: (location: LocationData) -> Unit) + + fun openSettings() +} \ No newline at end of file diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/orientation/DeviceOrientation.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/orientation/DeviceOrientation.kt new file mode 100644 index 0000000000..9c4e753406 --- /dev/null +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/orientation/DeviceOrientation.kt @@ -0,0 +1,13 @@ +package dev.inmo.tgbotapi.webapps.orientation + +external interface DeviceOrientation { + val isStarted: Boolean + val absolute: Boolean + val alpha: Double + val beta: Double + val gamma: Double + + fun start(params: DeviceOrientationStartParams, callback: (Boolean) -> Unit) + fun stop(callback: (Boolean) -> Unit) +} + diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/orientation/DeviceOrientationStartParams.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/orientation/DeviceOrientationStartParams.kt new file mode 100644 index 0000000000..c93c191747 --- /dev/null +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/orientation/DeviceOrientationStartParams.kt @@ -0,0 +1,19 @@ +package dev.inmo.tgbotapi.webapps.orientation + +import dev.inmo.tgbotapi.types.MilliSeconds +import kotlin.js.json + +external interface DeviceOrientationStartParams { + @JsName("refresh_rate") + val refreshRate: MilliSeconds + @JsName("need_absolute") + val needAbsolute: Boolean +} + +fun DeviceOrientationStartParams( + refreshRate: MilliSeconds = 1000, + needAbsolute: Boolean = false +): DeviceOrientationStartParams = json( + "refresh_rate" to refreshRate, + "need_absolute" to needAbsolute +).unsafeCast() \ No newline at end of file