Skip to content

Commit c62e896

Browse files
authored
chore: telegram swipe update (#239)
1 parent 4a6102d commit c62e896

File tree

2 files changed

+51
-48
lines changed
  • apps

2 files changed

+51
-48
lines changed

apps/atrium-telegram/app/utils/init.ts

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,11 @@ export async function init(options: {
2727
initSDK()
2828

2929
// Add Eruda if needed.
30-
if (options.eruda) {
31-
import('eruda').then(({ default: eruda }) => {
32-
eruda.init()
33-
eruda.position({ x: window.innerWidth - 50, y: 0 })
34-
})
35-
}
30+
options.eruda
31+
&& void import('eruda').then(({ default: eruda }) => {
32+
eruda.init()
33+
eruda.position({ x: window.innerWidth - 50, y: 0 })
34+
})
3635

3736
// Telegram for macOS has a ton of bugs, including cases, when the client doesn't
3837
// even response to the "web_app_request_theme" method. It also generates an incorrect
@@ -49,16 +48,18 @@ export async function init(options: {
4948
firstThemeSent = true
5049
tp ||= retrieveLaunchParams().tgWebAppThemeParams
5150
}
52-
return emitEvent('theme_changed', { theme_params: tp })
51+
emitEvent('theme_changed', { theme_params: tp })
52+
return
5353
}
5454

5555
if (event.name === 'web_app_request_safe_area') {
56-
return emitEvent('safe_area_changed', {
56+
emitEvent('safe_area_changed', {
5757
left: 0,
5858
top: 0,
5959
right: 0,
6060
bottom: 0,
6161
})
62+
return
6263
}
6364

6465
next()
@@ -77,30 +78,31 @@ export async function init(options: {
7778
}
7879

7980
if (viewport.mount.isAvailable()) {
80-
viewport.mount().then(() => {
81-
viewport.bindCssVars()
81+
await viewport.mount()
82+
viewport.bindCssVars()
8283

83-
if (viewport.requestFullscreen.isAvailable()) {
84-
viewport.requestFullscreen().finally(() => {
85-
// Wait
86-
setTimeout(() => {
87-
// The app is now in fullscreen
88-
if (window.innerWidth > 600) {
89-
// Application should be in fullscreen mode only on small screens!
90-
viewport.exitFullscreen()
91-
}
92-
}, 50)
93-
})
94-
}
95-
})
84+
if (viewport.requestFullscreen.isAvailable()) {
85+
await viewport.requestFullscreen()
86+
87+
setTimeout(() => {
88+
// The app is now in fullscreen
89+
if (window.innerWidth > 600) {
90+
// Application should be in fullscreen mode only on small screens!
91+
viewport.exitFullscreen()
92+
}
93+
}, 100)
94+
}
9695
}
9796

98-
closingBehavior.mount.ifAvailable()
99-
closingBehavior.enableConfirmation.ifAvailable()
97+
if (closingBehavior.mount.isAvailable()) {
98+
closingBehavior.mount()
99+
closingBehavior.enableConfirmation()
100+
}
100101

101-
// Disable vertical swipes to prevent app close
102-
swipeBehavior.mount.ifAvailable()
103-
swipeBehavior.disableVertical.ifAvailable()
102+
if (swipeBehavior.mount.isAvailable()) {
103+
swipeBehavior.mount()
104+
swipeBehavior.disableVertical()
105+
}
104106

105107
// Orientation lock
106108
postEvent('web_app_toggle_orientation_lock', {

apps/storefront-telegram/app/utils/init.ts

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -78,30 +78,31 @@ export async function init(options: {
7878
}
7979

8080
if (viewport.mount.isAvailable()) {
81-
viewport.mount().then(() => {
82-
viewport.bindCssVars()
81+
await viewport.mount()
82+
viewport.bindCssVars()
8383

84-
if (viewport.requestFullscreen.isAvailable()) {
85-
viewport.requestFullscreen().finally(() => {
86-
// Wait
87-
setTimeout(() => {
88-
// The app is now in fullscreen
89-
if (window.innerWidth > 600) {
90-
// Application should be in fullscreen mode only on small screens!
91-
viewport.exitFullscreen()
92-
}
93-
}, 50)
94-
})
95-
}
96-
})
84+
if (viewport.requestFullscreen.isAvailable()) {
85+
await viewport.requestFullscreen()
86+
87+
setTimeout(() => {
88+
// The app is now in fullscreen
89+
if (window.innerWidth > 600) {
90+
// Application should be in fullscreen mode only on small screens!
91+
viewport.exitFullscreen()
92+
}
93+
}, 100)
94+
}
9795
}
9896

99-
closingBehavior.mount.ifAvailable()
100-
closingBehavior.enableConfirmation.ifAvailable()
97+
if (closingBehavior.mount.isAvailable()) {
98+
closingBehavior.mount()
99+
closingBehavior.enableConfirmation()
100+
}
101101

102-
// Disable vertical swipes to prevent app close
103-
swipeBehavior.mount.ifAvailable()
104-
swipeBehavior.disableVertical.ifAvailable()
102+
if (swipeBehavior.mount.isAvailable()) {
103+
swipeBehavior.mount()
104+
swipeBehavior.disableVertical()
105+
}
105106

106107
// Orientation lock
107108
postEvent('web_app_toggle_orientation_lock', {

0 commit comments

Comments
 (0)