Skip to content

Commit

Permalink
Improve types for isPlatform
Browse files Browse the repository at this point in the history
  • Loading branch information
deptyped committed Jul 23, 2024
1 parent e26061a commit 4d87dbc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 25 deletions.
8 changes: 0 additions & 8 deletions docs/mini-apps/composables/use-web-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,5 @@ import { useWebApp } from 'vue-tg'
| `isReady` <Badge type="tip" text="custom" /> | `Readonly<Ref<boolean>>` |
| `isPlatform` <Badge type="tip" text="custom" /> | `(name: string) => boolean` |
| `isPlatformUnknown` <Badge type="tip" text="custom" /> | `boolean` |
| `isPlatformAndroid` <Badge type="tip" text="custom" /> | `boolean` |
| `isPlatformAndroidX` <Badge type="tip" text="custom" /> | `boolean` |
| `isPlatformIOS` <Badge type="tip" text="custom" /> | `boolean` |
| `isPlatformMacOS` <Badge type="tip" text="custom" /> | `boolean` |
| `isPlatformTDesktop` <Badge type="tip" text="custom" /> | `boolean` |
| `isPlatformWebA` <Badge type="tip" text="custom" /> | `boolean` |
| `isPlatformWebK` <Badge type="tip" text="custom" /> | `boolean` |
| `isPlatformUnigram` <Badge type="tip" text="custom" /> | `boolean` |
| `isFeatureSupported` <Badge type="tip" text="custom" /> | `(name: string) => boolean` |
| `canSendData` <Badge type="tip" text="custom" /> | `boolean` |
30 changes: 13 additions & 17 deletions src/composables/useWebApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,21 @@ const ready: typeof Telegram.WebApp.ready = (...params) => {
isReady.value = true
}

const isPlatform = (name: string) => Telegram.WebApp.platform === name
const isPlatform = (
name:
| (string & Record<never, never>)
| "unknown"
| "android"
| "android_x"
| "ios"
| "macos"
| "tdesktop"
| "weba"
| "webk"
| "unigram",
) => Telegram.WebApp.platform === name

const isPlatformUnknown = isPlatform("unknown")
const isPlatformAndroid = isPlatform("android")
const isPlatformAndroidX = isPlatform("android_x")
const isPlatformIOS = isPlatform("ios")
const isPlatformMacOS = isPlatform("macos")
const isPlatformTDesktop = isPlatform("tdesktop")
const isPlatformWebA = isPlatform("weba")
const isPlatformWebK = isPlatform("webk")
const isPlatformUnigram = isPlatform("unigram")

const featureSupportVersion = {
ClosingConfirmation: "6.2",
Expand Down Expand Up @@ -93,14 +97,6 @@ export function useWebApp() {
isReady: readonly(isReady),
isPlatform,
isPlatformUnknown,
isPlatformAndroid,
isPlatformAndroidX,
isPlatformIOS,
isPlatformMacOS,
isPlatformTDesktop,
isPlatformWebA,
isPlatformWebK,
isPlatformUnigram,
isFeatureSupported,
canSendData,
}
Expand Down

0 comments on commit 4d87dbc

Please sign in to comment.