From 59713a66e3dce8b2c006dc1ce7847b761d759147 Mon Sep 17 00:00:00 2001 From: Maximilian Zhu Date: Mon, 29 Dec 2025 13:02:07 +0100 Subject: Add network check to WeatherWrap script Added a network connectivity check function to determine if the script can proceed with fetching weather data. If no network is available, it returns an offline status. (It will show an offline Icon in Waybar after waking up from `systemctl suspend` or `systemctl hibernate` and having no network. If you click it in waybar it will recheck, but this is unintended) --- config/hypr/UserScripts/WeatherWrap.sh | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'config/hypr/UserScripts') diff --git a/config/hypr/UserScripts/WeatherWrap.sh b/config/hypr/UserScripts/WeatherWrap.sh index 10c125dc..5b266930 100755 --- a/config/hypr/UserScripts/WeatherWrap.sh +++ b/config/hypr/UserScripts/WeatherWrap.sh @@ -6,6 +6,30 @@ SCRIPT_DIR="$(dirname "$0")" PY_SCRIPT="$SCRIPT_DIR/Weather.py" BASH_FALLBACK="$SCRIPT_DIR/Weather.sh" +# Function to check network connectivity +check_network() { + # Try multiple methods to check network + if ping -c1 -W2 8.8.8.8 >/dev/null 2>&1; then + return 0 + fi + + if ping -c1 -W2 1.1.1.1 >/dev/null 2>&1; then + return 0 + fi + + if curl -s --connect-timeout 3 "https://ipinfo.io" >/dev/null 2>&1; then + return 0 + fi + + return 1 +} + +# If no network, return offline status immediately +if ! check_network; then + echo '{"text":"󰖪", "alt":"Offline", "tooltip":"No network connection"}' + exit 0 +fi + run_fallback() { if [ -f "$BASH_FALLBACK" ]; then # Invoke via bash to avoid requiring +x and ensure consistent shell @@ -30,4 +54,4 @@ else echo "python3 not found in PATH — falling back to Weather.sh" >&2 run_fallback "$@" exit $? -fi \ No newline at end of file +fi -- cgit v1.2.3