feat: better screen lock checker

This commit is contained in:
Krzysztof Rudnicki 2026-03-08 21:39:39 +01:00
parent 7d537c134a
commit a71bcc5e98
2 changed files with 79 additions and 22 deletions

View File

@ -2,14 +2,14 @@
# Script to add screen locker to i3 autostart # Script to add screen locker to i3 autostart
# This will run the workout screen locker on system startup # This will run the workout screen locker on system startup
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SCREEN_LOCK_PATH="$SCRIPT_DIR/screen_lock.py" SCREEN_LOCK_PATH="$SCRIPT_DIR/screen_lock.py"
I3_CONFIG="$HOME/.config/i3/config" I3_CONFIG="$HOME/.config/i3/config"
# Check if screen_lock.py exists # Check if screen_lock.py exists
if [ ! -f "$SCREEN_LOCK_PATH" ]; then if [ ! -f "$SCREEN_LOCK_PATH" ]; then
echo "Error: screen_lock.py not found at $SCREEN_LOCK_PATH" echo "Error: screen_lock.py not found at $SCREEN_LOCK_PATH"
exit 1 exit 1
fi fi
# Make sure screen_lock.py is executable # Make sure screen_lock.py is executable
@ -17,31 +17,31 @@ chmod +x "$SCREEN_LOCK_PATH"
# Check if i3 config exists # Check if i3 config exists
if [ ! -f "$I3_CONFIG" ]; then if [ ! -f "$I3_CONFIG" ]; then
echo "Error: i3 config not found at $I3_CONFIG" echo "Error: i3 config not found at $I3_CONFIG"
echo "Please create i3 config first or specify correct path" echo "Please create i3 config first or specify correct path"
exit 1 exit 1
fi fi
# Check if autostart line already exists # Check if autostart line already exists
if grep -q "exec.*screen_lock.py" "$I3_CONFIG"; then if grep -q "exec.*screen_lock.py" "$I3_CONFIG"; then
echo "Screen locker autostart already configured in i3 config" echo "Screen locker autostart already configured in i3 config"
echo "Current line:" echo "Current line:"
grep "exec.*screen_lock.py" "$I3_CONFIG" grep "exec.*screen_lock.py" "$I3_CONFIG"
read -p "Do you want to replace it? (y/n) " -n 1 -r read -p "Do you want to replace it? (y/n) " -n 1 -r
echo echo
if [[ $REPLY =~ ^[Yy]$ ]]; then if [[ $REPLY =~ ^[Yy]$ ]]; then
# Remove old line # Remove old line
sed -i '/exec.*screen_lock\.py/d' "$I3_CONFIG" sed -i '/exec.*screen_lock\.py/d' "$I3_CONFIG"
else else
echo "Keeping existing configuration" echo "Keeping existing configuration"
exit 0 exit 0
fi fi
fi fi
# Add autostart line to i3 config # Add autostart line to i3 config
echo "" >> "$I3_CONFIG" echo "" >>"$I3_CONFIG"
echo "# Workout screen locker on startup (production mode)" >> "$I3_CONFIG" echo "# Workout screen locker on startup (production mode)" >>"$I3_CONFIG"
echo "exec --no-startup-id python3 $SCREEN_LOCK_PATH --production" >> "$I3_CONFIG" echo "exec --no-startup-id python3 $SCREEN_LOCK_PATH --production" >>"$I3_CONFIG"
echo "✓ Screen locker added to i3 autostart (production mode)" echo "✓ Screen locker added to i3 autostart (production mode)"
echo "✓ Configuration added to: $I3_CONFIG" echo "✓ Configuration added to: $I3_CONFIG"
@ -50,3 +50,24 @@ echo "The screen locker will run on next i3 restart/login"
echo "" echo ""
echo "To test now, run: i3-msg restart" echo "To test now, run: i3-msg restart"
echo "To run in demo mode, remove --production flag from $I3_CONFIG" echo "To run in demo mode, remove --production flag from $I3_CONFIG"
# Check autostart installation status
echo ""
echo "=== Autostart Status ==="
if grep -q "exec.*screen_lock.py" "$I3_CONFIG"; then
echo "✓ i3 autostart: INSTALLED"
grep "exec.*screen_lock.py" "$I3_CONFIG"
else
echo "✗ i3 autostart: NOT INSTALLED"
fi
if systemctl --user is-enabled workout-locker.service &>/dev/null; then
echo "✓ systemd service: INSTALLED and enabled"
else
echo " systemd service: not installed"
fi
# Immediately check if today's workout is done; block if not
echo ""
echo "=== Checking today's workout status ==="
python3 "$SCREEN_LOCK_PATH" --production

View File

@ -1,11 +1,26 @@
#!/bin/bash #!/bin/bash
# Install workout locker as a systemd user service # Install workout locker as a systemd user service
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SCREEN_LOCK_PATH="$SCRIPT_DIR/screen_lock.py"
SERVICE_FILE="$SCRIPT_DIR/workout-locker.service" SERVICE_FILE="$SCRIPT_DIR/workout-locker.service"
USER_SERVICE_DIR="$HOME/.config/systemd/user" USER_SERVICE_DIR="$HOME/.config/systemd/user"
SERVICE_NAME="workout-locker.service" SERVICE_NAME="workout-locker.service"
# Check if service is already installed
if [ -f "$USER_SERVICE_DIR/$SERVICE_NAME" ]; then
echo "Screen locker systemd service is already installed."
echo "Current status:"
systemctl --user status "$SERVICE_NAME" --no-pager || true
echo ""
read -p "Do you want to reinstall/update it? (y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Keeping existing installation"
exit 0
fi
fi
# Create user systemd directory if it doesn't exist # Create user systemd directory if it doesn't exist
mkdir -p "$USER_SERVICE_DIR" mkdir -p "$USER_SERVICE_DIR"
@ -28,3 +43,24 @@ echo "To start now: systemctl --user start workout-locker"
echo "To check status: systemctl --user status workout-locker" echo "To check status: systemctl --user status workout-locker"
echo "To stop: systemctl --user stop workout-locker" echo "To stop: systemctl --user stop workout-locker"
echo "To disable autostart: systemctl --user disable workout-locker" echo "To disable autostart: systemctl --user disable workout-locker"
# Check autostart installation status
echo ""
echo "=== Autostart Status ==="
if systemctl --user is-enabled "$SERVICE_NAME" &>/dev/null; then
echo "✓ systemd service: INSTALLED and enabled"
else
echo "✗ systemd service: NOT enabled"
fi
I3_CONFIG="$HOME/.config/i3/config"
if [ -f "$I3_CONFIG" ] && grep -q "exec.*screen_lock.py" "$I3_CONFIG"; then
echo "✓ i3 autostart: INSTALLED"
else
echo " i3 autostart: not installed"
fi
# Immediately check if today's workout is done; block if not
echo ""
echo "=== Checking today's workout status ==="
python3 "$SCREEN_LOCK_PATH" --production