bb4f0c265d
Split mobile and tablet breakpoints, restore desktop-style reading on landscape tablets, and lock Android tablet apps to landscape. Co-authored-by: Cursor <cursoragent@cursor.com>
26 lines
798 B
TypeScript
26 lines
798 B
TypeScript
/** Android 平板 PWA 安装后默认锁定横屏 */
|
|
export function initTabletLandscape() {
|
|
if (typeof window === 'undefined') return
|
|
|
|
function tryLockLandscape() {
|
|
const isStandalone =
|
|
window.matchMedia('(display-mode: standalone)').matches ||
|
|
(window.navigator as Navigator & { standalone?: boolean }).standalone
|
|
|
|
if (!isStandalone || !/Android/i.test(navigator.userAgent)) return
|
|
|
|
const shortestSide = Math.min(window.screen.width, window.screen.height)
|
|
if (shortestSide < 600) return
|
|
|
|
const lock = screen.orientation?.lock?.bind(screen.orientation)
|
|
if (!lock) return
|
|
|
|
lock('landscape-primary').catch(() => {
|
|
lock('landscape').catch(() => {})
|
|
})
|
|
}
|
|
|
|
tryLockLandscape()
|
|
window.addEventListener('orientationchange', tryLockLandscape)
|
|
}
|