about summary refs log tree commit diff
diff options
context:
space:
mode:
authorManuel Palenzuela <manuelpalenzuelamerino@gmail.com>2019-06-30 12:32:11 +0200
committerManuel Palenzuela <manuelpalenzuelamerino@gmail.com>2019-06-30 12:32:11 +0200
commiteda4d3fe37d295919945ec66c791b1369055abff (patch)
treec86bbbd3617a11a56a55b70c552a96c87db052f3
parentFixed day/night detection (diff)
downloadsmart-wallpaper-eda4d3fe37d295919945ec66c791b1369055abff.tar.gz
smart-wallpaper-eda4d3fe37d295919945ec66c791b1369055abff.tar.bz2
smart-wallpaper-eda4d3fe37d295919945ec66c791b1369055abff.zip
Rewrite. Added exit function. Added good day/night checking + no overlaying of wallpapers
-rwxr-xr-xsmart-wallpaper74
1 files changed, 57 insertions, 17 deletions
diff --git a/smart-wallpaper b/smart-wallpaper
index e5dfac7..429ec1e 100755
--- a/smart-wallpaper
+++ b/smart-wallpaper
@@ -1,11 +1,22 @@
 #!/bin/bash
 
+trap cleanup EXIT
+
 input_daytimewallpaper=''
 input_nighttimewallpaper=''
 daytimewallpaper=''
 nighttimewallpaper=''
 location=''
 
+currenttime='pn5Lf1f8SH' #random string so the first loop works
+timebool=false
+
+cleanup() {
+  if [[ $(pidof gifview | wc -l) == 1 ]]; then
+    kill $(pidof gifview)
+  fi
+}
+
 print_usage() {
   echo "Usage: smart-wallpaper [FLAG]"
   echo "  Flags:"
@@ -16,12 +27,33 @@ print_usage() {
 }
 
 set_wallpaper() {
+
+  if [[ $(pidof gifview | wc -l) == 1 ]]; then
+    kill $(pidof gifview)
+  fi
+
   if [[ $1 == *".gif" ]] && [ -f /usr/bin/gifview ]; then
-    gifview --animate -w root $1
+    gifview --animate -w root $1 &
   else
-    #killall gifview# every 500h secs its settings the wallpaper but is it necessary (check if gifview proc?)
     feh --bg-fill $1
   fi
+
+}
+
+checktime() {
+  if [ "$location" != "" ]; then
+    if redshift -l $location -p | grep -i -q "$currenttime"; then
+      timebool=true
+    else
+      timebool=false
+    fi
+  else
+    if redshift -p | grep -i -q "$currenttime"; then
+      timebool=true
+    else
+      timebool=false
+    fi
+  fi
 }
 
 if (( $# == 0 )); then
@@ -57,25 +89,33 @@ nighttimewallpaper=$(find $input_nighttimewallpaper -type f | shuf -n 1)
 while true
 do
 
-  if [ "$location" != "" ]; then
-    string=$(redshift -l $location -p)
-    shopt -s nocasematch
-    if [[ $string == *"day"* ]]; then
-      set_wallpaper "$daytimewallpaper"
-    else
-      set_wallpaper "$nighttimewallpaper"
-    fi
-    shopt -u nocasematch
+  checktime
+
+  if [ $timebool == true ]; then
+    echo "same"
+    #:
   else
-    string=$(redshift -p)
-    shopt -s nocasematch
-    if [[ $string == *"day"* ]]; then
-      set_wallpaper "$daytimewallpaper"
+    echo "diifferent"
+    echo $currenttime
+    if [ "$location" != "" ]; then
+      if redshift -l $location -p | grep -i -q "day"; then
+        currenttime="day"
+        set_wallpaper "$daytimewallpaper"
+      else
+        currenttime="night"
+        set_wallpaper "$nighttimewallpaper"
+      fi
     else
-      set_wallpaper "$nighttimewallpaper"
+      if redshift -p | grep -i -q "day"; then
+        currenttime="day"
+        set_wallpaper "$daytimewallpaper"
+      else
+        currenttime="night"
+        set_wallpaper "$nighttimewallpaper"
+      fi
     fi
-    shopt -u nocasematch
   fi
+    echo $currenttime
 
   sleep 500s
 done