v9.2 follow-up: skip ms-word on Mac by default + sideload notes
- Web: ยิง ms-word:ofe คู่กับการดาวน์โหลดเฉพาะ non-Mac โดย default — บน Mac ไม่ยิงเพราะ Word 16.101+ เมิน URL แล้วเด้งหน้าเลือกไฟล์ ทุกครั้งจนรำคาญ (override ด้วย NUXT_PUBLIC_OPEN_IN_WORD=on|off) - CLAUDE.md: จดสูตร sideload บน Mac — ปิด Word ก่อน npm start (Word อ่าน manifest ตอน startup เท่านั้น), ปล่อย dev server รันทิ้ง, แก้โค้ดใช้ hot reload - Spec/plan sync + web 60/60 + build; QA reviewer PASS (1 round, minors 3 — แก้ 2 ปฏิเสธ 1 พร้อมเหตุผล) Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
parent
ee4d8573ee
commit
83a949cfa0
7 changed files with 52 additions and 10 deletions
|
|
@ -4,6 +4,14 @@ import { versionDownloadPath, wordOpenUrl, type VersionFormat } from '../utils/v
|
|||
/** Shared by history and generate success — ลิงก์เปิดอายุสั้นของ backend (open-link) ใช้ทั้งดาวน์โหลดและเปิดแบบ best-effort */
|
||||
export function useVersionOpen() {
|
||||
const { apiJson } = useApi()
|
||||
// อ่านตอน setup (มี nuxt context) — จะยิง ms-word:ofe ควบคู่กับการดาวน์โหลดหรือไม่
|
||||
// (v9.2): Word for Mac 16.101+ เมิน URL ทุกรูปแบบและเด้งหน้าเลือกไฟล์ทุกครั้ง — default
|
||||
// จึงไม่ยิงบน Mac; override ด้วย env NUXT_PUBLIC_OPEN_IN_WORD=on|off เพื่อบังคับทุกแพลตฟอร์ม
|
||||
const openInWord = String(useRuntimeConfig().public.openInWord ?? '').toLowerCase()
|
||||
const isMac = typeof navigator !== 'undefined'
|
||||
&& /Mac/i.test(navigator.platform || navigator.userAgent)
|
||||
const fireWordScheme = openInWord === 'on' ? true : openInWord === 'off' ? false : !isMac
|
||||
|
||||
const openingVersionId = ref<string | null>(null)
|
||||
const downloadError = ref<string | null>(null)
|
||||
const fallbackUrl = ref<string | null>(null)
|
||||
|
|
@ -32,17 +40,17 @@ export function useVersionOpen() {
|
|||
}
|
||||
|
||||
/** เปิดไฟล์ docx แบบ download-first (v9.2): ดาวน์โหลดไฟล์ให้ทันทีทุกครั้ง แล้วยิง ms-word:ofe
|
||||
* ควบคู่แบบ best-effort เผื่อเครื่องที่ scheme ยังทำงาน (Windows / Word รุ่นก่อน) —
|
||||
* เลิกพึ่ง heuristic การสลับแอป เพราะ Word for Mac 16.101+ (ก.ย. 2026) เมิน URL ทุกรูปแบบ
|
||||
* โดยเด้งหน้าเลือกไฟล์ (เหมือนสลับแอปจริง — heuristic โดนหลอกจนไม่ดาวน์โหลดให้)
|
||||
* ควบคู่แบบ best-effort เฉพาะเมื่อ fireWordScheme (default: ไม่ยิงบน Mac — ดูคอมเมนต์ด้านบน)
|
||||
* ใช้กับลิงก์ที่ถืออยู่เองได้เลย (ไฟล์ร่าง FR-16: response ของ generate-draft คือ URL แล้ว) */
|
||||
function openDocxUrl(url: string) {
|
||||
resetOpen()
|
||||
fallbackUrl.value = url
|
||||
saveToDownloads(url)
|
||||
openNotice.value =
|
||||
'ดาวน์โหลดไฟล์แล้วที่โฟลเดอร์ Downloads — เปิดจากที่นั่นได้เลย (บางเครื่อง Word จะเปิดให้อัตโนมัติ)'
|
||||
window.location.assign(wordOpenUrl(url))
|
||||
openNotice.value = fireWordScheme
|
||||
? 'ดาวน์โหลดไฟล์แล้วที่โฟลเดอร์ Downloads — เปิดจากที่นั่นได้เลย (บางเครื่อง Word จะเปิดให้อัตโนมัติ)'
|
||||
: 'ดาวน์โหลดไฟล์แล้วที่โฟลเดอร์ Downloads — เปิดจากที่นั่นได้เลย'
|
||||
if (fireWordScheme)
|
||||
window.location.assign(wordOpenUrl(url))
|
||||
}
|
||||
|
||||
async function openVersion(documentId: string, versionId: string, format: VersionFormat = 'docx') {
|
||||
|
|
|
|||
|
|
@ -27,6 +27,9 @@ export default defineNuxtConfig({
|
|||
// Keycloak dev ใช้ https:8443 (cert ของ office-addin-dev-certs — เชื่อถือได้ในเครื่อง)
|
||||
keycloakAuthority: 'https://localhost:8443/realms/word-versioning',
|
||||
keycloakClientId: 'word-versioning-web',
|
||||
// ยิง ms-word:ofe ควบคู่กับการดาวน์โหลดหรือไม่ — '' = auto (ไม่ยิงบน Mac เพราะ Word 16.101+
|
||||
// เมิน URL ทุกรูปแบบและเด้งหน้าเลือกไฟล์รำคาญ, ยิงบน Windows/อื่นๆ), 'on'/'off' = บังคับทุกที่ (v9.2)
|
||||
openInWord: '',
|
||||
},
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ function mount() {
|
|||
|
||||
beforeEach(() => {
|
||||
vi.stubGlobal('useApi', () => ({ apiJson }))
|
||||
// default: auto — happy-dom ไม่ใช่ Mac UA จึงยิง ms-word ควบคู่ (แต่ละ test ที่ต้องการก็ stub ทับได้)
|
||||
vi.stubGlobal('useRuntimeConfig', () => ({ public: { openInWord: '' } }))
|
||||
tab = { opener: {}, closed: false, location: { replace }, close }
|
||||
vi.spyOn(window, 'open').mockReturnValue(tab as unknown as Window)
|
||||
})
|
||||
|
|
@ -130,4 +132,28 @@ describe('version open lifecycle', () => {
|
|||
expect(saved[1].href).toBe('https://files.example/second.docx')
|
||||
expect(state.fallbackUrl.value).toBe('https://files.example/second.docx')
|
||||
})
|
||||
it('OPEN_IN_WORD=off: ไม่ยิง ms-word เลย — ดาวน์โหลดอย่างเดียว (Word 16.101+ บน Mac เด้งหน้าเลือกไฟล์ทุกครั้ง)', () => {
|
||||
vi.stubGlobal('useRuntimeConfig', () => ({ public: { openInWord: 'off' } }))
|
||||
const assign = vi.spyOn(window.location, 'assign').mockImplementation(() => {})
|
||||
vi.spyOn(HTMLAnchorElement.prototype, 'click').mockImplementation(() => {})
|
||||
const state = mount()
|
||||
state.openDocxUrl('https://files.example/draft.docx')
|
||||
expect(assign).not.toHaveBeenCalled()
|
||||
expect(state.openNotice.value).not.toContain('อัตโนมัติ') // ข้อความไม่เกี้ยวเรื่องเปิดอัตโนมัติ
|
||||
})
|
||||
it('auto บน Mac: ไม่ยิง ms-word (default), override on แล้วยิงแม้บน Mac', () => {
|
||||
vi.spyOn(window.navigator, 'platform', 'get').mockReturnValue('MacIntel')
|
||||
let state = mount() // default '' → auto → Mac = ไม่ยิง
|
||||
const assign = vi.spyOn(window.location, 'assign').mockImplementation(() => {})
|
||||
vi.spyOn(HTMLAnchorElement.prototype, 'click').mockImplementation(() => {})
|
||||
state.openDocxUrl('https://files.example/draft.docx')
|
||||
expect(assign).not.toHaveBeenCalled()
|
||||
|
||||
app.unmount()
|
||||
host.remove()
|
||||
vi.stubGlobal('useRuntimeConfig', () => ({ public: { openInWord: 'on' } }))
|
||||
state = mount()
|
||||
state.openDocxUrl('https://files.example/draft.docx')
|
||||
expect(assign).toHaveBeenCalledWith('ms-word:ofe|u|https://files.example/draft.docx')
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue