wallpaper-changer systemd service - working

This commit is contained in:
Sam 2024-05-12 12:35:31 +01:00
parent 03495183b2
commit be4163dcd4
2 changed files with 12 additions and 29 deletions

View File

@ -8,10 +8,10 @@
imports = [
../wallpaper-changer/swww-wallpaper-changer
];
wayland.windowManager.hyprland = {
enable = true;
systemd = {
variables = ["--all"];
enable = true;
# Same as default, but stop graphical-session too
extraCommands = lib.mkBefore [

View File

@ -6,45 +6,28 @@
systemd.user.services.wallpaper-changer = {
Unit = {
Description = "Script to change wallpaper using swww";
After = [ "graphical-session.target" ]; # or "wayland.target", depending on your system setup
#After = [ "hyprland-session.target" ];
PartOf = [ "hyprland-session.target" ];
After = [ "hyprland-session.target" ]; # or "wayland.target", depending on your system setup
};
Install = {
WantedBy = [ "default.target" ];
};
Service = {
Restart = "on-failure"; # This will make the service restart on failure
ExecStart= "${pkgs.writeShellScript "swww-daemon" ''
${pkgs.swww}/bin/swww-daemon
''}";
ExecStartPost = "${pkgs.writeShellScript "swww-wallpaper-changer" ''
#!/run/current-system/sw/bin/bash
Type = [ "oneshot" ];
ExecStart = "${pkgs.writeShellScript "swww-wallpaper-changer" ''
export WAYLAND_DISPLAY="wayland-1"
set +o errexit
set +o nounset
set +o pipefail
script_name=''${BASH_SOURCE[0]}
for pid in $(pidof -x "$script_name"); do
if [ "$pid" != $$ ]; then
kill -15 "$pid"
fi
done
#[ "$XDG_SESSION_TYPE" != "wayland" ] && echo "Not a Wayland session, exiting." && exit 1
wallpaper_dir="$HOME/.local/share/bg/"
swww_daemon_pid=$(pidof -x 'swww-daemon')
swww_pid=$(pidof -x 'swww')
#[ -z "$swww_daemon_pid" ] || kill -15 "$swww_daemon_pid"
[ -z "$swww_pid" ] || kill -15 "$swww_pid"
#${pkgs.swww}/bin/swww-daemon &
# Allow some time for desktop to start
sleep 3
echo "starting daemon..."
${pkgs.swww}/bin/swww-daemon &
while true; do
find "$wallpaper_dir" -type f -follow \( -iname \*.jpg -o -iname \*.png -o -iname \*.gif -o -iname \*.bmp \) | shuf | while read -r file; do
${pkgs.swww}/bin/swww img "$file" --transition-step 10 --transition-fps 60
[ $? != 0 ] && echo "swww failed. Exiting" && exit 1
sleep 3
[ $? != 0 ] && echo "swww failed, reloading daemon" && exit 1
sleep 600
done
done
''}";