mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-05-23 01:09:50 +08:00
修复下拉快速访问
This commit is contained in:
@@ -63,9 +63,24 @@ export const checkPWAStatus = async () => {
|
||||
hasPWAFeatures: hasServiceWorker,
|
||||
// 是否在独立显示模式下运行
|
||||
isStandaloneMode,
|
||||
// 综合判断:至少满足一个条件就认为是PWA环境
|
||||
isPWAEnvironment: hasServiceWorker || isStandaloneMode,
|
||||
// 综合判断:更宽松的检测,在移动设备上默认启用PWA功能
|
||||
isPWAEnvironment: hasServiceWorker || isStandaloneMode || isMobileDevice(),
|
||||
// 完整的PWA体验:既有功能又在独立模式下运行
|
||||
isFullPWA: hasServiceWorker && isStandaloneMode,
|
||||
}
|
||||
}
|
||||
|
||||
// 检测是否为移动设备
|
||||
const isMobileDevice = (): boolean => {
|
||||
// 检查用户代理字符串
|
||||
const userAgent = navigator.userAgent || ''
|
||||
const mobileRegex = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini|Mobile|mobile|CriOS/i
|
||||
|
||||
// 检查触摸屏支持
|
||||
const hasTouchScreen = 'ontouchstart' in window || navigator.maxTouchPoints > 0
|
||||
|
||||
// 检查屏幕尺寸(小于768px认为是移动设备)
|
||||
const isMobileSize = window.innerWidth < 768
|
||||
|
||||
return mobileRegex.test(userAgent) || hasTouchScreen || isMobileSize
|
||||
}
|
||||
|
||||
@@ -19,22 +19,23 @@ async function initializePWAGlobally() {
|
||||
|
||||
if (globalPwaStatus.value !== null || globalLoading.value) return Promise.resolve()
|
||||
|
||||
initPromise = new Promise(async (resolve, reject) => {
|
||||
initPromise = new Promise(async resolve => {
|
||||
globalLoading.value = true
|
||||
try {
|
||||
globalPwaStatus.value = await checkPWAStatus()
|
||||
resolve()
|
||||
} catch (error) {
|
||||
console.error('Failed to detect PWA status', error)
|
||||
// 即使检测失败,也设置一个合理的默认值
|
||||
globalPwaStatus.value = {
|
||||
hasPWAFeatures: false,
|
||||
isStandaloneMode: isPWADisplayMode(),
|
||||
isPWAEnvironment: isPWADisplayMode(),
|
||||
isFullPWA: false,
|
||||
}
|
||||
reject(error)
|
||||
} finally {
|
||||
globalLoading.value = false
|
||||
// 无论成功还是失败,都解决Promise
|
||||
resolve()
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -219,7 +219,7 @@ export function usePullDownGesture(options: PullDownOptions = {}) {
|
||||
let eventsAdded = false
|
||||
|
||||
const addEventListeners = () => {
|
||||
if (!eventsAdded && appMode.value && display.mdAndDown.value) {
|
||||
if (!eventsAdded && appMode.value) {
|
||||
document.addEventListener('touchstart', handleTouchStart, { passive: false })
|
||||
document.addEventListener('touchmove', handleTouchMove, { passive: false })
|
||||
document.addEventListener('touchend', handleTouchEnd, { passive: true })
|
||||
@@ -238,23 +238,18 @@ export function usePullDownGesture(options: PullDownOptions = {}) {
|
||||
|
||||
// PWA状态确定后,一次性决定是否添加事件监听器
|
||||
onMounted(() => {
|
||||
// 如果PWA已经检测完成,直接添加事件监听器
|
||||
if (appMode.value !== null) {
|
||||
addEventListeners()
|
||||
} else {
|
||||
// 等待PWA检测完成(从null变为boolean)
|
||||
const stopWatcher = watch(
|
||||
appMode,
|
||||
newValue => {
|
||||
if (newValue !== null) {
|
||||
addEventListeners()
|
||||
// PWA状态确定后停止监听
|
||||
stopWatcher()
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
)
|
||||
}
|
||||
// 等待PWA检测完成后添加事件监听器
|
||||
const stopWatcher = watch(
|
||||
appMode,
|
||||
newValue => {
|
||||
if (newValue) {
|
||||
addEventListeners()
|
||||
// PWA状态确定后停止监听
|
||||
stopWatcher()
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
)
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
|
||||
@@ -169,7 +169,7 @@ useScrollLockWithWatch(showPluginQuickAccess)
|
||||
// 检查是否可以使用下拉手势
|
||||
const canUsePullGesture = () => {
|
||||
// 检查是否在dashboard页面
|
||||
const isDashboard = route.name === 'dashboard' || route.path === '/dashboard'
|
||||
const isDashboard = route.path === '/dashboard' || route.path === '/'
|
||||
// 检查是否是管理员
|
||||
const isAdmin = superUser.value
|
||||
// 检查插件快速访问面板是否已显示
|
||||
|
||||
Reference in New Issue
Block a user