diff --git a/src/pages/AuthFilesPage.tsx b/src/pages/AuthFilesPage.tsx index 88958b7..f1ad0e0 100644 --- a/src/pages/AuthFilesPage.tsx +++ b/src/pages/AuthFilesPage.tsx @@ -170,6 +170,34 @@ const writeAuthFilesUiState = (state: AuthFilesUiState) => { } }; +const copyToClipboard = async (text: string): Promise => { + try { + if (typeof navigator !== 'undefined' && navigator.clipboard?.writeText) { + await navigator.clipboard.writeText(text); + return true; + } + } catch { + // fallback below + } + + try { + const textarea = document.createElement('textarea'); + textarea.value = text; + textarea.style.position = 'fixed'; + textarea.style.opacity = '0'; + textarea.style.left = '-9999px'; + textarea.style.top = '0'; + document.body.appendChild(textarea); + textarea.focus(); + textarea.select(); + const copied = document.execCommand('copy'); + document.body.removeChild(textarea); + return copied; + } catch { + return false; + } +}; + interface PrefixProxyEditorState { fileName: string; loading: boolean; @@ -1016,6 +1044,16 @@ export function AuthFilesPage() { } }; + const copyTextWithNotification = async (text: string) => { + const copied = await copyToClipboard(text); + showNotification( + copied + ? t('notification.link_copied', { defaultValue: 'Copied to clipboard' }) + : t('notification.copy_failed', { defaultValue: 'Copy failed' }), + copied ? 'success' : 'error' + ); + }; + // 检查模型是否被 OAuth 排除 const isModelExcluded = (modelId: string, providerType: string): boolean => { const providerKey = normalizeProviderKey(providerType); @@ -2050,9 +2088,7 @@ export function AuthFilesPage() { onClick={() => { if (selectedFile) { const text = JSON.stringify(selectedFile, null, 2); - navigator.clipboard.writeText(text).then(() => { - showNotification(t('notification.link_copied'), 'success'); - }); + void copyTextWithNotification(text); } }} > @@ -2108,11 +2144,7 @@ export function AuthFilesPage() { key={model.id} className={`${styles.modelItem} ${isExcluded ? styles.modelItemExcluded : ''}`} onClick={() => { - navigator.clipboard.writeText(model.id); - showNotification( - t('notification.link_copied', { defaultValue: '已复制到剪贴板' }), - 'success' - ); + void copyTextWithNotification(model.id); }} title={ isExcluded