From c74643263a7ac5d49820cad7dbd71ddfcd647030 Mon Sep 17 00:00:00 2001 From: Hewston Fox Date: Wed, 18 Mar 2026 21:18:15 +0200 Subject: [PATCH] fix: paje refresh crush --- src/tg/index.ts | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/tg/index.ts b/src/tg/index.ts index 369be55..3ea8542 100644 --- a/src/tg/index.ts +++ b/src/tg/index.ts @@ -5,13 +5,10 @@ export const STORAGE_KEYS = { } as const; export type StorageKey = (typeof STORAGE_KEYS)[keyof typeof STORAGE_KEYS]; -const isRealTelegram = () => { - if (typeof window === "undefined") return false; - const search = location.hash.slice(1) || location.search.slice(1); - return search.includes("tgWebAppData"); -}; +// @ts-expect-error Just for an initial check +const IS_REAL_TG = Boolean(window?.Telegram?.WebApp); -if (!isRealTelegram()) { +if (!IS_REAL_TG) { tg.mockTelegramEnv({ launchParams: { tgWebAppData: new URLSearchParams({ @@ -61,7 +58,7 @@ const fallbackImplementation = < cb: T, onErr: F, ): Async extends true ? Promise : Awaited => { - if (isRealTelegram()) { + if (IS_REAL_TG) { const res = cb.ifAvailable.apply(null, args); const returnValue = (res.ok ? res.data : onErr.apply(null, args)) as Result; if (!async) return returnValue as Async extends true ? Promise : Awaited; @@ -84,9 +81,7 @@ export default { tg.swipeBehavior.disableVertical.ifAvailable(); tg.viewport.expand.ifAvailable(); tg.miniApp.setHeaderColor.ifAvailable("#000000"); - console.log( - isRealTelegram() ? "Telegram Mini App initialized" : "TMA Debug mode in Web initialized", - ); + console.log(IS_REAL_TG ? "Telegram Mini App initialized" : "TMA Debug mode in Web initialized"); console.log(tg.retrieveLaunchParams()); }, openLink(url: string | URL, options?: tg.OpenLinkOptions) {