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