252 lines
7.2 KiB
Bash
Executable File
252 lines
7.2 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# ========================================
|
|
# DBus 锁屏信号测试脚本
|
|
# 用于诊断为什么锁屏信号没有被接收到
|
|
# ========================================
|
|
|
|
echo "========================================"
|
|
echo "DBus Lock Signal Test Script"
|
|
echo "========================================"
|
|
echo ""
|
|
|
|
# 颜色定义
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
CYAN='\033[0;36m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# 检查必要的工具
|
|
echo "Checking required tools..."
|
|
if ! command -v dbus-monitor &> /dev/null; then
|
|
echo -e "${RED}✗${NC} dbus-monitor not found. Please install: sudo apt install dbus-x11"
|
|
exit 1
|
|
fi
|
|
|
|
if ! command -v dbus-send &> /dev/null; then
|
|
echo -e "${RED}✗${NC} dbus-send not found. Please install: sudo apt install dbus-x11"
|
|
exit 1
|
|
fi
|
|
|
|
echo -e "${GREEN}✓${NC} All required tools available"
|
|
echo ""
|
|
|
|
# ========================================
|
|
# 1. 检查当前会话信息
|
|
# ========================================
|
|
echo "========================================"
|
|
echo "Step 1: Session Information"
|
|
echo "========================================"
|
|
echo ""
|
|
|
|
echo "Environment Variables:"
|
|
echo " XDG_SESSION_ID: ${XDG_SESSION_ID:-<not set>}"
|
|
echo " XDG_SESSION_TYPE: ${XDG_SESSION_TYPE:-<not set>}"
|
|
echo " XDG_CURRENT_DESKTOP: ${XDG_CURRENT_DESKTOP:-<not set>}"
|
|
echo " DESKTOP_SESSION: ${DESKTOP_SESSION:-<not set>}"
|
|
echo " GDMSESSION: ${GDMSESSION:-<not set>}"
|
|
echo ""
|
|
|
|
# 尝试获取当前会话路径
|
|
if [ -n "$XDG_SESSION_ID" ]; then
|
|
SESSION_PATH="/org/freedesktop/login1/session/$XDG_SESSION_ID"
|
|
echo "Calculated session path: $SESSION_PATH"
|
|
echo ""
|
|
|
|
# 验证会话路径是否有效
|
|
echo "Verifying session path..."
|
|
if dbus-send --system --print-reply --dest=org.freedesktop.login1 \
|
|
"$SESSION_PATH" \
|
|
org.freedesktop.DBus.Introspectable.Introspect &>/dev/null; then
|
|
echo -e "${GREEN}✓${NC} Session path is valid"
|
|
else
|
|
echo -e "${RED}✗${NC} Session path is not valid"
|
|
fi
|
|
echo ""
|
|
fi
|
|
|
|
# ========================================
|
|
# 2. 检查可用的锁屏相关服务
|
|
# ========================================
|
|
echo "========================================"
|
|
echo "Step 2: Available Lock Services"
|
|
echo "========================================"
|
|
echo ""
|
|
|
|
echo "Checking Session Bus Services:"
|
|
echo "-------------------------------"
|
|
|
|
# GNOME ScreenSaver
|
|
echo -n " org.gnome.ScreenSaver: "
|
|
if dbus-send --session --print-reply --dest=org.gnome.ScreenSaver \
|
|
/org/gnome/ScreenSaver \
|
|
org.freedesktop.DBus.Introspectable.Introspect &>/dev/null; then
|
|
echo -e "${GREEN}Available${NC}"
|
|
else
|
|
echo -e "${RED}Not available${NC}"
|
|
fi
|
|
|
|
# Deepin 相关服务
|
|
DEEPIN_SERVICES=(
|
|
"com.deepin.dde.lockFront"
|
|
"com.deepin.ScreenSaver"
|
|
"com.deepin.SessionManager"
|
|
"org.deepin.dde.lockFront"
|
|
)
|
|
|
|
for service in "${DEEPIN_SERVICES[@]}"; do
|
|
echo -n " $service: "
|
|
if dbus-send --session --print-reply --dest="$service" / \
|
|
org.freedesktop.DBus.Introspectable.Introspect &>/dev/null; then
|
|
echo -e "${GREEN}Available${NC}"
|
|
else
|
|
echo -e "${RED}Not available${NC}"
|
|
fi
|
|
done
|
|
|
|
echo ""
|
|
echo "Checking System Bus Services:"
|
|
echo "-----------------------------"
|
|
|
|
# systemd-logind
|
|
echo -n " org.freedesktop.login1: "
|
|
if dbus-send --system --print-reply --dest=org.freedesktop.login1 \
|
|
/org/freedesktop/login1 \
|
|
org.freedesktop.DBus.Introspectable.Introspect &>/dev/null; then
|
|
echo -e "${GREEN}Available${NC}"
|
|
else
|
|
echo -e "${RED}Not available${NC}"
|
|
fi
|
|
|
|
echo ""
|
|
|
|
# ========================================
|
|
# 3. 列出当前会话的所有可用信号
|
|
# ========================================
|
|
if [ -n "$SESSION_PATH" ]; then
|
|
echo "========================================"
|
|
echo "Step 3: Session Signals"
|
|
echo "========================================"
|
|
echo ""
|
|
echo "Available signals on $SESSION_PATH:"
|
|
echo ""
|
|
|
|
dbus-send --system --print-reply --dest=org.freedesktop.login1 \
|
|
"$SESSION_PATH" \
|
|
org.freedesktop.DBus.Introspectable.Introspect 2>/dev/null | \
|
|
grep -E "signal name" | sed 's/^[[:space:]]*/ /'
|
|
|
|
echo ""
|
|
fi
|
|
|
|
# ========================================
|
|
# 4. 创建临时监听脚本
|
|
# ========================================
|
|
echo "========================================"
|
|
echo "Step 4: Signal Monitoring Setup"
|
|
echo "========================================"
|
|
echo ""
|
|
|
|
TEMP_DIR="/tmp/lock_signal_test_$$"
|
|
mkdir -p "$TEMP_DIR"
|
|
|
|
# Session bus monitor
|
|
cat > "$TEMP_DIR/monitor_session.sh" << 'EOF'
|
|
#!/bin/bash
|
|
echo "=== Monitoring SESSION BUS ==="
|
|
echo "Listening for lock-related signals..."
|
|
echo ""
|
|
dbus-monitor --session "type='signal'" 2>&1 | \
|
|
grep --line-buffered -iE "signal|lock|Lock|screen|Screen|Active|active" | \
|
|
while IFS= read -r line; do
|
|
if echo "$line" | grep -q "signal"; then
|
|
echo "$(date '+%H:%M:%S') [SIGNAL] $line"
|
|
else
|
|
echo "$(date '+%H:%M:%S') $line"
|
|
fi
|
|
done
|
|
EOF
|
|
|
|
# System bus monitor
|
|
cat > "$TEMP_DIR/monitor_system.sh" << 'EOF'
|
|
#!/bin/bash
|
|
echo "=== Monitoring SYSTEM BUS ==="
|
|
echo "Listening for login1 Session signals..."
|
|
echo ""
|
|
dbus-monitor --system "type='signal',interface='org.freedesktop.login1.Session'" 2>&1 | \
|
|
grep --line-buffered -E "signal|Lock|Unlock|lock|unlock" | \
|
|
while IFS= read -r line; do
|
|
if echo "$line" | grep -q "signal"; then
|
|
echo "$(date '+%H:%M:%S') [SIGNAL] $line"
|
|
else
|
|
echo "$(date '+%H:%M:%S') $line"
|
|
fi
|
|
done
|
|
EOF
|
|
|
|
chmod +x "$TEMP_DIR/monitor_session.sh"
|
|
chmod +x "$TEMP_DIR/monitor_system.sh"
|
|
|
|
echo "Monitoring scripts created in: $TEMP_DIR"
|
|
echo ""
|
|
|
|
# ========================================
|
|
# 5. 开始监听
|
|
# ========================================
|
|
echo "========================================"
|
|
echo "Step 5: Real-time Signal Monitoring"
|
|
echo "========================================"
|
|
echo ""
|
|
echo -e "${YELLOW}Instructions:${NC}"
|
|
echo " 1. This script will now monitor DBus signals"
|
|
echo " 2. Open another terminal and lock your screen:"
|
|
echo " - Press Super+L (or Ctrl+Alt+L)"
|
|
echo " - Or run: gnome-screensaver-command -l"
|
|
echo " - Or run: dde-lock (on Deepin)"
|
|
echo " 3. Observe which signals appear below"
|
|
echo " 4. Unlock your screen"
|
|
echo " 5. Press Ctrl+C to stop monitoring"
|
|
echo ""
|
|
echo -e "${CYAN}Monitoring both SESSION and SYSTEM buses...${NC}"
|
|
echo ""
|
|
echo "========================================"
|
|
echo ""
|
|
|
|
# 创建日志文件
|
|
LOG_FILE="$TEMP_DIR/signals.log"
|
|
|
|
# 在后台启动两个监听器
|
|
"$TEMP_DIR/monitor_session.sh" 2>&1 | tee -a "$LOG_FILE" &
|
|
SESSION_PID=$!
|
|
|
|
"$TEMP_DIR/monitor_system.sh" 2>&1 | tee -a "$LOG_FILE" &
|
|
SYSTEM_PID=$!
|
|
|
|
# 等待用户中断
|
|
wait_for_user() {
|
|
while true; do
|
|
sleep 1
|
|
done
|
|
}
|
|
|
|
# 捕获 Ctrl+C
|
|
trap "echo ''; echo 'Stopping monitors...'; kill $SESSION_PID $SYSTEM_PID 2>/dev/null; exit 0" INT TERM
|
|
|
|
wait_for_user
|
|
|
|
# ========================================
|
|
# 清理
|
|
# ========================================
|
|
echo ""
|
|
echo "========================================"
|
|
echo "Cleanup"
|
|
echo "========================================"
|
|
echo ""
|
|
echo "Log file saved to: $LOG_FILE"
|
|
echo "You can review it with: cat $LOG_FILE"
|
|
echo ""
|
|
echo "To clean up: rm -rf $TEMP_DIR"
|
|
echo ""
|