mirror of
https://github.com/cap153/LANChat.git
synced 2026-12-06 16:00:35 +00:00
调整分享按钮位置、打开失败降级文件类型再次尝试
This commit is contained in:
1 parent
fb250964e1
commit
d5630cfb15
3 files changed
+68
-35
No files matched your search
@@ -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()
|
||||
|
||||
+36
-23
@@ -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);
|
||||
}
|
||||
|
||||
+19
-10
@@ -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 = `<svg viewBox="0 0 24 24" width="18" height="18" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"><circle cx="18" cy="5" r="3"></circle><circle cx="6" cy="12" r="3"></circle><circle cx="18" cy="19" r="3"></circle><line x1="8.59" y1="13.51" x2="15.42" y2="17.49"></line><line x1="15.41" y1="6.51" x2="8.59" y2="10.49"></line></svg>`;
|
||||
shareBtn.innerHTML = `<svg viewBox="0 0 24 24" width="16" height="16" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"><circle cx="18" cy="5" r="3"></circle><circle cx="6" cy="12" r="3"></circle><circle cx="18" cy="19" r="3"></circle><line x1="8.59" y1="13.51" x2="15.42" y2="17.49"></line><line x1="15.41" y1="6.51" x2="8.59" y2="10.49"></line></svg>`;
|
||||
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 {
|
||||
// 桌面端:点击打开文件位置
|
||||
|
||||
Reference in new issue
Block a user