|
1472 | 1472 | const MULTI_WINDOW_RETURN_BALL_DRAG_SHRINK_SIZE = 160; |
1473 | 1473 | const MULTI_WINDOW_RETURN_BALL_DRAG_SHRINK_FALLBACK_MS = 220; |
1474 | 1474 | const MULTI_WINDOW_RETURN_BALL_DRAG_RESTORE_FALLBACK_MS = 600; |
| 1475 | + const MULTI_WINDOW_RETURN_BALL_REVEAL_FALLBACK_MS = 600; |
1475 | 1476 | let multiWindowReturnBallDragState = null; |
1476 | 1477 | let idleReturnBallDesktopDragStateFrame = 0; |
1477 | 1478 | let idleReturnBallDesktopDragStatePending = null; |
|
2347 | 2348 | restoreSavedReturnBallStyle(container, state); |
2348 | 2349 | } |
2349 | 2350 |
|
2350 | | - async function revealReturnBallDragWindow() { |
| 2351 | + function dispatchReturnBallRevealFailed(reason, error) { |
| 2352 | + scheduleIdleReturnBallDesktopBridge('return-ball-reveal-failed', container); |
| 2353 | + window.dispatchEvent(new CustomEvent('neko:return-ball-reveal-failed', { |
| 2354 | + detail: { |
| 2355 | + reason: reason || 'unknown', |
| 2356 | + container: container, |
| 2357 | + errorMessage: error && (error.message || String(error)) |
| 2358 | + } |
| 2359 | + })); |
| 2360 | + } |
| 2361 | + |
| 2362 | + function revealReturnBallDragWindow() { |
2351 | 2363 | if (!window.nekoPetDrag || typeof window.nekoPetDrag.reveal !== 'function') { |
| 2364 | + dispatchReturnBallRevealFailed('bridge-unavailable'); |
2352 | 2365 | return false; |
2353 | 2366 | } |
| 2367 | + let settled = false; |
| 2368 | + const fallbackTimer = setTimeout(() => { |
| 2369 | + if (settled) return; |
| 2370 | + dispatchReturnBallRevealFailed('reveal-timeout'); |
| 2371 | + }, MULTI_WINDOW_RETURN_BALL_REVEAL_FALLBACK_MS); |
2354 | 2372 | try { |
2355 | | - return await window.nekoPetDrag.reveal(); |
| 2373 | + const revealResult = window.nekoPetDrag.reveal(); |
| 2374 | + Promise.resolve(revealResult).then((ok) => { |
| 2375 | + settled = true; |
| 2376 | + clearTimeout(fallbackTimer); |
| 2377 | + if (ok === false) { |
| 2378 | + dispatchReturnBallRevealFailed('reveal-failed'); |
| 2379 | + } |
| 2380 | + }).catch((error) => { |
| 2381 | + settled = true; |
| 2382 | + clearTimeout(fallbackTimer); |
| 2383 | + console.warn('[App] 返回球拖拽渲染完成后恢复窗口显示失败:', error); |
| 2384 | + dispatchReturnBallRevealFailed('reveal-rejected', error); |
| 2385 | + }); |
| 2386 | + return true; |
2356 | 2387 | } catch (error) { |
| 2388 | + settled = true; |
| 2389 | + clearTimeout(fallbackTimer); |
2357 | 2390 | console.warn('[App] 返回球拖拽渲染完成后恢复窗口显示失败:', error); |
| 2391 | + dispatchReturnBallRevealFailed('reveal-threw', error); |
2358 | 2392 | return false; |
2359 | 2393 | } |
2360 | 2394 | } |
|
2694 | 2728 | if (!isActiveDragToken(dragToken)) return; |
2695 | 2729 | const expectedWidth = restoreBounds ? restoreBounds.width : state.savedWindowW; |
2696 | 2730 | const expectedHeight = restoreBounds ? restoreBounds.height : state.savedWindowH; |
2697 | | - waitForViewportSize(dragToken, expectedWidth, expectedHeight, async () => { |
| 2731 | + waitForViewportSize(dragToken, expectedWidth, expectedHeight, () => { |
2698 | 2732 | restoreSavedBallStyle(); |
2699 | 2733 | delete document.body.dataset.nekoBallDrag; |
2700 | 2734 | container.setAttribute('data-dragging', 'false'); |
2701 | 2735 | scheduleIdleReturnBallDesktopBridge('return-ball-drag-click', container); |
2702 | | - await revealReturnBallDragWindow(); |
| 2736 | + revealReturnBallDragWindow(); |
2703 | 2737 | dispatchReturnBallClick(); |
2704 | 2738 | }, { |
2705 | 2739 | fallbackMs: MULTI_WINDOW_RETURN_BALL_DRAG_RESTORE_FALLBACK_MS, |
|
2734 | 2768 |
|
2735 | 2769 | const expectedWidth = finalBounds ? finalBounds.width : state.savedWindowW; |
2736 | 2770 | const expectedHeight = finalBounds ? finalBounds.height : state.savedWindowH; |
2737 | | - waitForViewportSize(dragToken, expectedWidth, expectedHeight, async () => { |
| 2771 | + waitForViewportSize(dragToken, expectedWidth, expectedHeight, () => { |
2738 | 2772 | if (shouldRestoreSavedBallStyle) { |
2739 | 2773 | restoreSavedBallStyle(); |
2740 | 2774 | container.setAttribute('data-dragging', 'false'); |
|
2747 | 2781 | movedDistancePx: movedDistancePx |
2748 | 2782 | } |
2749 | 2783 | })); |
2750 | | - await revealReturnBallDragWindow(); |
| 2784 | + revealReturnBallDragWindow(); |
2751 | 2785 | return; |
2752 | 2786 | } |
2753 | 2787 | // 先同步恢复球 opacity,再删除 nekoBallDrag 显示页面内容, |
|
2765 | 2799 | movedDistancePx: movedDistancePx |
2766 | 2800 | } |
2767 | 2801 | })); |
2768 | | - await revealReturnBallDragWindow(); |
| 2802 | + revealReturnBallDragWindow(); |
2769 | 2803 | // 延迟恢复 transition,避免恢复瞬间触发动画 |
2770 | 2804 | state.transitionCleanupTimer = setTimeout(() => { |
2771 | 2805 | state.transitionCleanupTimer = null; |
|
0 commit comments