From d5630cfb15134e5f27a1fc346d115f39cc858579 Mon Sep 17 00:00:00 2001 From: captain Date: Sun, 5 Apr 2026 00:01:15 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=88=86=E4=BA=AB=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E4=BD=8D=E7=BD=AE=E3=80=81=E6=89=93=E5=BC=80=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E9=99=8D=E7=BA=A7=E6=96=87=E4=BB=B6=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E5=86=8D=E6=AC=A1=E5=B0=9D=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/lanchat/app/MainActivity.kt | 15 ++++- src/css/style.css | 59 +++++++++++-------- src/js/ui.js | 29 +++++---- 3 files changed, 68 insertions(+), 35 deletions(-) diff --git a/src-tauri/gen/android/app/src/main/java/com/lanchat/app/MainActivity.kt b/src-tauri/gen/android/app/src/main/java/com/lanchat/app/MainActivity.kt index 1503d02..1927ec6 100644 --- a/src-tauri/gen/android/app/src/main/java/com/lanchat/app/MainActivity.kt +++ b/src-tauri/gen/android/app/src/main/java/com/lanchat/app/MainActivity.kt @@ -241,8 +241,19 @@ class MainActivity : TauriActivity() { addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) } - startActivity(intent) - println("[MainActivity] 打开文件 Intent 已启动") + try { + startActivity(intent) + println("[MainActivity] 打开文件 Intent 已启动") + } catch (e: SecurityException) { + // content URI 权限过期,降级为 */* 再试一次 + println("[MainActivity] 权限异常,降级为 */* 重试: ${e.message}") + val fallbackIntent = Intent(Intent.ACTION_VIEW).apply { + setDataAndType(uri, "*/*") + addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + } + startActivity(fallbackIntent) + println("[MainActivity] 降级打开文件 Intent 已启动") + } } catch (e: Exception) { println("[MainActivity] 打开文件失败: ${e.message}") e.printStackTrace() diff --git a/src/css/style.css b/src/css/style.css index 546b7c1..06c7c4f 100644 --- a/src/css/style.css +++ b/src/css/style.css @@ -1800,33 +1800,46 @@ h2::before { cursor: not-allowed; } -/* 文件卡片分享按钮(仅 Android 端渲染) */ -.file-share-btn { - display: flex; - align-items: center; - justify-content: center; - flex-shrink: 0; - width: 32px; - height: 32px; - margin-left: 8px; - border-radius: 8px; - border: 1px solid rgba(255, 255, 255, 0.15); - background: rgba(255, 255, 255, 0.1); - color: var(--text-dim, #b3b3b3); - cursor: pointer; - transition: background 0.2s, color 0.2s; -} - -.file-share-btn:hover { - background: rgba(255, 255, 255, 0.2); - color: #fff; -} +/* ========================================= + 文件消息与分享按钮高级美化 + ========================================= */ /* 文件卡片内:文件信息 + 分享按钮横向排列 */ .file-action-row { display: flex; align-items: center; - justify-content: space-between; - gap: 8px; width: 100%; + gap: 12px; /* 拉开文件内容与按钮的间距 */ } + +/* 基础分享按钮(普通文件卡片使用) */ +.file-share-btn { + display: flex; + align-items: center; + justify-content: center; + flex-shrink: 0; + width: 34px; + height: 34px; + border-radius: 10px; /* 圆角矩形,彻底告别头像的错觉 */ + border: none; /* 去掉边框,更加扁平化 */ + background: rgba(255, 255, 255, 0.08); /* 极弱的背景色 */ + color: var(--text-main); + cursor: pointer; + transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1); + box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); +} + +/* 发送方(深色气泡)里的按钮,底色稍微亮一点 */ +.message.sent .file-share-btn { + background: rgba(255, 255, 255, 0.15); +} + +/* 按钮点击/悬停反馈 */ +.file-share-btn:hover, +.file-share-btn:active { + background: var(--primary); + color: #fff; + transform: scale(1.05); + box-shadow: 0 4px 12px rgba(189, 147, 249, 0.4); +} + diff --git a/src/js/ui.js b/src/js/ui.js index a626794..f017e96 100644 --- a/src/js/ui.js +++ b/src/js/ui.js @@ -126,7 +126,7 @@ async function addUserToList(id, name, addr, isOffline = false) { if (!window.userLastMessageTimestamps) { window.userLastMessageTimestamps = {}; } - + if (!window.userLastMessageTimestamps[id]) { try { const messages = await apiGetChatHistory(id, 1, 0); @@ -926,7 +926,7 @@ function createMessageElement(message, isSent) { const isAndroid = navigator.userAgent.includes('Android'); if (isAndroid) { - // Android 端:点击主体打开文件,右侧分享按钮分享到其他应用 + // 1. 给主体绑定打开文件的事件 fileContainer.addEventListener('click', async () => { try { await apiOpenFileInAndroid(message.file_path); @@ -935,13 +935,13 @@ function createMessageElement(message, isSent) { } }); - // 分享按钮(仅 Android),与文件信息并排 + // 2. 创建分享按钮 const shareBtn = document.createElement('button'); shareBtn.className = 'file-share-btn'; shareBtn.title = '分享到其他应用'; - shareBtn.innerHTML = ``; + shareBtn.innerHTML = ``; shareBtn.addEventListener('click', async (e) => { - e.stopPropagation(); + e.stopPropagation(); // 阻止冒泡,防止触发打开文件 try { await apiShareFileToOtherApp(message.file_path); } catch (e) { @@ -949,14 +949,23 @@ function createMessageElement(message, isSent) { } }); - // 用横向 row 包住文件信息和分享按钮 + // 【普通文件模式】:创建横向容器 const row = document.createElement('div'); row.className = 'file-action-row'; - // 把 fileContainer 现有的第一个子节点(file-info-wrapper)移入 row - while (fileContainer.firstChild) { - row.appendChild(fileContainer.firstChild); + + if (isSent) { + // 发送方(靠右):分享按钮在左,文件信息在右 + row.appendChild(shareBtn); + while (fileContainer.firstChild) { + row.appendChild(fileContainer.firstChild); + } + } else { + // 接收方(靠左):文件信息在左,分享按钮在右 + while (fileContainer.firstChild) { + row.appendChild(fileContainer.firstChild); + } + row.appendChild(shareBtn); } - row.appendChild(shareBtn); fileContainer.appendChild(row); } else { // 桌面端:点击打开文件位置