1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-12-22 00:27:14 +00:00

support of accelerometer, gyroscope, location and orientation data

This commit is contained in:
InsanusMokrassar 2024-12-05 15:49:07 +06:00
parent 652765bf46
commit 41a142addb
11 changed files with 144 additions and 1 deletions

View File

@ -0,0 +1,3 @@
package dev.inmo.tgbotapi.webapps
external interface ContentSafeAreaInset : SafeAreaInset {}

View File

@ -0,0 +1,9 @@
package dev.inmo.tgbotapi.webapps
external interface SafeAreaInset {
val top: Int
val bottom: Int
val left: Int
val right: Int
}

View File

@ -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

View File

@ -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)
}

View File

@ -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<AccelerometerStartParams>()

View File

@ -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)
}

View File

@ -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<GyroscopeStartParams>()

View File

@ -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?
}

View File

@ -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()
}

View File

@ -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)
}

View File

@ -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<DeviceOrientationStartParams>()