diff --git a/icon/Clash_Logo.png b/icon/Clash_Logo.png new file mode 100755 index 0000000..c624b94 Binary files /dev/null and b/icon/Clash_Logo.png differ diff --git a/icon/README.md b/icon/README.md new file mode 100755 index 0000000..d99061b --- /dev/null +++ b/icon/README.md @@ -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(透明背景) \ No newline at end of file diff --git a/shutdown.sh b/shutdown.sh index c2ba4e7..9644f31 100644 --- a/shutdown.sh +++ b/shutdown.sh @@ -11,4 +11,12 @@ fi # 清除环境变量 > /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" diff --git a/start.sh b/start.sh index d6e584d..1cf339b 100644 --- a/start.sh +++ b/start.sh @@ -34,6 +34,9 @@ SKIP_DOWNLOAD_CONFIG=false # 初始化跳过编辑profile标志 SKIP_EDIT_PROFILE=false +# 初始化跳过系统托盘图标标志 +SKIP_TRAY_ICON=false + # 处理命令行参数 while [[ $# -gt 0 ]]; do case $1 in @@ -45,6 +48,10 @@ while [[ $# -gt 0 ]]; do SKIP_EDIT_PROFILE=true shift ;; + --skip-tray-icon) + SKIP_TRAY_ICON=true + shift + ;; *) echo "未知参数: $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功能 success() { echo -en "\\033[60G[\\033[1;32m OK \\033[0;39m]\r" @@ -291,3 +343,12 @@ if [ "$SKIP_EDIT_PROFILE" = false ]; then else echo -e "\n[INFO] 跳过系统代理环境变量配置..." fi + +# 启动系统托盘图标 +if [ "$SKIP_TRAY_ICON" = false ]; then + if check_dependencies; then + start_tray_icon + fi +else + echo -e "\n[INFO] 跳过系统托盘图标启动..." +fi