fix(update): 复制 AI 提示词可用性与升级命令版本 (v0.5.3-local.10)
三个问题一起修:
1. 复制不生效:copyText 只试 navigator.clipboard.writeText,在 webview
(非安全上下文/权限未授予)会抛错直接返回 false,且按钮仍显示原样 →
表现为「点了没反应」。改为三级降级:Clipboard API → execCommand('copy')
→ 再次 Clipboard API;并新增 update.copyFailed 失败态提示(3s)。
2. 按钮颜色太浅:.dsh-wt_updateBtnCopy 原为 rgba(79,142,247,.18) 半透明底
+ #cfe0ff 浅蓝字,在浅色主题上几乎看不见。改为实心强调色 + 白字 + 加粗,
并补 hover/active 反馈。
3. 升级命令用的是当前版本:UPDATE_TGZ 写死 v0.5.3-local.9,不随检测结果变化,
「有新版本」提示里给的却是自己这一版的地址。改为
worktableUpgrade(tag) 按目标版本生成;index.tsx / split.tsx 两个调用点
均传 updateInfo.latest。
测试:
- host-transport.test.mjs 调用签名补 tag 参数
- 新增断言:命令必须指向目标版本(local.10 与 local.9 各验一次)
验证:npm run pack 全绿,双资产同源 sha256 2ff7d45a…。
This commit is contained in:
@@ -37,12 +37,21 @@ export function hostPreviewUrl(
|
||||
|
||||
/** Keep update instructions on the active profile; Desktop must use its bundled CLI. */
|
||||
// 本仓发布在自建 Gitea:它不支持 GitHub 的 /releases/latest/download 简写,
|
||||
// 安装命令必须带具体 tag。这里给固定 tag(随发布更新),避免给出 404 的命令。
|
||||
const UPDATE_TGZ = 'https://gitea.ququclean.com/xiaoqu/dsh-worktable/releases/download/v0.5.3-local.9/dsh-worktable.tgz'
|
||||
// 安装命令必须带具体 tag。tag 由调用方传入(等于检查到的新版本),
|
||||
// 不再写死当前版本——否则「有新版本」提示里给的却是自己这一版的地址。
|
||||
const UPDATE_BASE = 'https://gitea.ququclean.com/xiaoqu/dsh-worktable/releases/download'
|
||||
|
||||
export function worktableUpgrade(protocol = typeof location === 'undefined' ? 'http:' : location.protocol) {
|
||||
export function upgradeCommandFor(tag: string, protocol = typeof location === 'undefined' ? 'http:' : location.protocol): string {
|
||||
const desktop = protocol === 'dsh-app:'
|
||||
const command = 'dsh plugin --profile ' + (desktop ? 'desktop' : 'web') + ' add "' + UPDATE_TGZ + '"'
|
||||
const clean = String(tag || '').trim().replace(/^v/, '')
|
||||
const t = clean ? 'v' + clean : ''
|
||||
const url = t ? UPDATE_BASE + '/' + t + '/dsh-worktable.tgz' : UPDATE_BASE + '/'
|
||||
return 'dsh plugin --profile ' + (desktop ? 'desktop' : 'web') + ' add "' + url + '"'
|
||||
}
|
||||
|
||||
export function worktableUpgrade(tag: string, protocol = typeof location === 'undefined' ? 'http:' : location.protocol) {
|
||||
const desktop = protocol === 'dsh-app:'
|
||||
const command = upgradeCommandFor(tag, protocol)
|
||||
const prompt = desktop
|
||||
? '帮我升级 dsh-worktable。我当前使用官方桌面端:先定位该桌面端自带的 dsh CLI 并准备更新,再提醒我完整退出桌面端。确认退出后使用该 CLI 执行 ' + command + '。不要使用网页端 CLI,不要修改 web profile,不要自动杀进程或重启;完成后提醒我手动重新打开桌面端。'
|
||||
: '帮我升级 dsh-worktable:执行 ' + command + ',完成后提醒我重启 dsh web 并刷新页面'
|
||||
|
||||
@@ -35,7 +35,9 @@ type DockMode = 'footer' | 'float'
|
||||
// 查上游既看不到本仓版本,国内网络也常失败。
|
||||
// 走宿主中转:页面来源是随机端口 127.0.0.1,直连 Gitea 跨源且无 CORS 头会被拦截
|
||||
const UPDATE_API = '/api/worktable/update-check'
|
||||
const { command: UPGRADE_CMD, prompt: UPGRADE_AI, desktop: DESKTOP_HOST } = worktableUpgrade()
|
||||
// 升级命令必须在「检测到新版本」后按该版本生成(见下方 upgrade 系列 useMemo),
|
||||
// 不能用模块级常量——否则提示里给的是当前已装版本的地址。
|
||||
const DESKTOP_HOST = typeof location !== 'undefined' && location.protocol === 'dsh-app:'
|
||||
// 更新提示图标(手绘 SVG,避免 emoji 跨平台渲染差异)
|
||||
const ICON_SYNC = (
|
||||
<svg viewBox="0 0 16 16" aria-hidden>
|
||||
@@ -51,10 +53,33 @@ const ICON_SPARK = (
|
||||
<path d="M12.6 11.2l.5 1.3 1.3.5-1.3.5-.5 1.3-.5-1.3-1.3-.5 1.3-.5z" fill="currentColor" />
|
||||
</svg>
|
||||
)
|
||||
/**
|
||||
* 复制文案:优先 Clipboard API;不可用(webview 非安全上下文、权限未授予、
|
||||
* 或 API 存在但调用被拒)时回退到 execCommand('copy'),再不行用隐藏 textarea + 选区。
|
||||
* 只返回 true 表示「文本确实进了剪贴板」,避免按钮显示 ✓ 却什么都没复制。
|
||||
*/
|
||||
async function copyText(text: string): Promise<boolean> {
|
||||
try {
|
||||
if (navigator.clipboard?.writeText && window.isSecureContext !== false) {
|
||||
await navigator.clipboard.writeText(text)
|
||||
return true
|
||||
}
|
||||
} catch { /* 继续降级 */ }
|
||||
try {
|
||||
const ta = document.createElement('textarea')
|
||||
ta.value = text
|
||||
ta.setAttribute('readonly', '')
|
||||
ta.style.cssText = 'position:fixed;top:0;left:0;width:1px;height:1px;opacity:0;pointer-events:none'
|
||||
document.body.appendChild(ta)
|
||||
ta.select()
|
||||
ta.setSelectionRange(0, ta.value.length)
|
||||
const ok = typeof document.execCommand === 'function' ? document.execCommand('copy') : false
|
||||
document.body.removeChild(ta)
|
||||
if (ok) return true
|
||||
} catch { /* 继续降级 */ }
|
||||
try {
|
||||
if (navigator.clipboard?.writeText) { await navigator.clipboard.writeText(text); return true }
|
||||
} catch { /* fallthrough */ }
|
||||
} catch { /* 全部失败 */ }
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -1092,6 +1117,7 @@ function WorktableSection(props: any) {
|
||||
const updateInfo = newerUpdateInfo(rawUpdateInfo)
|
||||
const [updateCheckOn, setUpdateCheckOn] = useState<boolean>(() => localStorage.getItem('dsh.worktable.updateCheck.v1') !== '0')
|
||||
const [updateCopied, setUpdateCopied] = useState(false)
|
||||
const [updateCopyFailed, setUpdateCopyFailed] = useState(false)
|
||||
const [updateStatus, setUpdateStatus] = useState<'idle' | 'checking' | 'uptodate' | 'failed'>('idle')
|
||||
const updateCheckingRef = useRef(false)
|
||||
const updateAliveRef = useRef(true)
|
||||
@@ -1131,9 +1157,22 @@ function WorktableSection(props: any) {
|
||||
}
|
||||
}, [])
|
||||
useEffect(() => { if (updateCheckOn) void checkUpdates() }, [updateCheckOn, checkUpdates])
|
||||
// 升级命令/提示按「检测到的新版本」生成:给出的是要装的版本,而不是当前已装版本。
|
||||
const upgrade = useMemo(
|
||||
() => worktableUpgrade(updateInfo?.latest ?? LOCAL_VERSION),
|
||||
[updateInfo?.latest],
|
||||
)
|
||||
const copyUpgradeAi = async () => {
|
||||
const ok = await copyText(UPGRADE_AI)
|
||||
if (ok) { setUpdateCopied(true); setTimeout(() => setUpdateCopied(false), 2200) }
|
||||
const ok = await copyText(upgrade.prompt)
|
||||
if (ok) {
|
||||
setUpdateCopyFailed(false)
|
||||
setUpdateCopied(true)
|
||||
setTimeout(() => setUpdateCopied(false), 2200)
|
||||
} else {
|
||||
// 复制失败要让用户看见,否则就是「点了没反应」
|
||||
setUpdateCopyFailed(true)
|
||||
setTimeout(() => setUpdateCopyFailed(false), 3000)
|
||||
}
|
||||
}
|
||||
const skipUpdate = () => {
|
||||
if (updateInfo) {
|
||||
@@ -2749,10 +2788,10 @@ function buildCustomLayoutPrompt(req: string): string {
|
||||
<div className="dsh-wt_updateHead"><span className="dsh-wt_updateDot" />{t('update.available')} · v{updateInfo.latest}</div>
|
||||
<div className="dsh-wt_updateVers">{t('update.current')} v{LOCAL_VERSION} → v{updateInfo.latest}</div>
|
||||
{updateInfo.notes && <div className="dsh-wt_updateNotes">{updateInfo.notes}</div>}
|
||||
<div className="dsh-wt_updateCmd">{UPGRADE_CMD}</div>
|
||||
<div className="dsh-wt_updateCmd">{upgrade.command}</div>
|
||||
<div className="dsh-wt_updateBtns">
|
||||
<button type="button" className="dsh-wt_updateBtn dsh-wt_updateBtnCopy" onClick={() => void copyUpgradeAi()}>
|
||||
{updateCopied ? '✓ ' + t('update.copied') : <>{ICON_SPARK} {t('update.copyAi')}</>}
|
||||
{updateCopied ? '✓ ' + t('update.copied') : updateCopyFailed ? '⚠ ' + t('update.copyFailed') : <>{ICON_SPARK} {t('update.copyAi')}</>}
|
||||
</button>
|
||||
<button type="button" className="dsh-wt_updateBtn" onClick={skipUpdate}>{t('update.skip')}</button>
|
||||
</div>
|
||||
|
||||
@@ -230,6 +230,7 @@ export const zh = {
|
||||
'update.available': '新版本可用',
|
||||
'update.current': '当前版本',
|
||||
'update.copyAi': '复制 AI 提示词',
|
||||
'update.copyFailed': '复制失败,请手动选中命令',
|
||||
'update.skip': '忽略此版本',
|
||||
'update.autoCheck': '自动检查更新',
|
||||
'update.checkNow': '立即检查',
|
||||
@@ -472,6 +473,7 @@ export const en = {
|
||||
'update.available': 'New version available',
|
||||
'update.current': 'Current version',
|
||||
'update.copyAi': 'Copy AI prompt',
|
||||
'update.copyFailed': 'Copy failed, select the command manually',
|
||||
'update.skip': 'Skip this version',
|
||||
'update.autoCheck': 'Auto-check updates',
|
||||
'update.checkNow': 'Check now',
|
||||
|
||||
@@ -492,8 +492,8 @@ function boxPayload(x0: number, y0: number, x1: number, y1: number): { primary:
|
||||
return { primary, line, candidates, limited, src }
|
||||
}
|
||||
|
||||
/** 更新方法:复制给 AI 的升级指令(插件不自更新;升级由用户或其 Agent 执行 + 重启) */
|
||||
const { prompt: UPGRADE_AI } = worktableUpgrade()
|
||||
/** 更新方法:复制给 AI 的升级指令(插件不自更新;升级由用户或其 Agent 执行 + 重启)。
|
||||
* 命令按「检测到的新版本」生成 —— 见下方 onCopyUpgrade 里的 worktableUpgrade(tag)。 */
|
||||
|
||||
async function copyTextSafe(text: string): Promise<boolean> {
|
||||
try { if (navigator.clipboard?.writeText) { await navigator.clipboard.writeText(text); return true } } catch {}
|
||||
@@ -1764,7 +1764,9 @@ function ConsolePane() {
|
||||
}
|
||||
const [updCopied, setUpdCopied] = useState(false)
|
||||
const onCopyUpgrade = async () => {
|
||||
const ok = await copyTextSafe(UPGRADE_AI)
|
||||
// 按检测到的新版本生成命令;没有新版本时退回当前版本(保持原有可复制行为)
|
||||
const { prompt } = worktableUpgrade(updInfo?.latest ?? LOCAL_VERSION)
|
||||
const ok = await copyTextSafe(prompt)
|
||||
if (ok) { setUpdCopied(true); window.setTimeout(() => setUpdCopied(false), 2200) }
|
||||
}
|
||||
const onSkipVersion = () => {
|
||||
|
||||
@@ -656,7 +656,11 @@ export const css = xtermCss + '\n' + [
|
||||
'.dsh-wt_updateBtn svg{width:12px;height:12px;flex:none}',
|
||||
'.dsh-wt_updateBadge svg{width:12px;height:12px;flex:none}',
|
||||
'.dsh-wt_updateBtn:hover{background:var(--dsw-alias-fill-l1,rgba(255,255,255,.06))}',
|
||||
'.dsh-wt_updateBtnCopy{border-color:var(--dsw-alias-state-accent-primary,#4f8ef7);background:rgba(79,142,247,.18);color:#cfe0ff}',
|
||||
// 「复制 AI 提示词」主按钮:原来用 rgba(...,.18) 半透明底 + 浅蓝字,在实际主题上
|
||||
// 对比度极低(截图里几乎看不见)。改为实心强调色 + 白字,hover/active 明确反馈。
|
||||
'.dsh-wt_updateBtnCopy{border-color:transparent;background:var(--dsw-alias-state-accent-primary,#4f8ef7);color:#fff;font-weight:600}',
|
||||
'.dsh-wt_updateBtnCopy:hover{background:var(--dsw-alias-state-accent-primary-hover,#3f7de0);color:#fff}',
|
||||
'.dsh-wt_updateBtnCopy:active{transform:translateY(.5px)}',
|
||||
'.dsh-wt_updateHint{font-size:10.5px;color:var(--dsw-alias-label-tertiary,#7d8aa5)}',
|
||||
'.dsh-wt_versionRow{margin-top:8px;padding-top:8px;border-top:1px solid var(--dsw-alias-border-l1,#262b36);display:flex;align-items:center;justify-content:space-between;font-size:11px;color:var(--dsw-alias-label-tertiary,#7d8aa5)}',
|
||||
'.dsh-wt_updateToggle{display:flex;align-items:center;gap:6px;cursor:pointer;user-select:none}',
|
||||
|
||||
Reference in New Issue
Block a user