mirror of
https://github.com/wnlen/clash-for-linux.git
synced 2025-05-22 20:04:45 +08:00
添加托盘区图标,并且可以通过参数 --skip-tray-icon 跳过添加
This commit is contained in:
parent
33cbdaf482
commit
09aff5c6e5
BIN
icon/Clash_Logo.png
Executable file
BIN
icon/Clash_Logo.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
13
icon/README.md
Executable file
13
icon/README.md
Executable file
|
@ -0,0 +1,13 @@
|
||||||
|
# Clash Logo 图标
|
||||||
|
|
||||||
|
请将 Clash Logo 图标文件 `Clash_Logo.png` 放置在此目录下。
|
||||||
|
|
||||||
|
你可以从以下位置获取 Clash Logo:
|
||||||
|
1. 从官方仓库下载
|
||||||
|
2. 从其他 Clash 客户端提取
|
||||||
|
3. 使用任何 Clash 相关的 Logo 图片,并重命名为 `Clash_Logo.png`
|
||||||
|
|
||||||
|
图标要求:
|
||||||
|
- 文件名必须是:`Clash_Logo.png`
|
||||||
|
- 建议尺寸:128x128 像素或更大
|
||||||
|
- 格式:PNG(透明背景)
|
|
@ -11,4 +11,12 @@ fi
|
||||||
# 清除环境变量
|
# 清除环境变量
|
||||||
> /etc/profile.d/clash.sh
|
> /etc/profile.d/clash.sh
|
||||||
|
|
||||||
|
# 检查并关闭系统托盘图标
|
||||||
|
PID_NUM=`ps -ef | grep [y]ad | grep -i clash | wc -l`
|
||||||
|
PID=`ps -ef | grep [y]ad | grep -i clash | awk '{print $2}'`
|
||||||
|
if [ $PID_NUM -ne 0 ]; then
|
||||||
|
kill -9 $PID
|
||||||
|
echo -e "\n[INFO] 已移除系统托盘图标"
|
||||||
|
fi
|
||||||
|
|
||||||
echo -e "\n服务关闭成功,请执行以下命令关闭系统代理:proxy_off\n"
|
echo -e "\n服务关闭成功,请执行以下命令关闭系统代理:proxy_off\n"
|
||||||
|
|
61
start.sh
61
start.sh
|
@ -34,6 +34,9 @@ SKIP_DOWNLOAD_CONFIG=false
|
||||||
# 初始化跳过编辑profile标志
|
# 初始化跳过编辑profile标志
|
||||||
SKIP_EDIT_PROFILE=false
|
SKIP_EDIT_PROFILE=false
|
||||||
|
|
||||||
|
# 初始化跳过系统托盘图标标志
|
||||||
|
SKIP_TRAY_ICON=false
|
||||||
|
|
||||||
# 处理命令行参数
|
# 处理命令行参数
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case $1 in
|
case $1 in
|
||||||
|
@ -45,6 +48,10 @@ while [[ $# -gt 0 ]]; do
|
||||||
SKIP_EDIT_PROFILE=true
|
SKIP_EDIT_PROFILE=true
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
--skip-tray-icon)
|
||||||
|
SKIP_TRAY_ICON=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
echo "未知参数: $1"
|
echo "未知参数: $1"
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -55,6 +62,51 @@ done
|
||||||
|
|
||||||
#################### 函数定义 ####################
|
#################### 函数定义 ####################
|
||||||
|
|
||||||
|
# 检查依赖是否安装
|
||||||
|
check_dependencies() {
|
||||||
|
if ! command -v yad &> /dev/null; then
|
||||||
|
echo -e "\033[33m[WARN] 未检测到 yad,尝试安装...\033[0m"
|
||||||
|
if command -v apt &> /dev/null; then
|
||||||
|
sudo apt update && sudo apt install -y yad
|
||||||
|
elif command -v yum &> /dev/null; then
|
||||||
|
sudo yum install -y yad
|
||||||
|
elif command -v dnf &> /dev/null; then
|
||||||
|
sudo dnf install -y yad
|
||||||
|
else
|
||||||
|
echo -e "\033[31m[ERROR] 无法安装 yad,请手动安装后重试\033[0m"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# 启动系统托盘图标
|
||||||
|
start_tray_icon() {
|
||||||
|
local icon_path="$Server_Dir/icon/Clash_Logo.png"
|
||||||
|
|
||||||
|
# 检查图标文件是否存在
|
||||||
|
if [ ! -f "$icon_path" ]; then
|
||||||
|
echo -e "\033[31m[ERROR] 未找到图标文件: $icon_path\033[0m"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 检查是否已有Clash托盘图标
|
||||||
|
if ps -ef | grep -q "[y]ad.*clash"; then
|
||||||
|
echo -e "\n[INFO] 系统托盘图标已存在,跳过添加"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 启动系统托盘图标
|
||||||
|
nohup yad --notification \
|
||||||
|
--image="$icon_path" \
|
||||||
|
--text="Clash" \
|
||||||
|
--command="xdg-open http://127.0.0.1:9090/ui" \
|
||||||
|
--no-middle \
|
||||||
|
&> "$Log_Dir/tray.log" &
|
||||||
|
|
||||||
|
echo -e "\n[INFO] 系统托盘图标已启动"
|
||||||
|
}
|
||||||
|
|
||||||
# 自定义action函数,实现通用action功能
|
# 自定义action函数,实现通用action功能
|
||||||
success() {
|
success() {
|
||||||
echo -en "\\033[60G[\\033[1;32m OK \\033[0;39m]\r"
|
echo -en "\\033[60G[\\033[1;32m OK \\033[0;39m]\r"
|
||||||
|
@ -291,3 +343,12 @@ if [ "$SKIP_EDIT_PROFILE" = false ]; then
|
||||||
else
|
else
|
||||||
echo -e "\n[INFO] 跳过系统代理环境变量配置..."
|
echo -e "\n[INFO] 跳过系统代理环境变量配置..."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# 启动系统托盘图标
|
||||||
|
if [ "$SKIP_TRAY_ICON" = false ]; then
|
||||||
|
if check_dependencies; then
|
||||||
|
start_tray_icon
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo -e "\n[INFO] 跳过系统托盘图标启动..."
|
||||||
|
fi
|
||||||
|
|
Loading…
Reference in New Issue
Block a user