Skip to content
This repository has been archived by the owner on May 27, 2023. It is now read-only.

Commit

Permalink
Added connection timeout - Issue #2
Browse files Browse the repository at this point in the history
  • Loading branch information
katernet committed Sep 27, 2018
1 parent 43b400f commit 5cbe4de
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Darkmode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
## macOS Dark Mode at sunset
## Solar times pulled from Yahoo Weather API
## Author: katernet ## Version 1.7.1
## Author: katernet ## Version 1.7.2

## Global variables ##
darkdir=~/Library/Application\ Support/darkmode # darkmode directory
Expand Down Expand Up @@ -71,6 +71,17 @@ darkMode() {

# Solar query
solar() {
# Check for connection to Yahoo API
time=$(date +%s)
while true && [ $(( $(date +%s) - 20)) -lt $time ]; do # Sccessful connection or 20s timeout
if curl -s query.yahooapis.com; then
break
else # Timeout
sleep 20
echo "Connection timeout. Exiting."
exit 1
fi
done
# Set location
# Get city and nation from http://ipinfo.io
loc=$(curl -s ipinfo.io/geo | awk -F: '{print $2}' | awk 'FNR ==3 {print}' | sed 's/[", ]//g')
Expand Down

0 comments on commit 5cbe4de

Please sign in to comment.