diff --git a/home/wm/addon/wallpaper.nix b/home/wm/addon/wallpaper.nix index 5c4be0b..0000ded 100644 --- a/home/wm/addon/wallpaper.nix +++ b/home/wm/addon/wallpaper.nix @@ -2,34 +2,64 @@ let pictures = "${config.xdg.userDirs.pictures}"; change-wallpaper = "${pkgs.scripts}/bin/chpaper ${pictures}/Wallpapers"; + wallpaper-downloader = "${pkgs.scripts}/bin/wallhaven ${pictures}/Wallpapers"; in { systemd.user = { - services.wallpaper = { - Unit = { - Description = "Change Wallpaper"; - PartOf = [ "graphical-session.target" ]; - After = [ "graphical-session-pre.target" ]; - Wants = "swww-daemon.service"; + services = { + wallhaven = { + Unit = { + Description = "Wallpaper Downloader"; + }; + Install = { + WantedBy = [ "default.target" ]; + }; + Service = { + Type = "oneshot"; + ExecStart = "${wallpaper-downloader}"; + }; + }; - Install = { - WantedBy = [ "graphical-session.target" ]; - }; - Service = { - Type = "oneshot"; - ExecStart = "${change-wallpaper}"; + wallpaper = { + Unit = { + Description = "Change Wallpaper"; + PartOf = [ "graphical-session.target" ]; + After = [ "graphical-session-pre.target" ]; + Wants = "swww-daemon.service"; + }; + Install = { + WantedBy = [ "graphical-session.target" ]; + }; + Service = { + Type = "oneshot"; + ExecStart = "${change-wallpaper}"; + }; }; }; - timers.wallpaper = { - Unit = { - Description = "Change Wallpaper"; + timers = { + wallhaven = { + Unit = { + Description = "Wallpaper Downloader"; + }; + Install = { + WantedBy = [ "default.target" ]; + }; + Timer = { + OnCalendar = "Fri"; + Persistent= true; + }; }; - Install = { - WantedBy = [ "default.target" ]; - }; - Timer = { - OnStartupSec = "10min"; - OnUnitActiveSec = "10min"; + wallpaper = { + Unit = { + Description = "Change Wallpaper"; + }; + Install = { + WantedBy = [ "default.target" ]; + }; + Timer = { + OnStartupSec = "10min"; + OnUnitActiveSec = "10min"; + }; }; }; }; diff --git a/home/wm/hyprland/default.nix b/home/wm/hyprland/default.nix index 1d994cf..f0eca9c 100644 --- a/home/wm/hyprland/default.nix +++ b/home/wm/hyprland/default.nix @@ -15,7 +15,6 @@ let wpctl = "${pkgs.wireplumber}/bin/wpctl"; pictures = "${config.xdg.userDirs.pictures}"; - wallhaven-wallpaper = "${pkgs.scripts}/bin/chpaper \$(${pkgs.scripts}/bin/wallhaven ${pictures}/Wallpapers)"; in { wayland.windowManager.hyprland = { @@ -168,7 +167,6 @@ in "SUPER,escape, exec, ${swaylock} -f -i /tmp/wallpaper.jpg" "SUPER_SHIFT,W, exec, systemctl --user start wallpaper.service" - "SUPER_ALT,W, exec, ${wallhaven-wallpaper}" "SUPER,1, workspace, 1" "SUPER,2, workspace, 2" diff --git a/packages/scripts/wallhaven.sh b/packages/scripts/wallhaven.sh index 54b3982..9c5bb81 100755 --- a/packages/scripts/wallhaven.sh +++ b/packages/scripts/wallhaven.sh @@ -16,8 +16,8 @@ mkdir -p "${DIR}" CONFIG_DIR="${XDG_CONFIG_HOME:-${HOME}/.config}" CONFIG_FILE="${CONFIG_DIR}/wallpaper_config.json" -if [ ! -e ${CONFIG_FILE} ]; then - echo '{"tags":null,"categories":"100","purity":"100", "sorting":"random", "size":null, "ratios":null, "colors":null, "ai_filter":1, "range": "1M"}' | jq > ${CONFIG_FILE} +if [ ! -e "${CONFIG_FILE}" ]; then + echo '{"tags":null,"categories":"100","purity":"100", "sorting":"random", "size":null, "ratios":null, "colors":null, "ai_filter":1, "range": "1M"}' | jq > "${CONFIG_FILE}" fi CONFIG="$(cat "${CONFIG_FILE}")" @@ -29,7 +29,7 @@ fi TAGS="$(echo "${CONFIG}" | jq -r '.tags // empty')" if [ -n "${TAGS}" ]; then - TAGS="q=$(echo ${TAGS} | sed -e 's/ /%20/g' -e 's/+/%2B/g' -e 's/-/%2D/g' -e 's/:/%3A/g')&" + TAGS="q=$(echo "${TAGS}" | sed -e 's/ /%20/g' -e 's/+/%2B/g' -e 's/-/%2D/g' -e 's/:/%3A/g')&" fi CATEGORIES="$(echo "${CONFIG}" | jq -r '.categories // empty')" @@ -67,10 +67,9 @@ if [ -n "${RANGE}" ]; then RANGE="topRange=${RANGE}&" fi -notify-send -r 1234 -u normal -a Wallpapers -i information -t 5000 "Wallpapers" "Fetching a list of wallpapers..." URL="${WALLHAVEN_BASE_URL}/search?${TAGS}${CATEGORIES}${PURITY}${SIZE}${RATIOS}${COLORS}${AI_FILTER}${SORTING}${RANGE}" CURL_CMD="${CURL_BASE_CMD} \"${URL}\"" -RESULT="$(eval ${CURL_CMD})" +RESULT="$(eval "${CURL_CMD}")" NO_OF_IMAGES="$(echo "${RESULT}" | jq -r '.meta.total')" if [ "${NO_OF_IMAGES}" -eq 0 ]; then notify-send -r 1234 -u normal -a Wallpapers -i information -t 5000 "Wallpapers" "No images available for current configuration." @@ -85,14 +84,12 @@ if [ "${ITEM_PAGE}" -gt 0 ]; then SEED="seed=${SEED}&" fi CURL_CMD="${CURL_BASE_CMD} \"${URL}${SEED}page=$((ITEM_PAGE+1))\"" - RESULT="$(eval ${CURL_CMD})" + RESULT="$(eval "${CURL_CMD}")" fi ID="$(echo "${RESULT}" | jq -r ".data[${ITEM_NUMBER}].id")" notify-send -r 1234 -u normal -a Wallpapers -i information -t 5000 "Wallpapers" "Got ${NO_OF_IMAGES} images. Using image ${ID} from page $((ITEM_PAGE+1)) ..." IMAGE_URL="$(echo "${RESULT}" | jq -r ".data[${ITEM_NUMBER}].path")" FILENAME="${IMAGE_URL##*/}" -notify-send -r 1234 -u normal -a Wallpapers -i information -t 5000 "Wallpapers" "Downloading image: ${IMAGE_URL}" curl --silent -L --output-dir "${DIR}" -o "${FILENAME}" "${IMAGE_URL}" -notify-send -r 1234 -u normal -a Wallpapers -i information -t 5000 "Wallpapers" "Downloaded image: ${DIR}/${FILENAME}" echo "${DIR}/${FILENAME}"