fix(webui): copy and export files on Safari LAN HTTP
Clipboard APIs and instant blob downloads fail on insecure origins and WebKit. Route every export through the shared helpers.
This commit is contained in:
9 files changed
+70
-126
No files matched your search
@@ -27,7 +27,7 @@ import { DropdownSelect, type DropdownOption } from '@/components/ui/dropdown-se
|
|||||||
import { Input } from '@/components/ui/input';
|
import { Input } from '@/components/ui/input';
|
||||||
import { Label } from '@/components/ui/label';
|
import { Label } from '@/components/ui/label';
|
||||||
import { ToggleSwitch } from '@/components/ui/toggle-switch';
|
import { ToggleSwitch } from '@/components/ui/toggle-switch';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn, copyText } from '@/lib/utils';
|
||||||
import {
|
import {
|
||||||
accessTokenFeedback,
|
accessTokenFeedback,
|
||||||
type AccessTokenFeedback,
|
type AccessTokenFeedback,
|
||||||
@@ -413,27 +413,6 @@ interface TokenFieldProps {
|
|||||||
feedback?: AccessTokenFeedback;
|
feedback?: AccessTokenFeedback;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Insecure-context clipboard fallback. Returns true on success.
|
|
||||||
* Cast through a local alias so ts(6387) doesn't flag the call site —
|
|
||||||
* the deprecation tag is on the live signature and we know we're using
|
|
||||||
* the still-supported legacy form on purpose. */
|
|
||||||
function legacyCopyToClipboard(value: string): boolean {
|
|
||||||
try {
|
|
||||||
const ta = document.createElement('textarea');
|
|
||||||
ta.value = value;
|
|
||||||
ta.style.position = 'fixed';
|
|
||||||
ta.style.opacity = '0';
|
|
||||||
document.body.appendChild(ta);
|
|
||||||
ta.select();
|
|
||||||
const exec = (document as unknown as { execCommand(cmd: string): boolean }).execCommand;
|
|
||||||
const ok = exec.call(document, 'copy');
|
|
||||||
document.body.removeChild(ta);
|
|
||||||
return ok;
|
|
||||||
} catch {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Password-style input for the access token. Hidden by default to keep
|
* Password-style input for the access token. Hidden by default to keep
|
||||||
* the value out of over-the-shoulder reads / screenshots; an eye toggle
|
* the value out of over-the-shoulder reads / screenshots; an eye toggle
|
||||||
@@ -448,16 +427,7 @@ function TokenField({ label, value, onChange, onGenerate, placeholder, feedback
|
|||||||
|
|
||||||
const handleCopy = async () => {
|
const handleCopy = async () => {
|
||||||
if (!value) return;
|
if (!value) return;
|
||||||
try {
|
if (!await copyText(value)) return;
|
||||||
await navigator.clipboard.writeText(value);
|
|
||||||
} catch {
|
|
||||||
// navigator.clipboard is undefined on insecure origins (LAN HTTP
|
|
||||||
// outside localhost). Fall back to a transient textarea +
|
|
||||||
// document.execCommand('copy'). The latter is deprecated but every
|
|
||||||
// current browser still honours it and there is no modern
|
|
||||||
// replacement for non-secure-context clipboard writes.
|
|
||||||
if (!legacyCopyToClipboard(value)) return;
|
|
||||||
}
|
|
||||||
setCopied(true);
|
setCopied(true);
|
||||||
if (copiedTimerRef.current != null) window.clearTimeout(copiedTimerRef.current);
|
if (copiedTimerRef.current != null) window.clearTimeout(copiedTimerRef.current);
|
||||||
copiedTimerRef.current = window.setTimeout(() => {
|
copiedTimerRef.current = window.setTimeout(() => {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { Activity, ChevronRight, Download, Pause, Play, RadioTower, Search, Tras
|
|||||||
import { JsonTree } from '@/components/ui/json-tree';
|
import { JsonTree } from '@/components/ui/json-tree';
|
||||||
import { Segmented } from '@/components/debug/segmented';
|
import { Segmented } from '@/components/debug/segmented';
|
||||||
import { useApi } from '@/lib/api';
|
import { useApi } from '@/lib/api';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn, downloadBlob } from '@/lib/utils';
|
||||||
import type { DebugStreamMessage } from '@/types';
|
import type { DebugStreamMessage } from '@/types';
|
||||||
|
|
||||||
const STREAM_CAP = 300;
|
const STREAM_CAP = 300;
|
||||||
@@ -133,17 +133,10 @@ export function LiveActivity() {
|
|||||||
}, [rows, kindFilter, query]);
|
}, [rows, kindFilter, query]);
|
||||||
|
|
||||||
const exportJson = () => {
|
const exportJson = () => {
|
||||||
const blob = new Blob([JSON.stringify(visible.map((r) => ({ at: r.at, ...r.msg })), null, 2)], { type: 'application/json' });
|
downloadBlob(
|
||||||
const url = URL.createObjectURL(blob);
|
new Blob([JSON.stringify(visible.map((r) => ({ at: r.at, ...r.msg })), null, 2)], { type: 'application/json' }),
|
||||||
const a = document.createElement('a');
|
`debug-activity-${visible.length}.json`,
|
||||||
a.href = url;
|
);
|
||||||
a.download = `debug-activity-${visible.length}.json`;
|
|
||||||
document.body.appendChild(a);
|
|
||||||
a.click();
|
|
||||||
a.remove();
|
|
||||||
// Revoke after the download has had a chance to start (immediate revoke
|
|
||||||
// cancels it in some browsers).
|
|
||||||
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import { ScrollArea } from '@/components/ui/scroll-area';
|
|||||||
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';
|
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';
|
||||||
import { ConfirmDialog } from '@/components/confirm-dialog';
|
import { ConfirmDialog } from '@/components/confirm-dialog';
|
||||||
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn, downloadBlob } from '@/lib/utils';
|
||||||
import type { LogEntry, LogLevel, LogsPreset, UiHighlightRule } from '@/types';
|
import type { LogEntry, LogLevel, LogsPreset, UiHighlightRule } from '@/types';
|
||||||
import { useApi } from '@/lib/api';
|
import { useApi } from '@/lib/api';
|
||||||
import {
|
import {
|
||||||
@@ -370,13 +370,8 @@ export function LogsPage() {
|
|||||||
l.line || `${l.time} ${l.level.toUpperCase().padEnd(7)} [${l.scope}] ${l.message}`,
|
l.line || `${l.time} ${l.level.toUpperCase().padEnd(7)} [${l.scope}] ${l.message}`,
|
||||||
));
|
));
|
||||||
const blob = new Blob([lines.join('\n') + '\n'], { type: 'text/plain;charset=utf-8' });
|
const blob = new Blob([lines.join('\n') + '\n'], { type: 'text/plain;charset=utf-8' });
|
||||||
const url = URL.createObjectURL(blob);
|
|
||||||
const a = document.createElement('a');
|
|
||||||
const ts = new Date().toISOString().replace(/[:.]/g, '-').slice(0, 19);
|
const ts = new Date().toISOString().replace(/[:.]/g, '-').slice(0, 19);
|
||||||
a.href = url;
|
downloadBlob(blob, `snowluma-logs-${ts}.log`);
|
||||||
a.download = `snowluma-logs-${ts}.log`;
|
|
||||||
a.click();
|
|
||||||
URL.revokeObjectURL(url);
|
|
||||||
}, [filtered]);
|
}, [filtered]);
|
||||||
|
|
||||||
const exportFullTrace = useCallback(async () => {
|
const exportFullTrace = useCallback(async () => {
|
||||||
@@ -392,13 +387,7 @@ export function LogsPage() {
|
|||||||
},
|
},
|
||||||
() => api.logs.exportTrace(),
|
() => api.logs.exportTrace(),
|
||||||
);
|
);
|
||||||
const blob = new Blob([text], { type: 'text/plain;charset=utf-8' });
|
downloadBlob(new Blob([text], { type: 'text/plain;charset=utf-8' }), filename);
|
||||||
const url = URL.createObjectURL(blob);
|
|
||||||
const a = document.createElement('a');
|
|
||||||
a.href = url;
|
|
||||||
a.download = filename;
|
|
||||||
a.click();
|
|
||||||
URL.revokeObjectURL(url);
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('exportTrace', err);
|
console.error('exportTrace', err);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -421,7 +410,7 @@ export function LogsPage() {
|
|||||||
const levelsFiltered = enabled.size < LEVELS.length;
|
const levelsFiltered = enabled.size < LEVELS.length;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card className="flex h-[calc(100vh-7rem)] min-h-[480px] flex-col overflow-hidden">
|
<Card className="flex h-[calc(100dvh-7rem)] min-h-[480px] flex-col overflow-hidden">
|
||||||
{/* ── Toolbar ─────────────────────────────────────────────── */}
|
{/* ── Toolbar ─────────────────────────────────────────────── */}
|
||||||
<CardHeader className="gap-3 sm:flex-row sm:items-start sm:justify-between">
|
<CardHeader className="gap-3 sm:flex-row sm:items-start sm:justify-between">
|
||||||
<div className="flex min-w-0 flex-col gap-1">
|
<div className="flex min-w-0 flex-col gap-1">
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
|||||||
import { SegmentedControl } from '@/components/interior/segmented-control';
|
import { SegmentedControl } from '@/components/interior/segmented-control';
|
||||||
import { useApi } from '@/lib/api';
|
import { useApi } from '@/lib/api';
|
||||||
import { useAppState } from '@/contexts/AppStateContext';
|
import { useAppState } from '@/contexts/AppStateContext';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn, downloadBlob, toColorInputValue } from '@/lib/utils';
|
||||||
import { settingsRoute, type SettingsTab } from '@/router';
|
import { settingsRoute, type SettingsTab } from '@/router';
|
||||||
import { NotificationsPanel } from '@/components/settings/notifications-panel';
|
import { NotificationsPanel } from '@/components/settings/notifications-panel';
|
||||||
import { GlobalConfigPanel } from '@/components/settings/global-config-panel';
|
import { GlobalConfigPanel } from '@/components/settings/global-config-panel';
|
||||||
@@ -138,7 +138,7 @@ function SettingsNav({ tab, onChange }: { tab: SettingsTab; onChange: (t: Settin
|
|||||||
aria-label="设置导航"
|
aria-label="设置导航"
|
||||||
className={cn(
|
className={cn(
|
||||||
'flex flex-wrap gap-1 rounded-xl border bg-card p-1.5',
|
'flex flex-wrap gap-1 rounded-xl border bg-card p-1.5',
|
||||||
'lg:w-52 lg:shrink-0 lg:flex-col lg:flex-nowrap lg:self-start lg:sticky lg:top-4 lg:max-h-[calc(100vh-6rem)] lg:overflow-y-auto',
|
'lg:w-52 lg:shrink-0 lg:flex-col lg:flex-nowrap lg:self-start lg:sticky lg:top-4 lg:max-h-[calc(100dvh-6rem)] lg:overflow-y-auto lg:overscroll-y-contain',
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{TAB_GROUPS.map((group, gi) => (
|
{TAB_GROUPS.map((group, gi) => (
|
||||||
@@ -476,12 +476,12 @@ function AppearancePanel() {
|
|||||||
>
|
>
|
||||||
<input
|
<input
|
||||||
type="color"
|
type="color"
|
||||||
value={a.accentCustom}
|
value={toColorInputValue(a.accentCustom)}
|
||||||
onChange={(e) => pickCustomAccent(e.target.value)}
|
onChange={(e) => pickCustomAccent(e.target.value)}
|
||||||
className="absolute inset-0 cursor-pointer opacity-0"
|
className="absolute inset-0 cursor-pointer opacity-0"
|
||||||
aria-label="自定义强调色"
|
aria-label="自定义强调色"
|
||||||
/>
|
/>
|
||||||
{a.accentMode === 'custom' && <Check className="size-4 text-white drop-shadow-sm" strokeWidth={3} />}
|
{a.accentMode === 'custom' && <Check className="pointer-events-none size-4 text-white drop-shadow-sm" strokeWidth={3} />}
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</SettingRow>
|
</SettingRow>
|
||||||
@@ -636,7 +636,7 @@ function BackgroundCard({
|
|||||||
<label className="relative size-10 cursor-pointer overflow-hidden rounded-lg border" style={{ backgroundColor: a.background.color }}>
|
<label className="relative size-10 cursor-pointer overflow-hidden rounded-lg border" style={{ backgroundColor: a.background.color }}>
|
||||||
<input
|
<input
|
||||||
type="color"
|
type="color"
|
||||||
value={a.background.color}
|
value={toColorInputValue(a.background.color)}
|
||||||
onChange={(e) => setAppearance({ background: { color: e.target.value } })}
|
onChange={(e) => setAppearance({ background: { color: e.target.value } })}
|
||||||
className="absolute inset-0 cursor-pointer opacity-0"
|
className="absolute inset-0 cursor-pointer opacity-0"
|
||||||
aria-label="背景颜色"
|
aria-label="背景颜色"
|
||||||
@@ -786,7 +786,8 @@ function FontField({
|
|||||||
spellCheck={false}
|
spellCheck={false}
|
||||||
autoComplete="off"
|
autoComplete="off"
|
||||||
style={custom ? { fontFamily: custom } : undefined}
|
style={custom ? { fontFamily: custom } : undefined}
|
||||||
className="w-full rounded-lg border bg-card/40 px-3 py-2 text-sm outline-none focus:border-primary"
|
data-ui-control=""
|
||||||
|
className="w-full rounded-lg border bg-card/40 px-3 py-2 text-base outline-none focus:border-primary md:text-sm"
|
||||||
/>
|
/>
|
||||||
{canQuery && fonts && fonts.length > 0 && (
|
{canQuery && fonts && fonts.length > 0 && (
|
||||||
<datalist id={listId}>
|
<datalist id={listId}>
|
||||||
@@ -877,7 +878,7 @@ function ThemeVarsPanel({
|
|||||||
>
|
>
|
||||||
<input
|
<input
|
||||||
type="color"
|
type="color"
|
||||||
value={override || '#888888'}
|
value={toColorInputValue(override || '#888888', '#888888')}
|
||||||
onChange={(e) => set(f.token, e.target.value)}
|
onChange={(e) => set(f.token, e.target.value)}
|
||||||
className="absolute inset-0 cursor-pointer opacity-0"
|
className="absolute inset-0 cursor-pointer opacity-0"
|
||||||
aria-label={`${f.label}颜色`}
|
aria-label={`${f.label}颜色`}
|
||||||
@@ -956,8 +957,8 @@ function DataPanel() {
|
|||||||
// native Cmd/Ctrl+Z undoes. Each is a complete, valid rule.
|
// native Cmd/Ctrl+Z undoes. Each is a complete, valid rule.
|
||||||
const CSS_SNIPPETS: { label: string; css: string }[] = [
|
const CSS_SNIPPETS: { label: string; css: string }[] = [
|
||||||
{ label: '侧栏字号', css: '.text-sidebar-foreground {\n font-size: 1.05em;\n}' },
|
{ label: '侧栏字号', css: '.text-sidebar-foreground {\n font-size: 1.05em;\n}' },
|
||||||
{ label: '卡片毛玻璃', css: '.bg-card {\n backdrop-filter: blur(8px);\n background-color: color-mix(in oklab, var(--card) 80%, transparent);\n}' },
|
{ label: '卡片毛玻璃', css: '.bg-card {\n -webkit-backdrop-filter: blur(8px);\n backdrop-filter: blur(8px);\n background-color: color-mix(in oklab, var(--card) 80%, transparent);\n}' },
|
||||||
{ label: '隐藏滚动条', css: '*::-webkit-scrollbar {\n width: 0;\n height: 0;\n}' },
|
{ label: '隐藏滚动条', css: '* {\n scrollbar-width: none;\n}\n*::-webkit-scrollbar {\n width: 0;\n height: 0;\n}' },
|
||||||
{ label: '加粗标题', css: 'h1, h2, h3 {\n font-weight: 700;\n letter-spacing: -0.01em;\n}' },
|
{ label: '加粗标题', css: 'h1, h2, h3 {\n font-weight: 700;\n letter-spacing: -0.01em;\n}' },
|
||||||
{ label: '紧凑卡片', css: '.rounded-xl {\n border-radius: 0.5rem;\n}' },
|
{ label: '紧凑卡片', css: '.rounded-xl {\n border-radius: 0.5rem;\n}' },
|
||||||
];
|
];
|
||||||
@@ -1009,13 +1010,7 @@ function AdvancedPanel() {
|
|||||||
},
|
},
|
||||||
() => api.ui.get(),
|
() => api.ui.get(),
|
||||||
);
|
);
|
||||||
const blob = new Blob([JSON.stringify(config, null, 2)], { type: 'application/json' });
|
downloadBlob(new Blob([JSON.stringify(config, null, 2)], { type: 'application/json' }), 'snowluma-ui-config.json');
|
||||||
const url = URL.createObjectURL(blob);
|
|
||||||
const a = document.createElement('a');
|
|
||||||
a.href = url;
|
|
||||||
a.download = 'snowluma-ui-config.json';
|
|
||||||
a.click();
|
|
||||||
URL.revokeObjectURL(url);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('export UI config failed', error);
|
console.error('export UI config failed', error);
|
||||||
setMsg({ kind: 'err', text: '导出失败' });
|
setMsg({ kind: 'err', text: '导出失败' });
|
||||||
@@ -1135,7 +1130,7 @@ function AdvancedPanel() {
|
|||||||
maxLength={50000}
|
maxLength={50000}
|
||||||
spellCheck={false}
|
spellCheck={false}
|
||||||
placeholder={'/* 例如:放大侧栏字号 */\n.text-sidebar-foreground { font-size: 1.05em; }'}
|
placeholder={'/* 例如:放大侧栏字号 */\n.text-sidebar-foreground { font-size: 1.05em; }'}
|
||||||
className="h-64 resize-y rounded-lg bg-card/40 p-3 font-mono text-[12px] leading-relaxed"
|
className="h-64 resize-y rounded-lg bg-card/40 p-3 font-mono text-base leading-relaxed md:text-[12px]"
|
||||||
/>
|
/>
|
||||||
{cssWarn && (
|
{cssWarn && (
|
||||||
<p className="flex items-start gap-1.5 text-xs text-warning">
|
<p className="flex items-start gap-1.5 text-xs text-warning">
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import { ConfirmDialog } from '@/components/confirm-dialog';
|
|||||||
import { useActionFeedback } from '@/contexts/ActionFeedbackContext';
|
import { useActionFeedback } from '@/contexts/ActionFeedbackContext';
|
||||||
import { useApi } from '@/lib/api';
|
import { useApi } from '@/lib/api';
|
||||||
import { useFlashMessage } from '@/hooks/use-flash-message';
|
import { useFlashMessage } from '@/hooks/use-flash-message';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn, downloadBlob } from '@/lib/utils';
|
||||||
import type { SystemSettingsResponse } from '@/types';
|
import type { SystemSettingsResponse } from '@/types';
|
||||||
|
|
||||||
export function SystemPanel() {
|
export function SystemPanel() {
|
||||||
@@ -157,13 +157,10 @@ export function SystemPanel() {
|
|||||||
},
|
},
|
||||||
() => api.systemSettings.exportBackup(exportCreds),
|
() => api.systemSettings.exportBackup(exportCreds),
|
||||||
);
|
);
|
||||||
const blob = new Blob([JSON.stringify(bundle, null, 2)], { type: 'application/json' });
|
downloadBlob(
|
||||||
const url = URL.createObjectURL(blob);
|
new Blob([JSON.stringify(bundle, null, 2)], { type: 'application/json' }),
|
||||||
const a = document.createElement('a');
|
`snowluma-backup-${new Date().toISOString().replace(/[:.]/g, '-')}.json`,
|
||||||
a.href = url;
|
);
|
||||||
a.download = `snowluma-backup-${new Date().toISOString().replace(/[:.]/g, '-')}.json`;
|
|
||||||
a.click();
|
|
||||||
URL.revokeObjectURL(url);
|
|
||||||
flash('ok', '已导出备份');
|
flash('ok', '已导出备份');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
flash('err', e instanceof Error ? e.message : '导出失败');
|
flash('err', e instanceof Error ? e.message : '导出失败');
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import type { TotpEnrollment, TotpStatus } from '@/lib/api/types';
|
|||||||
import { parseSecondFactor } from '@/lib/totp-second-factor';
|
import { parseSecondFactor } from '@/lib/totp-second-factor';
|
||||||
import { TotpQr } from '@/components/settings/totp-qr';
|
import { TotpQr } from '@/components/settings/totp-qr';
|
||||||
import { TotpRecoveryCodes } from '@/components/settings/totp-recovery-codes';
|
import { TotpRecoveryCodes } from '@/components/settings/totp-recovery-codes';
|
||||||
|
import { copyText } from '@/lib/utils';
|
||||||
|
|
||||||
function SettingRow({
|
function SettingRow({
|
||||||
label,
|
label,
|
||||||
@@ -198,6 +199,22 @@ function TotpSetupDialog({
|
|||||||
<div className="flex flex-col items-center gap-3">
|
<div className="flex flex-col items-center gap-3">
|
||||||
<TotpQr value={enrollment.otpauthUrl} label="2FA 绑定二维码" />
|
<TotpQr value={enrollment.otpauthUrl} label="2FA 绑定二维码" />
|
||||||
<p className="break-all text-center font-mono text-xs text-muted-foreground">{enrollment.secret}</p>
|
<p className="break-all text-center font-mono text-xs text-muted-foreground">{enrollment.secret}</p>
|
||||||
|
<div className="flex flex-wrap justify-center gap-2">
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => { void copyText(enrollment.secret); }}
|
||||||
|
>
|
||||||
|
复制密钥
|
||||||
|
</Button>
|
||||||
|
<a
|
||||||
|
href={enrollment.otpauthUrl}
|
||||||
|
className="inline-flex h-8 items-center rounded-md border border-border px-3 text-xs font-medium text-foreground"
|
||||||
|
>
|
||||||
|
在验证器中打开
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<div className="grid grid-cols-2 gap-3">
|
<div className="grid grid-cols-2 gap-3">
|
||||||
@@ -220,6 +237,8 @@ function TotpSetupDialog({
|
|||||||
<Input
|
<Input
|
||||||
inputMode="numeric"
|
inputMode="numeric"
|
||||||
autoComplete="one-time-code"
|
autoComplete="one-time-code"
|
||||||
|
maxLength={6}
|
||||||
|
pattern="[0-9]*"
|
||||||
placeholder="6 位验证码"
|
placeholder="6 位验证码"
|
||||||
value={code}
|
value={code}
|
||||||
onChange={(e) => setCode(e.target.value)}
|
onChange={(e) => setCode(e.target.value)}
|
||||||
|
|||||||
@@ -1,27 +1,7 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { Check, Copy } from 'lucide-react';
|
import { Check, Copy } from 'lucide-react';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { copyText } from '@/lib/utils';
|
||||||
async function copyText(value: string): Promise<boolean> {
|
|
||||||
try {
|
|
||||||
await navigator.clipboard.writeText(value);
|
|
||||||
return true;
|
|
||||||
} catch {
|
|
||||||
try {
|
|
||||||
const ta = document.createElement('textarea');
|
|
||||||
ta.value = value;
|
|
||||||
ta.style.position = 'fixed';
|
|
||||||
ta.style.opacity = '0';
|
|
||||||
document.body.appendChild(ta);
|
|
||||||
ta.select();
|
|
||||||
const ok = document.execCommand('copy');
|
|
||||||
document.body.removeChild(ta);
|
|
||||||
return ok;
|
|
||||||
} catch {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function TotpRecoveryCodes({
|
export function TotpRecoveryCodes({
|
||||||
codes,
|
codes,
|
||||||
@@ -31,6 +11,7 @@ export function TotpRecoveryCodes({
|
|||||||
onConfirm: () => void;
|
onConfirm: () => void;
|
||||||
}) {
|
}) {
|
||||||
const [copied, setCopied] = useState(false);
|
const [copied, setCopied] = useState(false);
|
||||||
|
const [copyError, setCopyError] = useState(false);
|
||||||
const [saved, setSaved] = useState(false);
|
const [saved, setSaved] = useState(false);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -40,8 +21,13 @@ export function TotpRecoveryCodes({
|
|||||||
</p>
|
</p>
|
||||||
<ol className="grid grid-cols-2 gap-2 font-mono text-sm">
|
<ol className="grid grid-cols-2 gap-2 font-mono text-sm">
|
||||||
{codes.map((code) => (
|
{codes.map((code) => (
|
||||||
<li key={code} className="rounded-md border bg-muted/40 px-3 py-2 text-center tracking-wide">
|
<li key={code}>
|
||||||
{code}
|
<input
|
||||||
|
readOnly
|
||||||
|
value={code}
|
||||||
|
className="w-full rounded-md border bg-muted/40 px-3 py-2 text-center tracking-wide outline-none"
|
||||||
|
onFocus={(e) => e.currentTarget.select()}
|
||||||
|
/>
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
</ol>
|
</ol>
|
||||||
@@ -51,12 +37,18 @@ export function TotpRecoveryCodes({
|
|||||||
size="sm"
|
size="sm"
|
||||||
className="self-start"
|
className="self-start"
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
if (await copyText(codes.join('\n'))) setCopied(true);
|
const ok = await copyText(codes.join('\n'));
|
||||||
|
setCopied(ok);
|
||||||
|
setCopyError(!ok);
|
||||||
|
if (ok) window.setTimeout(() => setCopied(false), 1600);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{copied ? <Check className="size-4" /> : <Copy className="size-4" />}
|
{copied ? <Check className="size-4" /> : <Copy className="size-4" />}
|
||||||
{copied ? '已复制' : '复制全部'}
|
{copied ? '已复制' : '复制全部'}
|
||||||
</Button>
|
</Button>
|
||||||
|
{copyError && (
|
||||||
|
<p className="text-xs text-destructive">复制失败,请长按上面的码手动拷贝。</p>
|
||||||
|
)}
|
||||||
<label className="flex items-start gap-2 text-sm">
|
<label className="flex items-start gap-2 text-sm">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
// preview toggle. Read-only; no external deps.
|
// preview toggle. Read-only; no external deps.
|
||||||
import { useState, type ReactNode } from 'react';
|
import { useState, type ReactNode } from 'react';
|
||||||
import { Check, ChevronRight, Copy, Image as ImageIcon } from 'lucide-react';
|
import { Check, ChevronRight, Copy, Image as ImageIcon } from 'lucide-react';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn, copyText } from '@/lib/utils';
|
||||||
|
|
||||||
const IMAGE_URL_RE = /^https?:\/\/[^\s]+?\.(?:png|jpe?g|gif|webp|bmp)(?:[?#][^\s]*)?$/i;
|
const IMAGE_URL_RE = /^https?:\/\/[^\s]+?\.(?:png|jpe?g|gif|webp|bmp)(?:[?#][^\s]*)?$/i;
|
||||||
// QQ multimedia rkey image URLs don't end in an extension but carry these hints.
|
// QQ multimedia rkey image URLs don't end in an extension but carry these hints.
|
||||||
@@ -121,24 +121,10 @@ export function JsonTree({ data, className, maxHeight = '20rem' }: { data: unkno
|
|||||||
// Stringify lazily, only on an actual copy — not on every render (a large
|
// Stringify lazily, only on an actual copy — not on every render (a large
|
||||||
// payload would otherwise re-serialise the whole tree each commit).
|
// payload would otherwise re-serialise the whole tree each commit).
|
||||||
const text = (() => { try { return JSON.stringify(data, null, 2); } catch { return String(data); } })();
|
const text = (() => { try { return JSON.stringify(data, null, 2); } catch { return String(data); } })();
|
||||||
try {
|
if (await copyText(text)) {
|
||||||
if (navigator.clipboard?.writeText) {
|
|
||||||
await navigator.clipboard.writeText(text);
|
|
||||||
} else {
|
|
||||||
// navigator.clipboard is undefined on http LAN deployments — fall back
|
|
||||||
// to the legacy execCommand path so copy still works (and shows feedback).
|
|
||||||
const ta = document.createElement('textarea');
|
|
||||||
ta.value = text;
|
|
||||||
ta.style.position = 'fixed';
|
|
||||||
ta.style.opacity = '0';
|
|
||||||
document.body.appendChild(ta);
|
|
||||||
ta.select();
|
|
||||||
document.execCommand('copy');
|
|
||||||
document.body.removeChild(ta);
|
|
||||||
}
|
|
||||||
setCopied(true);
|
setCopied(true);
|
||||||
setTimeout(() => setCopied(false), 1200);
|
setTimeout(() => setCopied(false), 1200);
|
||||||
} catch { /* clipboard blocked */ }
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -272,7 +272,10 @@ export function ActionFeedbackViewport() {
|
|||||||
const runningActivity = activity?.phase === 'running' ? activity : null;
|
const runningActivity = activity?.phase === 'running' ? activity : null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="pointer-events-none fixed bottom-4 right-4 z-[80] flex w-[min(360px,calc(100vw-2rem))] flex-col items-end gap-2">
|
<div
|
||||||
|
className="pointer-events-none fixed z-[80] flex w-[min(360px,calc(100vw-2rem))] flex-col items-end gap-2"
|
||||||
|
style={{ bottom: 'max(1rem, env(safe-area-inset-bottom))', right: 'max(1rem, env(safe-area-inset-right))' }}
|
||||||
|
>
|
||||||
{notices.map((notice) => (
|
{notices.map((notice) => (
|
||||||
<ActionNoticeBanner
|
<ActionNoticeBanner
|
||||||
key={notice.id}
|
key={notice.id}
|
||||||
|
|||||||
Reference in new issue
Block a user