Hotfix: auto-download fallback when Word cold-start drops the open URL
ผู้ใช้จริง (Mac): กด "เปิดใน Word" ตอน Word ยังไม่เปิดค้างอยู่ — Word cold-start แล้ว URL event หลุด แสดงหน้า Recent แทนเอกสาร (ข้อจำกัด ms-word:ofe บน macOS; กลไกนี้ผ่าน manual test ตอน Word เปิดอยู่ก่อนแล้ว) - useVersionOpen.openDocxUrl: หน้าต่างรอ 1.5s → 3s และเมื่อไม่เห็นการ สลับแอป → ดาวน์โหลดไฟล์ให้อัตโนมัติ (anchor → presigned attachment) + ข้อความแนะนำเปิดจาก Downloads หรือกดซ้ำเมื่อ Word เปิดอยู่แล้ว — ใช้ร่วมทุกจุดเปิด docx (version rows, v0, ไฟล์ร่าง) PDF ไม่เกี่ยว - Tests: timing edge 2999/3000 + href + notice, ไม่ download เมื่อสลับ แอปจริง, re-click ยกเลิก timer เก่า (web 59/59 + build) - Spec FR-15/16 (~3s + auto-download + หมายเหตุ cold-start) + acceptance-review เพิ่ม manual check item - QA reviewer PASS (1 round; minors 3 — แก้ 1 ยอมรับ 2 พร้อมเหตุผล) Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
parent
b9b227926d
commit
e0558e3cf4
6 changed files with 82 additions and 10 deletions
|
|
@ -12,6 +12,13 @@ export function useVersionOpen() {
|
|||
let generation = 0
|
||||
let pendingTab: Window | null = null
|
||||
|
||||
/**
|
||||
* รอสังเกตการสลับไป Word (blur/visibilitychange) กี่มิลลิวินาทีก่อนสรุปว่าเปิดไม่สำเร็จ —
|
||||
* ยาวพอให้ Word cold-start โอกาสเปิดได้ทัน แต่ไม่นานจนผู้ใช้งง (ms-word:ofe บน macOS ตอน Word
|
||||
* ยังไม่เปิดค้างอยู่มักทำ URL event หลุด → เห็นหน้า Recent แทนเอกสาร — ข้อจำกัดของ platform)
|
||||
*/
|
||||
const WORD_SWITCH_WAIT_MS = 3000
|
||||
|
||||
function resetOpen() {
|
||||
generation++
|
||||
pendingTab?.close()
|
||||
|
|
@ -23,7 +30,18 @@ export function useVersionOpen() {
|
|||
openNotice.value = null
|
||||
}
|
||||
|
||||
/** เปิด presigned docx URL ใน Word ผ่าน ms-word:ofe พร้อม heuristic เตือนเมื่อไม่เห็นการสลับแอป —
|
||||
/** ให้เบราว์เซอร์เซฟ URL ลง Downloads (presigned URL ส่ง disposition: attachment อยู่แล้ว —
|
||||
* หน้าเว็บอยู่ที่เดิม ไม่ navigate ไปไหน) */
|
||||
function saveToDownloads(url: string) {
|
||||
const a = document.createElement('a')
|
||||
a.href = url
|
||||
document.body.append(a)
|
||||
a.click()
|
||||
a.remove()
|
||||
}
|
||||
|
||||
/** เปิด presigned docx URL ใน Word ผ่าน ms-word:ofe — ถ้าไม่เห็นการสลับแอปภายใน WORD_SWITCH_WAIT_MS
|
||||
* ถือว่าเปิดไม่สำเร็จ: ดาวน์โหลดไฟล์ให้อัตโนมัติ + แจ้งผู้ใช้ (กดซ้ำตอน Word เปิดอยู่แล้วจะสำเร็จ)
|
||||
* ใช้กับลิงก์ที่ถืออยู่เองได้เลย (ไฟล์ร่าง FR-16: response ของ generate-draft คือ URL แล้ว) */
|
||||
function openDocxUrl(url: string) {
|
||||
resetOpen()
|
||||
|
|
@ -34,9 +52,13 @@ export function useVersionOpen() {
|
|||
window.addEventListener('blur', onBlur)
|
||||
document.addEventListener('visibilitychange', onVisibility)
|
||||
const timer = window.setTimeout(() => {
|
||||
if (!switched) openNotice.value = 'หาก Word ไม่เปิด กรุณาดาวน์โหลดไฟล์แล้วเปิดใน Word'
|
||||
if (!switched) {
|
||||
openNotice.value =
|
||||
'Word ไม่ได้เปิดเอกสารอัตโนมัติ (มักเกิดตอน Word เพิ่งถูกเปิดขึ้นครั้งแรก) — ดาวน์โหลดไฟล์ให้แล้วที่โฟลเดอร์ Downloads ให้เปิดจากที่นั่น หรือกดเปิดใน Word อีกครั้งเมื่อ Word เปิดอยู่แล้ว'
|
||||
saveToDownloads(url)
|
||||
}
|
||||
cleanup()
|
||||
}, 1500)
|
||||
}, WORD_SWITCH_WAIT_MS)
|
||||
cleanup = () => {
|
||||
window.clearTimeout(timer)
|
||||
window.removeEventListener('blur', onBlur)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue