40 lines
913 B
TypeScript

/* eslint-disable no-console */
/* eslint-disable promise/prefer-await-to-then */
import {
backButton,
$debug as debugSDK,
initData,
init as initSDK,
miniApp,
swipeBehavior,
} from '@telegram-apps/sdk-react';
/**
* Initializes the application and configures its dependencies.
*/
export async function init(debug: boolean): Promise<void> {
// Set @telegram-apps/sdk-react debug mode.
if (debug) debugSDK.set(debug);
// Initialize special event handlers for Telegram Desktop, Android, iOS, etc.
// Also, configure the package.
initSDK();
// Mount all components used in the project.
if (backButton.isSupported()) {
backButton.mount();
}
miniApp.mount();
initData.restore();
if (swipeBehavior.mount.isAvailable()) {
swipeBehavior.mount();
}
// Add Eruda if needed.
if (debug) import('eruda').then((library) => library.default.init()).catch(console.error);
}