From d9c45aaeae0872774f254d504d302b510b49f3d7 Mon Sep 17 00:00:00 2001 From: Neil Sleightholm Date: Thu, 26 Nov 2026 15:47:31 +0700 Subject: [PATCH] Upload message: fade once the path is at the prompt (2.5.11) After an upload the header kept the full path until something else replaced it. Show a 5-second 'Inserted ' note instead, and keep the tap-to-copy path only when the path could not be typed at the prompt. setStatus now drops the previous message's timer and tap handler, so a tap no longer copies an old path and an old timer can't clear a newer message. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 2 +- claude-terminal/CHANGELOG.md | 9 ++ claude-terminal/config.yaml | 2 +- .../image-service/public/index.html | 109 ++++++------------ tests/browser/package.json | 2 +- tests/browser/test-upload-status.mjs | 108 +++++++++++++++++ 6 files changed, 155 insertions(+), 77 deletions(-) create mode 100644 tests/browser/test-upload-status.mjs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 38b1cf8d..e6edad84 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -80,7 +80,7 @@ jobs: npm ci --ignore-scripts npx playwright install --with-deps chromium webkit - - name: Real touch taps preserve terminal input and focus + - name: Touch key bar and upload status message in real browsers working-directory: tests/browser run: npm test diff --git a/claude-terminal/CHANGELOG.md b/claude-terminal/CHANGELOG.md index 680f6850..3f462af1 100644 --- a/claude-terminal/CHANGELOG.md +++ b/claude-terminal/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## 2.5.11 + +### 🛠️ Improvement - Upload Message Fades +- **The header no longer keeps the full path of the last upload**: after a paste, drop or 📎 upload, the panel typed the path at the prompt and also showed it in the header until something else replaced it. The path is already at the prompt, and on a phone the message took up half the header + - When the path is typed at the prompt, the header now shows `📋 Inserted ` for 5 seconds, like other messages + - Only when the path couldn't be typed at the prompt does the full path stay, and a tap copies it +- **Fixed: tapping the header could copy an old path**: the tap-to-copy action stayed after a later message replaced the upload message. It now goes with the message, and an earlier message's 5-second timer can no longer clear a newer one +- New browser test (Chromium and WebKit) covering both cases + ## 2.5.10 ### 📚 Documentation - Running More Than One Claude diff --git a/claude-terminal/config.yaml b/claude-terminal/config.yaml index 40431930..7bc3f49c 100644 --- a/claude-terminal/config.yaml +++ b/claude-terminal/config.yaml @@ -1,7 +1,7 @@ --- name: "Claude Terminal Pro" description: "Enhanced terminal interface for Anthropic's Claude Code CLI with persistent auth, package management, and image paste support. Fork of heytcass/home-assistant-addons" -version: "2.5.10" +version: "2.5.11" slug: "claude_terminal_pro" init: false diff --git a/claude-terminal/image-service/public/index.html b/claude-terminal/image-service/public/index.html index 119f9359..7bf80f7c 100644 --- a/claude-terminal/image-service/public/index.html +++ b/claude-terminal/image-service/public/index.html @@ -1188,14 +1188,42 @@ const fileInput = document.getElementById('file-input'); const dropZone = document.getElementById('drop-zone'); + let statusTimer = null; + + // A message fades after 5 s unless persistent. Each message replaces + // the last one completely: its fade timer and any tap-to-copy + // handler go too, so an old timer can't clear a newer message and a + // tap never copies a path that is no longer shown. function setStatus(message, type = '', persistent = false) { + clearTimeout(statusTimer); status.textContent = message; status.className = type; + status.onclick = null; + status.style.cursor = ''; + status.style.userSelect = ''; if (message && !persistent) { - setTimeout(() => setStatus(''), 5000); + statusTimer = setTimeout(() => setStatus(''), 5000); } } + // Only when a path could not be typed at the prompt: it stays until + // replaced, and a tap copies it, so it can still be pasted. + function showCopyablePath(filePath) { + setStatus(`📋 ${filePath} (tap to copy)`, 'success', true); + status.style.cursor = 'pointer'; + status.style.userSelect = 'text'; + status.onclick = async () => { + if (await copyToClipboard(filePath)) { + setStatus('✓ Copied', 'success', true); + statusTimer = setTimeout(() => showCopyablePath(filePath), 2000); + } else { + // Left selectable, so it can be copied by hand + setStatus(`📋 ${filePath} (select and copy)`, 'error', true); + status.style.userSelect = 'text'; + } + }; + } + // Files on the clipboard. A copied image, or files copied in Finder or // Explorer (Safari and recent Chrome/Edge). Text pastes return none. function pastedFiles(e) { @@ -1246,77 +1274,9 @@ const result = await response.json(); if (result.success) { - const filePath = result.path; - - // Display full path persistently with click-to-copy functionality - setStatus(`📋 ${filePath} (click to select)`, 'success', true); - console.log('File uploaded:', filePath); - - // Make status clickable to select text (works in iframes) - status.style.cursor = 'pointer'; - status.style.userSelect = 'text'; - - status.onclick = () => { - // Try modern clipboard API first - if (navigator.clipboard && navigator.clipboard.writeText) { - navigator.clipboard.writeText(filePath) - .then(() => { - const originalText = status.textContent; - setStatus('✓ Copied!', 'success', false); - setTimeout(() => { - setStatus(originalText, 'success', true); - }, 2000); - }) - .catch(() => { - selectText(); - }); - } else { - // Fallback: select the text so user can copy with Cmd+C - selectText(); - } - }; - - // Insert the path at the terminal prompt - autoCopyAndPaste(filePath); - - // Helper to select text (works in all contexts) - function selectText() { - const range = document.createRange(); - const selection = window.getSelection(); - - // Clear any existing selection - selection.removeAllRanges(); - - // Create a temporary text node with just the path - const tempDiv = document.createElement('div'); - tempDiv.style.position = 'absolute'; - tempDiv.style.left = '-9999px'; - tempDiv.textContent = result.path; - document.body.appendChild(tempDiv); - - // Select the path text - range.selectNodeContents(tempDiv); - selection.addRange(range); - - // Try execCommand as fallback for copying - try { - const copied = document.execCommand('copy'); - if (copied) { - setStatus('✓ Copied! (Cmd+C)', 'success', false); - } else { - setStatus('✓ Selected! Press Cmd+C to copy', 'success', false); - } - } catch (err) { - setStatus('✓ Selected! Press Cmd+C to copy', 'success', false); - } - - // Clean up and restore message - setTimeout(() => { - document.body.removeChild(tempDiv); - selection.removeAllRanges(); - setStatus(`📋 ${result.path} (click to select)`, 'success', true); - }, 3000); - } + console.log('File uploaded:', result.path); + // Type the path at the prompt + autoCopyAndPaste(result.path); } else { setStatus(result.error || 'Upload failed', 'error'); } @@ -1397,13 +1357,14 @@ if (term && typeof term.paste === 'function') { term.paste(filePath + ' '); term.focus(); - setStatus(`📋 ${filePath} - inserted at prompt`, 'success', true); + // The prompt shows the full path, so the name is enough + setStatus(`📋 Inserted ${filePath.split('/').pop()}`, 'success'); return; } } catch (err) { console.log('Cannot reach terminal for auto-insert:', err); } - setStatus(`📋 ${filePath} (click to copy)`, 'success', true); + showCopyablePath(filePath); } // Helper to copy text to clipboard diff --git a/tests/browser/package.json b/tests/browser/package.json index 5ef49766..04c96817 100644 --- a/tests/browser/package.json +++ b/tests/browser/package.json @@ -2,7 +2,7 @@ "name": "claude-terminal-browser-tests", "private": true, "scripts": { - "test": "node test-key-bar.mjs" + "test": "node test-key-bar.mjs && node test-upload-status.mjs" }, "devDependencies": { "playwright": "1.64.1" diff --git a/tests/browser/test-upload-status.mjs b/tests/browser/test-upload-status.mjs new file mode 100644 index 00000000..babd6309 --- /dev/null +++ b/tests/browser/test-upload-status.mjs @@ -0,0 +1,108 @@ +// The header message after an upload: a short note that fades when the path +// was typed at the prompt, and a tap-to-copy path that stays only when it +// could not be. Runs the real panel page against a fake terminal and upload. +import assert from 'node:assert/strict'; +import http from 'node:http'; +import path from 'node:path'; +import { readFile } from 'node:fs/promises'; +import { chromium, webkit } from 'playwright'; + +const publicDir = new URL('../../claude-terminal/image-service/public/', import.meta.url); +const types = { '.html': 'text/html', '.js': 'text/javascript', '.mjs': 'text/javascript' }; +// ?paste=0 gives a terminal without term.paste, so the path can't be inserted +const terminal = (canPaste) => ``; +let canPaste = true; + +const server = http.createServer(async (req, res) => { + const url = new URL(req.url, 'http://x'); + if (url.pathname === '/upload') { + req.resume(); + res.setHeader('Content-Type', 'application/json'); + res.end(JSON.stringify({ success: true, path: '/data/uploads/20261126-003753-pasted.png' })); + } else if (url.pathname === '/config') { + res.setHeader('Content-Type', 'application/json'); + res.end('{"ttydPort":7681,"uploadDir":"/data/uploads"}'); + } else if (url.pathname.startsWith('/terminal')) { + res.setHeader('Content-Type', 'text/html'); + res.end(terminal(canPaste)); + } else { + const file = url.pathname === '/' ? 'index.html' : url.pathname.slice(1); + try { + const body = await readFile(new URL(file, publicDir)); + res.setHeader('Content-Type', types[path.extname(file)] || 'application/octet-stream'); + res.end(body); + } catch { + res.statusCode = 404; + res.end('{}'); + } + } +}); +await new Promise(resolve => server.listen(0, '127.0.0.1', resolve)); +const base = `http://127.0.0.1:${server.address().port}/`; + +async function openPanel(browser) { + const page = await browser.newPage(); + await page.clock.install(); + await page.goto(base); + await page.waitForFunction(() => document.getElementById('terminal-frame').contentWindow.term); + return page; +} + +async function upload(page) { + await page.setInputFiles('#file-input', { name: 'pasted.png', mimeType: 'image/png', buffer: Buffer.from('png') }); +} + +const statusText = (page) => page.locator('#status').textContent(); + +try { + for (const engine of [chromium, webkit]) { + const browser = await engine.launch(); + const name = engine.name(); + try { + // Inserted: a short note with the file name, which fades + canPaste = true; + let page = await openPanel(browser); + await upload(page); + await page.waitForFunction(() => document.getElementById('status').textContent.includes('Inserted')); + assert.equal(await statusText(page), '📋 Inserted 20261126-003753-pasted.png', `${name}: inserted note`); + const frame = page.frames().find(f => f.url().includes('/terminal')); + assert.deepEqual(await frame.evaluate(() => window.pasted), ['/data/uploads/20261126-003753-pasted.png '], + `${name}: path typed at the prompt once`); + assert.equal(await page.evaluate(() => document.getElementById('status').onclick), null, + `${name}: the inserted note is not tap-to-copy`); + await page.clock.runFor(5100); + assert.equal(await statusText(page), '', `${name}: the inserted note fades`); + await page.close(); + + // Not inserted: the full path stays and a tap copies it + canPaste = false; + page = await openPanel(browser); + await upload(page); + await page.waitForFunction(() => document.getElementById('status').textContent.includes('tap to copy')); + assert.equal(await statusText(page), '📋 /data/uploads/20261126-003753-pasted.png (tap to copy)', + `${name}: copyable path`); + await page.clock.runFor(60000); + assert.match(await statusText(page), /tap to copy/, `${name}: the copyable path stays`); + assert.equal(await page.evaluate(() => typeof document.getElementById('status').onclick), 'function', + `${name}: the path is tap-to-copy`); + + // A later message replaces it completely: no tap handler left + // behind, and the old path's restore can't overwrite it + await page.evaluate(() => setStatus('📥 Pasted into the terminal', 'success')); + assert.equal(await page.evaluate(() => document.getElementById('status').onclick), null, + `${name}: a later message drops the old tap-to-copy handler`); + await page.clock.runFor(5100); + assert.equal(await statusText(page), '', `${name}: the later message fades as usual`); + await page.close(); + console.log(`PASS ${name}: upload note fades, copyable path only when not inserted, no stale tap handler`); + } finally { + await browser.close(); + } + } +} finally { + await new Promise(resolve => server.close(resolve)); +}