Skip to content

Commit

Permalink
chore: fullscreen now correct on desktop (#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
hmbanan666 authored Dec 1, 2024
1 parent 91adfda commit 29241d9
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 30 deletions.
12 changes: 0 additions & 12 deletions apps/telegram-game/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,5 @@
</template>

<script setup lang="ts">
import { exitFullscreen, isFullScreen } from '@telegram-apps/sdk-vue'
import { useWindowSize } from '@vueuse/core'
useBackButton()
// Application is in fullscreen mode only on small screens!
const { width } = useWindowSize()
watch(width, () => {
if (width.value > 600 && isFullScreen()) {
exitFullscreen()
}
})
</script>
1 change: 0 additions & 1 deletion apps/telegram-game/src/assets/logo.svg

This file was deleted.

19 changes: 15 additions & 4 deletions apps/telegram-game/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import {
backButton,
closingBehavior,
disableVerticalSwipes,
fullScreen,
initData,
init as initSDK,
miniApp,
requestFullscreen,
swipeBehavior,
themeParams,
viewport,
Expand All @@ -33,6 +33,7 @@ export function init(debug: boolean): void {
miniApp.mount()
themeParams.mount()
swipeBehavior.mount()
fullScreen.mount()
closingBehavior.mount()
initData.restore()
void viewport
Expand All @@ -42,6 +43,19 @@ export function init(debug: boolean): void {
})
.then(() => {
viewport.bindCssVars()

if (viewport.requestFullscreen.isAvailable()) {
void viewport.requestFullscreen().finally(() => {
// Wait
setTimeout(() => {
// The app is now in fullscreen
if (window.innerWidth > 600) {
// Application should be in fullscreen mode only on small screens!
viewport.exitFullscreen()
}
}, 50)
})
}
})

// Define components-related CSS variables.
Expand All @@ -54,9 +68,6 @@ export function init(debug: boolean): void {
if (closingBehavior.enableConfirmation.isAvailable()) {
closingBehavior.enableConfirmation()
}
if (requestFullscreen.isAvailable()) {
void requestFullscreen()
}

// It will listen for changes in viewport size (even with the changes by opening a Virtual Keyboard), then apply the correct size into body of HTML.
if (window.visualViewport) {
Expand Down
13 changes: 0 additions & 13 deletions apps/telegram-game/src/views/GameView.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
<template>
<PageContainer :back="false" />
</template>

<script setup lang="ts">
import { exitFullscreen, isFullScreen } from '@telegram-apps/sdk-vue'
import { useWindowSize } from '@vueuse/core'
const { width } = useWindowSize()
watch(width, () => {
if (width.value > 600 && isFullScreen()) {
exitFullscreen()
}
})
</script>
2 changes: 2 additions & 0 deletions apps/telegram-game/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import process from 'node:process'
import { fileURLToPath, URL } from 'node:url'

import tailwindcss from '@tailwindcss/vite'
Expand Down Expand Up @@ -44,6 +45,7 @@ export default defineConfig({
createConfig(),
Terminal({
output: 'terminal',
console: process.env.NODE_ENV === 'development' ? 'terminal' : undefined,
}),
],
server: {
Expand Down

0 comments on commit 29241d9

Please sign in to comment.