Skip to content

Commit

Permalink
feat(mobile): add device detection and screen orientation locking
Browse files Browse the repository at this point in the history
  • Loading branch information
lgmarchi committed Nov 28, 2024
1 parent ea8c4b3 commit dca0020
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/lib/utils/Mobile.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import { Device } from "@capacitor/device"

export function checkMobile(): boolean {
return window.matchMedia("screen and (max-width: 800px)").matches
}

export async function isAndroidOriOS(): Promise<boolean> {
const info = await Device.getInfo()
return info.platform === "ios" || info.platform === "android"
}
14 changes: 14 additions & 0 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import InstallBanner from "$lib/components/ui/InstallBanner.svelte"
import Market from "$lib/components/market/Market.svelte"
import { swipe } from "$lib/components/ui/Swipe"
import { ScreenOrientation } from "@capacitor/screen-orientation"
import { isAndroidOriOS } from "$lib/utils/Mobile"
log.debug("Initializing app, layout routes page.")
Expand Down Expand Up @@ -264,7 +266,19 @@
isLocaleSet = true
}
const lockOrientation = async () => {
try {
await ScreenOrientation.lock({ orientation: "portrait" })
log.info("Screen orientation locked to portrait.")
} catch (error) {
console.error("Failed to lock screen orientation:", error)
}
}
onMount(async () => {
if (await isAndroidOriOS()) {
lockOrientation()
}
await checkIfUserIsLogged($page.route.id)
await initializeLocale()
buildStyle()
Expand Down

0 comments on commit dca0020

Please sign in to comment.