修复 发送过多的desktop文件

Signed-off-by: shenmo <jifengshenmo@outlook.com>
This commit is contained in:
2025-11-27 07:14:36 +00:00
committed by Gitee
parent 4023822a61
commit 4909ddf220
2 changed files with 65 additions and 12 deletions

View File

@@ -291,16 +291,42 @@ function create_desktop_file() {
export CURRENT_USER_DIR_DESKTOP=$(sudo -u "$user" xdg-user-dir DESKTOP)
function exec_create_desktop_file() {
local desktop_files=()
local package_name_lower=$(echo "$package_name" | tr '[:upper:]' '[:lower:]')
# 收集所有桌面文件
desktop_files+=($(dpkg -L "$package_name" | grep '/usr/share/applications/.*\.desktop$'))
desktop_files+=($(dpkg -L "$package_name" | grep '/opt/apps/'"$package_name"'/entries/applications/.*\.desktop$'))
# 收集指定路径下的桌面文件
# 1. /usr/share/applications/ 目录下的 .desktop 文件
desktop_files+=($(dpkg -L "$package_name" 2>/dev/null | grep '^/usr/share/applications/.*\.desktop$' || true))
# 2. /opt/apps/包名/entries/applications/ 目录下的 .desktop 文件
# 先尝试精确匹配包名路径
desktop_files+=($(dpkg -L "$package_name" 2>/dev/null | grep "^/opt/apps/$package_name/entries/applications/.*\.desktop$" || true))
# 再尝试小写包名路径(有些包可能使用小写路径)
desktop_files+=($(dpkg -L "$package_name" 2>/dev/null | grep "^/opt/apps/$package_name_lower/entries/applications/.*\.desktop$" || true))
# 如果没有找到任何符合条件的桌面文件,则直接返回
if [ ${#desktop_files[@]} -eq 0 ]; then
echo "未找到符合条件的桌面快捷方式文件(/usr/share/applications/ 或 /opt/apps/$package_name/entries/applications/"
return 0
fi
echo "找到 ${#desktop_files[@]} 个桌面快捷方式文件:"
printf '%s\n' "${desktop_files[@]}"
for desktop_file_path in "${desktop_files[@]}"; do
if [ "$FORCE_CREATE_DESKTOP" -eq 1 ] || [ -z "$(grep 'NoDisplay=true' "$desktop_file_path")" ]; then
echo "$desktop_file_path is checked and will be installed to desktop"
# 检查文件是否存在
if [ ! -f "$desktop_file_path" ]; then
echo "文件不存在,跳过: $desktop_file_path"
continue
fi
# 检查是否是 NoDisplay=true 的桌面文件
if [ -z "$(grep -i 'NoDisplay=true' "$desktop_file_path")" ]; then
echo "安装桌面快捷方式: $desktop_file_path"
chmod +x "$desktop_file_path"
sudo -u "$user" cp "$desktop_file_path" "${CURRENT_USER_DIR_DESKTOP}"
sudo -u "$user" cp "$desktop_file_path" "${CURRENT_USER_DIR_DESKTOP}/"
else
echo "跳过 NoDisplay=true 的桌面文件: $desktop_file_path"
fi
done
}

View File

@@ -291,19 +291,46 @@ function create_desktop_file() {
export CURRENT_USER_DIR_DESKTOP=$(sudo -u "$user" xdg-user-dir DESKTOP)
function exec_create_desktop_file() {
local desktop_files=()
local package_name_lower=$(echo "$package_name" | tr '[:upper:]' '[:lower:]')
# 收集所有桌面文件
desktop_files+=($(dpkg -L "$package_name" | grep '/usr/share/applications/.*\.desktop$'))
desktop_files+=($(dpkg -L "$package_name" | grep '/opt/apps/'"$package_name"'/entries/applications/.*\.desktop$'))
# 收集指定路径下的桌面文件
# 1. /usr/share/applications/ 目录下的 .desktop 文件
desktop_files+=($(dpkg -L "$package_name" 2>/dev/null | grep '^/usr/share/applications/.*\.desktop$' || true))
# 2. /opt/apps/包名/entries/applications/ 目录下的 .desktop 文件
# 先尝试精确匹配包名路径
desktop_files+=($(dpkg -L "$package_name" 2>/dev/null | grep "^/opt/apps/$package_name/entries/applications/.*\.desktop$" || true))
# 再尝试小写包名路径(有些包可能使用小写路径)
desktop_files+=($(dpkg -L "$package_name" 2>/dev/null | grep "^/opt/apps/$package_name_lower/entries/applications/.*\.desktop$" || true))
# 如果没有找到任何符合条件的桌面文件,则直接返回
if [ ${#desktop_files[@]} -eq 0 ]; then
echo "未找到符合条件的桌面快捷方式文件(/usr/share/applications/ 或 /opt/apps/$package_name/entries/applications/"
return 0
fi
echo "找到 ${#desktop_files[@]} 个桌面快捷方式文件:"
printf '%s\n' "${desktop_files[@]}"
for desktop_file_path in "${desktop_files[@]}"; do
if [ "$FORCE_CREATE_DESKTOP" -eq 1 ] || [ -z "$(grep 'NoDisplay=true' "$desktop_file_path")" ]; then
echo "$desktop_file_path is checked and will be installed to desktop"
# 检查文件是否存在
if [ ! -f "$desktop_file_path" ]; then
echo "文件不存在,跳过: $desktop_file_path"
continue
fi
# 检查是否是 NoDisplay=true 的桌面文件
if [ -z "$(grep -i 'NoDisplay=true' "$desktop_file_path")" ]; then
echo "安装桌面快捷方式: $desktop_file_path"
chmod +x "$desktop_file_path"
sudo -u "$user" cp "$desktop_file_path" "${CURRENT_USER_DIR_DESKTOP}"
sudo -u "$user" cp "$desktop_file_path" "${CURRENT_USER_DIR_DESKTOP}/"
else
echo "跳过 NoDisplay=true 的桌面文件: $desktop_file_path"
fi
done
}
export -f exec_create_desktop_file
# 在ACE环境中创建桌面快捷方式