update
This commit is contained in:
@@ -47,7 +47,7 @@
|
||||
// "on-click-right": "fuzzel -l 0 -p '>> ' | xargs -r sh -c",
|
||||
// "on-click": "fuzzel",
|
||||
// "on-click-middle": "pkill -9 fuzzel",
|
||||
"on-click": "eww open main --toggle",
|
||||
// "on-click": "eww open main --toggle",
|
||||
"on-click-right": "pkill rofi || rofi -show drun",
|
||||
"min-length": 2,
|
||||
"max-length": 2
|
||||
@@ -71,7 +71,6 @@
|
||||
"group/monitors": {
|
||||
"modules": [
|
||||
"network#speed",
|
||||
"custom/publicip",
|
||||
"temperature",
|
||||
"memory",
|
||||
"cpu",
|
||||
@@ -94,16 +93,6 @@
|
||||
"tooltip-format-disconnected": " Disconnected",
|
||||
"min-length": 20
|
||||
},
|
||||
"custom/publicip": {
|
||||
"interval": 30,
|
||||
"return-type": "json",
|
||||
"format": " {text}",
|
||||
"tooltip-format": "{alt}",
|
||||
"max-length": 6,
|
||||
"min-length": 6,
|
||||
"exec": "$HOME/.config/waybar/modules/publicip.sh",
|
||||
"on-click": "rm -f $HOME/.config/waybar/modules/publicip.cache && sleep 0.1"
|
||||
},
|
||||
"temperature": {
|
||||
"interval": 5,
|
||||
"thermal-zone": 6,
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck disable=SC1091,SC1090
|
||||
|
||||
# Entries in publicip.conf:
|
||||
# IP_QUERY_URL: URL to query public IP of the system.
|
||||
# return: JSON object with "ip" field.
|
||||
# note: This URL will be queried with short intervals (60s for example),
|
||||
# therefore it may not be a good idea to use a public API with
|
||||
# a limited number of calls.
|
||||
# IP_INFO_URL: URL to query IP location.
|
||||
# placeholder: <ip>
|
||||
# return: JSON object with "country_code" field.
|
||||
# note: This URL will only be quetried when public IP changes or when "force" is given as parameter.
|
||||
|
||||
path="$(dirname "$(readlink -f "$0")")"
|
||||
cache_file="$path/publicip.cache"
|
||||
config_file="$path/publicip.conf"
|
||||
time_log="$path/publicip.log"
|
||||
|
||||
[ -f "$config_file" ] || exit 1
|
||||
. "$config_file"
|
||||
[ -z "$IP_QUERY_URL" ] && exit 1
|
||||
[ -z "$IP_INFO_URL" ] && exit 1
|
||||
[ "$1" == "force" ] && rm -f "$cache_file"
|
||||
[ -f "$cache_file" ] && . "$cache_file"
|
||||
|
||||
# Try to check network connectivity before querying
|
||||
if ! ping -c 1 -W 2 1.1.1.1 >/dev/null 2>&1; then
|
||||
# No network, return cached values if available
|
||||
[ -z "$CACHED_IP" ] && CACHED_IP="N/A"
|
||||
[ -z "$CACHED_CODE" ] && CACHED_CODE="N/A"
|
||||
|
||||
echo "$(date +%Y-%m-%dT%H:%M:%S) - Waiting for network" >>"$time_log"
|
||||
|
||||
jq -n --unbuffered --compact-output \
|
||||
--arg ip "$CACHED_IP" \
|
||||
--arg country "$CACHED_CODE" \
|
||||
'{alt: $ip, text: $country}'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
ip_current=$(curl -s -L -4 "$IP_QUERY_URL" | jq -r '.ip')
|
||||
[ -z "$ip_current" ] && exit 1
|
||||
|
||||
if [ "$ip_current" != "$CACHED_IP" ]; then
|
||||
echo "$(date +%Y-%m-%dT%H:%M:%S) - IP changed: $CACHED_IP -> $ip_current" >>"$time_log"
|
||||
CACHED_IP="$ip_current"
|
||||
|
||||
ip_info_url=${IP_INFO_URL//<ip>/$ip_current}
|
||||
CACHED_CODE=$(curl -s -L "$ip_info_url" | jq -r '.country_code')
|
||||
[ -z "$CACHED_CODE" ] && CACHED_CODE="N/A"
|
||||
|
||||
echo "CACHED_IP=$CACHED_IP" >"$cache_file"
|
||||
echo "CACHED_CODE=$CACHED_CODE" >>"$cache_file"
|
||||
notify-send "New Public IP detected" "New IP: $ip_current\nCountry: $CACHED_CODE"
|
||||
fi
|
||||
|
||||
jq -n --unbuffered --compact-output \
|
||||
--arg ip "$CACHED_IP" \
|
||||
--arg country "$CACHED_CODE" \
|
||||
'{alt: $ip, text: $country}'
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
# Terminate already running bar instances
|
||||
killall -q waybar
|
||||
|
||||
# Wait until the processes have been shut down
|
||||
while pgrep -x waybar -u "$USER" >/dev/null; do sleep 1; done
|
||||
|
||||
# Launch main
|
||||
waybar &
|
||||
Reference in New Issue
Block a user