49 lines
1.2 KiB
TypeScript
49 lines
1.2 KiB
TypeScript
import { defineBoot } from '#q-app/wrappers'
|
|
import type { WebApp } from "@twa-dev/types"
|
|
|
|
declare global {
|
|
interface Window {
|
|
Telegram: { WebApp: WebApp }
|
|
}
|
|
}
|
|
|
|
export default defineBoot(({ app }) => {
|
|
const tg = window.Telegram?.WebApp
|
|
|
|
tg.ready()
|
|
tg.disableVerticalSwipes()
|
|
sessionStorage.setItem('isTelegram', tg.initData ? 'true' : 'false')
|
|
|
|
const platform = tg.platform.toLowerCase()
|
|
const isDesktopOrWeb = [
|
|
'tdesktop',
|
|
'tdlib',
|
|
'macos',
|
|
'web',
|
|
'weba',
|
|
'webk'
|
|
].includes(platform)
|
|
const isTablet = window.innerWidth > 1024
|
|
if (!isDesktopOrWeb && !isTablet) tg.expand()
|
|
|
|
tg.SettingsButton.show()
|
|
|
|
app.config.globalProperties.$tg = tg
|
|
app.config.globalProperties.$isDesktop = isDesktopOrWeb || isTablet
|
|
app.config.globalProperties.$isMobile = !isDesktopOrWeb && !isTablet
|
|
app.config.globalProperties.$isIOS = platform === 'ios'
|
|
app.config.globalProperties.$isAndroid = platform === 'android'
|
|
|
|
app.provide('tg', tg)
|
|
})
|
|
|
|
/* flag use
|
|
<div v-if="$isDesktop || isToolbarExpanded">
|
|
<q-tabs ...> </q-tabs>
|
|
</div>
|
|
|
|
script setup
|
|
import { getCurrentInstance } from 'vue'
|
|
const app = getCurrentInstance()
|
|
const isMobile = app?.appContext.config.globalProperties.$isMobile
|
|
*/ |