Widen settings forms and fix Token clipboard copy fallback.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-30 13:15:22 +08:00
parent 3556450ff0
commit 7136adcaa9
2 changed files with 46 additions and 5 deletions
+34 -4
View File
@@ -150,6 +150,39 @@ export default function SettingsPage() {
}
}
async function copyToken(text: string) {
setErr("");
setOk("");
try {
if (navigator.clipboard?.writeText) {
await navigator.clipboard.writeText(text);
setOk("已复制到剪贴板");
return;
}
} catch {
/* fall through to legacy copy */
}
try {
const ta = document.createElement("textarea");
ta.value = text;
ta.setAttribute("readonly", "");
ta.style.position = "fixed";
ta.style.left = "-9999px";
document.body.appendChild(ta);
ta.select();
ta.setSelectionRange(0, text.length);
const okCopy = document.execCommand("copy");
document.body.removeChild(ta);
if (okCopy) {
setOk("已复制到剪贴板");
return;
}
} catch {
/* ignore */
}
setErr("复制失败,请手动选中 Token 复制");
}
return (
<div>
<h2></h2>
@@ -297,10 +330,7 @@ export default function SettingsPage() {
<button
type="button"
className="btn ghost"
onClick={() => {
void navigator.clipboard.writeText(lastToken.token);
setOk("已复制到剪贴板");
}}
onClick={() => void copyToken(lastToken.token)}
>
</button>