mirror of
https://github.com/kuhyx/screen-locker.git
synced 2026-11-10 20:07:16 +01:00
Some checks are pending
pre-commit / pre-commit (push) Waiting to run
Tests / test (3.10) (push) Waiting to run
Tests / test (3.11) (push) Waiting to run
Tests / test (3.12) (push) Waiting to run
Tests / lock-popup-safety (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
A real StrongLifts session on 2026-08-10 never reached this machine, so it had to be logged as a manual workout -- spending a manual budget slot on a workout that was genuinely verified. The session was in Firebase the whole time; four separate defects each hid it. - pull_synced_workout() read a hardcoded devices/phone/log.json. Sinceffc6c72the phone pushes under a per-install uuid, so that directory has been frozen since 2026-07-17 and the PC kept returning a stale session from 07-27 as if it were current. Both readers now walk EVERY device directory; reinstalls keep minting new ones, so no single path can be right for long. - A session is identified by SHAPE (it has `exercises`), not by a `kind` field the phone never writes. That filter is why the one reader that did walk every directory discarded real sessions, and it also kept PC-origin runnerup/phone_verified records from being handed to a caller expecting a session. - FirebaseSyncError is a SIBLING of GitHubSyncError, not a subclass, so `except GitHubSyncError` never caught it and a DNS failure took the whole locker down (status=1/FAILURE, then a restart loop). Catch the common parent; a pull failure degrades to a warning. - A GitHub token is no longer required to sync. Firebase has been primary sinceeb4ff01, so a Firebase-only machine was reporting "sync is OFF" while syncing fine. Sync also only ran once per locker start, so a workout finished after login was invisible until the next login. workout-sync.timer runs the new headless --sync-only every 15 minutes; remove_systemd.sh now removes every unit the installer creates, not just two of them. workout_app: the 2026-08-05 reinstall wiped progression because the DB seeds factory defaults before the backup is restored, and the first write then exported those defaults over the only off-device copy. Storage permission is now settled before the DB opens, a defaults-only DB refuses to overwrite a richer backup, and the three swallowed storage errors say what broke. Sessions that exist only in Firebase/GitHub are restored into local history, so a reinstalled app has the history it actually earned rather than starting at whatever survived. Matched on (date, start_time), so re-syncing never duplicates and local rows always win. Adds a target-reps editor: progression can only ever RAISE reps, so a rep target a defaults re-seed set wrong could not be corrected from the UI at all. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JS5V44jkHZiH1wC7BH5h5n
117 lines
4.4 KiB
Bash
Executable File
117 lines
4.4 KiB
Bash
Executable File
#!/bin/bash
|
|
# Install workout locker as a systemd user service
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
SERVICE_FILE="$SCRIPT_DIR/workout-locker.service"
|
|
EARLY_BIRD_TIMER_FILE="$SCRIPT_DIR/early-bird-workout-check.timer"
|
|
SYNC_SERVICE_FILE="$SCRIPT_DIR/workout-sync.service"
|
|
SYNC_TIMER_FILE="$SCRIPT_DIR/workout-sync.timer"
|
|
USER_SERVICE_DIR="$HOME/.config/systemd/user"
|
|
SERVICE_NAME="workout-locker.service"
|
|
EARLY_BIRD_TIMER_NAME="early-bird-workout-check.timer"
|
|
SYNC_SERVICE_NAME="workout-sync.service"
|
|
SYNC_TIMER_NAME="workout-sync.timer"
|
|
|
|
# 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
|
|
mkdir -p "$USER_SERVICE_DIR"
|
|
|
|
# Remove old timer if it was previously installed
|
|
if systemctl --user is-active "workout-locker.timer" &>/dev/null; then
|
|
systemctl --user disable --now "workout-locker.timer" 2>/dev/null || true
|
|
fi
|
|
rm -f "$USER_SERVICE_DIR/workout-locker.timer"
|
|
|
|
# Seed shutdown_base.json with base=21 if not already present
|
|
SHUTDOWN_BASE="$SCRIPT_DIR/screen_locker/shutdown_base.json"
|
|
if [[ ! -f "$SHUTDOWN_BASE" ]]; then
|
|
printf '{\n "base_mon_wed_hour": 21,\n "base_thu_sun_hour": 21,\n "last_reset_date": ""\n}\n' > "$SHUTDOWN_BASE"
|
|
echo "✓ Created shutdown_base.json with base=21:00"
|
|
fi
|
|
|
|
# Copy service file to user systemd directory
|
|
cp "$SERVICE_FILE" "$USER_SERVICE_DIR/$SERVICE_NAME"
|
|
|
|
# Copy early bird timer
|
|
cp "$EARLY_BIRD_TIMER_FILE" "$USER_SERVICE_DIR/$EARLY_BIRD_TIMER_NAME"
|
|
|
|
# Copy the periodic workout-sync units. Without these, syncing happens only
|
|
# once per locker start, so a workout finished after login is not seen until
|
|
# the next login.
|
|
cp "$SYNC_SERVICE_FILE" "$USER_SERVICE_DIR/$SYNC_SERVICE_NAME"
|
|
cp "$SYNC_TIMER_FILE" "$USER_SERVICE_DIR/$SYNC_TIMER_NAME"
|
|
|
|
# Update paths in the service file to use absolute paths
|
|
REPO_ROOT="$SCRIPT_DIR"
|
|
sed -i "s|WorkingDirectory=.*|WorkingDirectory=$REPO_ROOT|" "$USER_SERVICE_DIR/$SERVICE_NAME"
|
|
sed -i "s|Environment=PYTHONPATH=.*|Environment=PYTHONPATH=$REPO_ROOT|" "$USER_SERVICE_DIR/$SERVICE_NAME"
|
|
sed -i "s|ExecStart=/usr/bin/python3.*|ExecStart=/usr/bin/python3 -m screen_locker.screen_lock --production|" "$USER_SERVICE_DIR/$SERVICE_NAME"
|
|
|
|
# Reload systemd daemon
|
|
systemctl --user daemon-reload
|
|
|
|
# Enable the service to start on login (one-shot, no periodic timer)
|
|
systemctl --user enable "$SERVICE_NAME"
|
|
|
|
# Enable the early bird re-check timer
|
|
systemctl --user enable --now "$EARLY_BIRD_TIMER_NAME"
|
|
|
|
# Enable the periodic workout sync
|
|
systemctl --user enable --now "$SYNC_TIMER_NAME"
|
|
|
|
echo "✓ Workout locker service installed"
|
|
echo "✓ Early bird re-check timer installed (fires daily at 08:30)"
|
|
echo "✓ Service will start automatically on next login"
|
|
echo ""
|
|
echo "To start now: systemctl --user start workout-locker"
|
|
echo "To check status: systemctl --user status workout-locker"
|
|
echo "To stop: systemctl --user stop 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
|
|
if systemctl --user is-enabled "$EARLY_BIRD_TIMER_NAME" &>/dev/null; then
|
|
echo "✓ early bird timer: INSTALLED and enabled"
|
|
else
|
|
echo "✗ early bird timer: NOT enabled"
|
|
fi
|
|
if systemctl --user is-enabled "$SYNC_TIMER_NAME" &>/dev/null; then
|
|
echo "✓ workout sync timer: INSTALLED and enabled (every 15 min)"
|
|
else
|
|
echo "✗ workout sync timer: 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"
|
|
echo ""
|
|
echo "To add i3 startup hook (recommended), add this line to $I3_CONFIG:"
|
|
echo " exec --no-startup-id /usr/bin/python3 -m screen_locker.screen_lock --production"
|
|
fi
|
|
|
|
# Immediately check if today's workout is done; block if not
|
|
echo ""
|
|
echo "=== Checking today's workout status ==="
|
|
PYTHONPATH="$SCRIPT_DIR" python3 -m screen_locker.screen_lock --production
|