diff options
| author | Maximilian Zhu <maximilian.zhu@loewenrot.de> | 2025-12-29 13:02:07 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-12-29 13:02:07 +0100 |
| commit | 59713a66e3dce8b2c006dc1ce7847b761d759147 (patch) | |
| tree | 212b8d683ab0aeb91da6f9250ff69a49139af52c | |
| parent | 7450439d789bf191ec97b04c89ecd84922e4cb4b (diff) | |
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)
| -rwxr-xr-x | config/hypr/UserScripts/WeatherWrap.sh | 26 |
1 files changed, 25 insertions, 1 deletions
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 |
