From 449a01420a4ae5da1285f9b56b961dfa9164550f Mon Sep 17 00:00:00 2001 From: Krzysztof kuhy Rudnicki Date: Fri, 6 Feb 2026 21:00:40 +0100 Subject: [PATCH] feat: brother printer checker --- .../digital_wellbeing/focus_mode_daemon.py | 21 ++++++-- .../pacman/pacman_blocked_keywords.txt | 3 +- .../pacman/pacman_whitelist.txt | 1 + scripts/utils/check_brother_printer.sh | 48 +++++++++++++++++++ 4 files changed, 66 insertions(+), 7 deletions(-) create mode 100755 scripts/utils/check_brother_printer.sh diff --git a/scripts/digital_wellbeing/focus_mode_daemon.py b/scripts/digital_wellbeing/focus_mode_daemon.py index f7c07e3..853fd8a 100755 --- a/scripts/digital_wellbeing/focus_mode_daemon.py +++ b/scripts/digital_wellbeing/focus_mode_daemon.py @@ -45,6 +45,15 @@ BROWSER_PATTERNS = frozenset([ "opera", "microsoft-edge", "ungoogled-chromium", + "thorium", +]) + +# Electron apps that should NOT be treated as browsers +# These use Chromium under the hood but are not web browsers +ELECTRON_IGNORE = frozenset([ + "electron", + "code", # VS Code + "chrome_crashpad", # Crashpad handler used by all Electron apps ]) # Patterns to ignore (browser helpers that aren't the main browser) @@ -52,6 +61,7 @@ IGNORE_PATTERNS = frozenset([ "crashhandler", "update", "helper", + "crashpad", ]) @@ -115,13 +125,14 @@ def is_steam_running(processes: Set[str]) -> bool: def is_browser_running(processes: Set[str]) -> bool: """Check if any browser is running.""" for proc in processes: - # Skip ignored patterns + # Skip Electron apps and ignored patterns + if proc in ELECTRON_IGNORE: + continue if any(ign in proc for ign in IGNORE_PATTERNS): continue - # Check browser patterns - for pattern in BROWSER_PATTERNS: - if pattern in proc: - return True + # Use exact match to avoid false positives from Electron apps + if proc in BROWSER_PATTERNS: + return True return False diff --git a/scripts/digital_wellbeing/pacman/pacman_blocked_keywords.txt b/scripts/digital_wellbeing/pacman/pacman_blocked_keywords.txt index 8c54a5e..aa9d9ac 100644 --- a/scripts/digital_wellbeing/pacman/pacman_blocked_keywords.txt +++ b/scripts/digital_wellbeing/pacman/pacman_blocked_keywords.txt @@ -56,5 +56,4 @@ youtube # Chrome/Chromium variants google-chrome chromium -ungoogled-chromium -thorium +ungoogled-chromium \ No newline at end of file diff --git a/scripts/digital_wellbeing/pacman/pacman_whitelist.txt b/scripts/digital_wellbeing/pacman/pacman_whitelist.txt index bfc1963..425693f 100644 --- a/scripts/digital_wellbeing/pacman/pacman_whitelist.txt +++ b/scripts/digital_wellbeing/pacman/pacman_whitelist.txt @@ -1,4 +1,5 @@ # Exact package names that should bypass the block even if matching a keyword. +thorium-browser-bin minizip miniupnpc haskell-generically diff --git a/scripts/utils/check_brother_printer.sh b/scripts/utils/check_brother_printer.sh new file mode 100755 index 0000000..17b3d02 --- /dev/null +++ b/scripts/utils/check_brother_printer.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash +# Check Brother laser printer consumable/maintenance status. +# Thin wrapper that ensures dependencies are present, then runs the +# Python implementation in ~/testsAndMisc/python_pkg/brother_printer. +# +# Usage: +# ./check_brother_printer.sh # auto-detect USB or network +# ./check_brother_printer.sh # force network/SNMP mode + +set -euo pipefail + +PYTHON_PKG_DIR="${HOME}/testsAndMisc/python_pkg" +BROTHER_MODULE="brother_printer" + +# ── Ensure dependencies ───────────────────────────────────────────── + +check_dependency() { + local cmd="$1" pkg="$2" + if ! command -v "$cmd" &>/dev/null; then + echo "Installing $pkg..." + sudo pacman -S --noconfirm --needed "$pkg" + fi +} + +check_dependency python3 python +check_dependency lsusb usbutils + +# net-snmp is optional (only needed for network mode) +if [[ -n "${1:-}" ]] && ! command -v snmpwalk &>/dev/null; then + echo "Installing net-snmp (needed for network mode)..." + sudo pacman -S --noconfirm --needed net-snmp +fi + +# ── Verify the Python module exists ────────────────────────────────── + +if [[ ! -f "${PYTHON_PKG_DIR}/${BROTHER_MODULE}/check_brother_printer.py" ]]; then + echo "Error: Python module not found at ${PYTHON_PKG_DIR}/${BROTHER_MODULE}/" >&2 + exit 1 +fi + +# ── Run (with sudo for USB access) ────────────────────────────────── + +if [[ $EUID -ne 0 ]]; then + exec sudo bash -c "cd '$PYTHON_PKG_DIR' && python3 -m '$BROTHER_MODULE' $*" +fi + +cd "$PYTHON_PKG_DIR" +exec python3 -m "$BROTHER_MODULE" "$@"