bcyran / timewall

Apple dynamic HEIF wallpapers on GNU/Linux.
MIT License
46 stars 1 forks source link

timewall set /path/to/image.heic after reboot need re-ran. #116

Closed rizitis closed 1 month ago

rizitis commented 1 month ago

Hello, thanks for your nice work!

I have build and install, {as package }, timewall-1.2.0 for Slackware-current. My ~/.config/timewall/config.toml is:

[location]
lat = 35.51
lon = 24.01

I also use rc.timewall script to call timewall set --daemon on startup:

#!/bin/sh
#
# rc.timewall: Slackware-style init script for timewall (dynamic wallpaper daemon)
# you can call it from rc.local on start up.

DAEMON=/usr/bin/timewall  # Adjust the path if your timewall binary is elsewhere
DAEMON_OPTS="set --daemon"
PIDFILE=/var/run/timewall.pid
LOGFILE=/var/log/timewall.log

start() {
    echo "Starting timewall..."
    if [ -f "$PIDFILE" ]; then
        echo "timewall is already running."
        return 1
    fi
    nohup $DAEMON $DAEMON_OPTS > $LOGFILE 2>&1 &
    echo $! > "$PIDFILE"
    echo "timewall started with PID $(cat $PIDFILE)."
}

stop() {
    echo "Stopping timewall..."
    if [ ! -f "$PIDFILE" ]; then
        echo "timewall is not running."
        return 1
    fi
    kill "$(cat $PIDFILE)"
    rm -f "$PIDFILE"
    echo "timewall stopped."
}

restart() {
    stop
    sleep 2
    start
}

status() {
    if [ -f "$PIDFILE" ]; then
        echo "timewall is running with PID $(cat $PIDFILE)."
    else
        echo "timewall is not running."
    fi
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        restart
        ;;
    status)
        status
        ;;
    *)
        echo "Usage: $0 {start|stop|restart|status}"
        exit 1
        ;;
esac

exit 0

My issue is this:
After reboot although daemon is up and wallpaper is the last one I used. Wallpaper status stuck in the status before last shutdown.
For example if I shutdown laptop 12:00am and power on again 8:00 am, wallpaper will stuck in 12:00am status and not refresh although daemon is ranning.
And If I ran manually timewall set /path/to/image.heic then immediately switch to the correct status and following time cycle as excepted during day time!
I was wondering if you have any suggestions how I can handle this "personal" issue?

thank you.

rizitis commented 1 month ago

If I check log file I have this error when I call daemon on startup: cat timewall.log Error: no image to set given

rizitis commented 1 month ago

I solved it by creating a desktop.entry in ~/.config/autostart/
This way no rc.script or anything else needed. After $USER login timewall set /path/to/image executed and everything is ok.

bcyran commented 1 month ago

Hi! I see that you already solved the issue but I will share my thoughts anyway.

Am I correct in the assumption that your rc script was ran as root? timewall stores its data, including the currently set wallpaper, in the home directory of the user who runs it. So if your daemon runs as root, it won't be able to see settings made using your regular user account. Basically, you need to run all timewall commands as the same user.

You could work around that by overriding the cache directory using TIMEWALL_CACHE_DIR env variable. Just a warning that it's undocumented, exists mainly for tests and isn't really a feature.

rizitis commented 1 month ago

thanks for answer. you are 100% right! when i noticed that calling timewall from rc.local as root was the problem i found the solution to call it from ~/.config/autostart/ because I want a KISS and global solution for all Desktop Environments .

> cat run_timewall.desktop 
[Desktop Entry]
Type=Application
Exec=/usr/bin/timewall set /home/omen/Pictures/Backgrounds/City.heic
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name=Run Timewall
Comment=Runs Timewall script at login

But this TIMEWALL_CACHE_DIR option you suggested is something very interesting and I would play with it for sure...
First idea inspired from cache_dir... was to edit exec in desktop entry like this:

[Desktop Entry]
Type=Application
Exec=sh -c '/usr/bin/timewall set $(readlink -f /home/omen/.cache/timewall/last_wall)'
....

which work fine!

Second idea is a separate script, (assume a folder with some images.heic exist) ./cyclic_wallpapers.sh > /dev/null 2>&1 &

#!/bin/bash

image_folder="/home/omen/Pictures/Backgrounds"

while true; do
    for image in "$image_folder"/*; do
        ln -sf "$image" ~/.cache/timewall/last_wall

        /usr/bin/timewall set $(readlink -f ~/.cache/timewall/last_wall)
     sleep 120
  done
done

Any way I will follow your project :) regards!