mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-29 18:13:47 +00:00
fix: wrap all SDK isSupported() calls in try-catch
This commit is contained in:
@@ -88,10 +88,14 @@ export function initTelegramSDK() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Disable vertical swipes if supported (sync)
|
// Disable vertical swipes if supported (sync)
|
||||||
|
try {
|
||||||
if (swipeBehavior.isSupported()) {
|
if (swipeBehavior.isSupported()) {
|
||||||
swipeBehavior.mount();
|
swipeBehavior.mount();
|
||||||
swipeBehavior.disableVertical();
|
swipeBehavior.disableVertical();
|
||||||
}
|
}
|
||||||
|
} catch {
|
||||||
|
// Swipe behavior not available
|
||||||
|
}
|
||||||
|
|
||||||
// Mount viewport and bind CSS variables (async)
|
// Mount viewport and bind CSS variables (async)
|
||||||
viewport
|
viewport
|
||||||
@@ -233,21 +237,33 @@ export function useTelegramSDK() {
|
|||||||
|
|
||||||
const expand = useCallback(() => {
|
const expand = useCallback(() => {
|
||||||
if (!isReady) return;
|
if (!isReady) return;
|
||||||
|
try {
|
||||||
viewport.expand();
|
viewport.expand();
|
||||||
|
} catch {
|
||||||
|
// Viewport not available
|
||||||
|
}
|
||||||
}, [isReady]);
|
}, [isReady]);
|
||||||
|
|
||||||
const disableVerticalSwipes = useCallback(() => {
|
const disableVerticalSwipes = useCallback(() => {
|
||||||
if (!isReady) return;
|
if (!isReady) return;
|
||||||
|
try {
|
||||||
if (swipeBehavior.isSupported()) {
|
if (swipeBehavior.isSupported()) {
|
||||||
swipeBehavior.disableVertical();
|
swipeBehavior.disableVertical();
|
||||||
}
|
}
|
||||||
|
} catch {
|
||||||
|
// Swipe behavior not available
|
||||||
|
}
|
||||||
}, [isReady]);
|
}, [isReady]);
|
||||||
|
|
||||||
const enableVerticalSwipes = useCallback(() => {
|
const enableVerticalSwipes = useCallback(() => {
|
||||||
if (!isReady) return;
|
if (!isReady) return;
|
||||||
|
try {
|
||||||
if (swipeBehavior.isSupported()) {
|
if (swipeBehavior.isSupported()) {
|
||||||
swipeBehavior.enableVertical();
|
swipeBehavior.enableVertical();
|
||||||
}
|
}
|
||||||
|
} catch {
|
||||||
|
// Swipe behavior not available
|
||||||
|
}
|
||||||
}, [isReady]);
|
}, [isReady]);
|
||||||
|
|
||||||
// Check if fullscreen is supported (Bot API 8.0+)
|
// Check if fullscreen is supported (Bot API 8.0+)
|
||||||
|
|||||||
@@ -29,18 +29,26 @@ function getTelegram(): TelegramWebApp | null {
|
|||||||
return window.Telegram?.WebApp ?? null;
|
return window.Telegram?.WebApp ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function safeIsSupported(checkFn: () => boolean): boolean {
|
||||||
|
try {
|
||||||
|
return checkFn();
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function createCapabilities(): PlatformCapabilities {
|
function createCapabilities(): PlatformCapabilities {
|
||||||
const tg = getTelegram();
|
const tg = getTelegram();
|
||||||
const inTelegram = isInTelegramWebApp();
|
const inTelegram = isInTelegramWebApp();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
hasBackButton: inTelegram && backButton.isSupported(),
|
hasBackButton: inTelegram && safeIsSupported(() => backButton.isSupported()),
|
||||||
hasMainButton: inTelegram,
|
hasMainButton: inTelegram,
|
||||||
hasHapticFeedback: inTelegram && hapticFeedback.isSupported(),
|
hasHapticFeedback: inTelegram && safeIsSupported(() => hapticFeedback.isSupported()),
|
||||||
hasNativeDialogs: inTelegram && popup.isSupported(),
|
hasNativeDialogs: inTelegram && safeIsSupported(() => popup.isSupported()),
|
||||||
hasThemeSync: inTelegram,
|
hasThemeSync: inTelegram,
|
||||||
hasInvoice: !!tg?.openInvoice,
|
hasInvoice: !!tg?.openInvoice,
|
||||||
hasCloudStorage: inTelegram && cloudStorage.isSupported(),
|
hasCloudStorage: inTelegram && safeIsSupported(() => cloudStorage.isSupported()),
|
||||||
hasShare: true,
|
hasShare: true,
|
||||||
version: tg?.version,
|
version: tg?.version,
|
||||||
};
|
};
|
||||||
@@ -53,7 +61,7 @@ function createBackButtonController(): BackButtonController {
|
|||||||
// Mount back button on first use
|
// Mount back button on first use
|
||||||
let mounted = false;
|
let mounted = false;
|
||||||
const ensureMounted = () => {
|
const ensureMounted = () => {
|
||||||
if (!mounted && inTelegram && backButton.isSupported()) {
|
if (!mounted && inTelegram && safeIsSupported(() => backButton.isSupported())) {
|
||||||
try {
|
try {
|
||||||
backButton.mount();
|
backButton.mount();
|
||||||
mounted = true;
|
mounted = true;
|
||||||
@@ -74,7 +82,7 @@ function createBackButtonController(): BackButtonController {
|
|||||||
},
|
},
|
||||||
|
|
||||||
show(onClick: () => void) {
|
show(onClick: () => void) {
|
||||||
if (!inTelegram || !backButton.isSupported()) return;
|
if (!inTelegram || !safeIsSupported(() => backButton.isSupported())) return;
|
||||||
|
|
||||||
ensureMounted();
|
ensureMounted();
|
||||||
|
|
||||||
@@ -89,7 +97,7 @@ function createBackButtonController(): BackButtonController {
|
|||||||
},
|
},
|
||||||
|
|
||||||
hide() {
|
hide() {
|
||||||
if (!inTelegram || !backButton.isSupported()) return;
|
if (!inTelegram || !safeIsSupported(() => backButton.isSupported())) return;
|
||||||
|
|
||||||
if (removeClickListener) {
|
if (removeClickListener) {
|
||||||
removeClickListener();
|
removeClickListener();
|
||||||
@@ -193,7 +201,7 @@ function createMainButtonController(): MainButtonController {
|
|||||||
|
|
||||||
function createHapticController(): HapticController {
|
function createHapticController(): HapticController {
|
||||||
const inTelegram = isInTelegramWebApp();
|
const inTelegram = isInTelegramWebApp();
|
||||||
const isSupported = inTelegram && hapticFeedback.isSupported();
|
const isSupported = inTelegram && safeIsSupported(() => hapticFeedback.isSupported());
|
||||||
|
|
||||||
return {
|
return {
|
||||||
impact(style: HapticImpactStyle = 'medium') {
|
impact(style: HapticImpactStyle = 'medium') {
|
||||||
@@ -215,7 +223,7 @@ function createHapticController(): HapticController {
|
|||||||
|
|
||||||
function createDialogController(): DialogController {
|
function createDialogController(): DialogController {
|
||||||
const inTelegram = isInTelegramWebApp();
|
const inTelegram = isInTelegramWebApp();
|
||||||
const isSupported = inTelegram && popup.isSupported();
|
const isSupported = inTelegram && safeIsSupported(() => popup.isSupported());
|
||||||
|
|
||||||
return {
|
return {
|
||||||
alert(message: string, _title?: string): Promise<void> {
|
alert(message: string, _title?: string): Promise<void> {
|
||||||
@@ -337,7 +345,7 @@ function createThemeController(): ThemeController {
|
|||||||
|
|
||||||
function createCloudStorageController(): CloudStorageController | null {
|
function createCloudStorageController(): CloudStorageController | null {
|
||||||
const inTelegram = isInTelegramWebApp();
|
const inTelegram = isInTelegramWebApp();
|
||||||
if (!inTelegram || !cloudStorage.isSupported()) return null;
|
if (!inTelegram || !safeIsSupported(() => cloudStorage.isSupported())) return null;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
async getItem(key: string): Promise<string | null> {
|
async getItem(key: string): Promise<string | null> {
|
||||||
|
|||||||
Reference in New Issue
Block a user