diff --git a/home-manager/services/neverssl-keepalive/keepalive.sh b/home-manager/services/neverssl-keepalive/keepalive.sh index d18f3bc41..68a805666 100755 --- a/home-manager/services/neverssl-keepalive/keepalive.sh +++ b/home-manager/services/neverssl-keepalive/keepalive.sh @@ -6,3 +6,15 @@ set -euo pipefail # Silently ping neverssl.com - ignore failures (network may be unavailable) curl -fsS --max-time 10 http://neverssl.com >/dev/null 2>&1 || true + +# macOS-specific: Open captive portal for Starbucks WiFi if connectivity is lost +if [[ $OSTYPE == "darwin"* ]]; then + SSID=$(networksetup -getairportnetwork en0 2>/dev/null | awk -F": " '{print $2}' || echo "") + + # Check for Starbucks networks (e.g., at_STARBUCKS_Wi2) + if [[ $SSID == *"STARBUCKS"* ]]; then + if ! ping -c 1 -W 2 1.1.1.1 >/dev/null 2>&1; then + open "http://captive.apple.com" 2>/dev/null || true + fi + fi +fi diff --git a/spec/keepalive_spec.sh b/spec/keepalive_spec.sh index e95e8c757..c2c3fcdd6 100644 --- a/spec/keepalive_spec.sh +++ b/spec/keepalive_spec.sh @@ -83,4 +83,27 @@ The output should include 'captive portal' End End +Describe 'Starbucks WiFi detection (macOS)' +It 'checks for macOS via OSTYPE' +When run bash -c "cat '$SCRIPT'" +The output should include 'OSTYPE' +The output should include 'darwin' +End + +It 'uses networksetup to get SSID' +When run bash -c "cat '$SCRIPT'" +The output should include 'networksetup -getairportnetwork' +End + +It 'checks for STARBUCKS SSID pattern' +When run bash -c "cat '$SCRIPT'" +The output should include '*"STARBUCKS"*' +End + +It 'opens captive portal when connectivity fails' +When run bash -c "cat '$SCRIPT'" +The output should include 'captive.apple.com' +End +End + End