Vlad Chikalkin 49df4365ca
Feature/telegram integration (#4)
* add files from official template

* remove all official template trash
2024-12-11 16:00:55 +03:00

46 lines
1.1 KiB
TypeScript

/* eslint-disable no-console */
/* eslint-disable promise/prefer-await-to-then */
import {
backButton,
$debug as debugSDK,
initData,
init as initSDK,
miniApp,
themeParams,
viewport,
} from '@telegram-apps/sdk-react';
/**
* Initializes the application and configures its dependencies.
*/
export function init(debug: boolean): void {
// Set @telegram-apps/sdk-react debug mode.
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();
themeParams.mount();
initData.restore();
void viewport
.mount()
.then(() => {
// Define components-related CSS variables.
viewport.bindCssVars();
miniApp.bindCssVars();
themeParams.bindCssVars();
})
.catch((error) => {
console.error('Something went wrong mounting the viewport', error);
});
// Add Eruda if needed.
if (debug) {
import('eruda').then((library) => library.default.init()).catch(console.error);
}
}