fix(wallpaper/konachan): make random konachan respect locale by utilizing xdg user dirs (if any) (#1662)

This commit is contained in:
end-4
2025-07-20 17:43:21 +02:00
committed by GitHub
2 changed files with 25 additions and 7 deletions
@@ -1,24 +1,42 @@
#!/usr/bin/env bash
get_pictures_dir() {
if command -v xdg-user-dir &> /dev/null; then
xdg-user-dir PICTURES
return
fi
local config_file="${XDG_CONFIG_HOME:-$HOME/.config}/user-dirs.dirs"
if [ -f "$config_file" ]; then
local pictures_path
pictures_path=$(source "$config_file" >/dev/null 2>&1; echo "$XDG_PICTURES_DIR")
echo "${pictures_path/#\$HOME/$HOME}"
return
fi
echo "$HOME/Pictures"
}
QUICKSHELL_CONFIG_NAME="ii"
XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
XDG_STATE_HOME="${XDG_STATE_HOME:-$HOME/.local/state}"
PICTURES_DIR=$(get_pictures_dir)
CONFIG_DIR="$XDG_CONFIG_HOME/quickshell/$QUICKSHELL_CONFIG_NAME"
CACHE_DIR="$XDG_CACHE_HOME/quickshell"
STATE_DIR="$XDG_STATE_HOME/quickshell"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
mkdir -p ~/Pictures/Wallpapers
page=$((1 + RANDOM % 1000));
mkdir -p "$PICTURES_DIR/Wallpapers"
page=$((1 + RANDOM % 1000));
response=$(curl "https://konachan.net/post.json?tags=rating%3Asafe&limit=1&page=$page")
link=$(echo "$response" | jq '.[0].file_url' -r);
link=$(echo "$response" | jq '.[0].file_url' -r);
ext=$(echo "$link" | awk -F. '{print $NF}')
downloadPath="$HOME/Pictures/Wallpapers/konachan_random_image.$ext"
downloadPath="$PICTURES_DIR/Wallpapers/konachan_random_image.$ext"
illogicalImpulseConfigPath="$HOME/.config/illogical-impulse/config.json"
currentWallpaperPath=$(jq -r '.background.wallpaperPath' $illogicalImpulseConfigPath)
if [ "$downloadPath" == "$currentWallpaperPath" ]; then
downloadPath="$HOME/Pictures/Wallpapers/konachan_random_image-1.$ext"
downloadPath="$PICTURES_DIR/Wallpapers/konachan_random_image-1.$ext"
fi
curl "$link" -o "$downloadPath"
"$SCRIPT_DIR/switchwall.sh" --image "$downloadPath"
+2 -2
View File
@@ -159,7 +159,7 @@
"Fake screen rounding": "伪造屏幕圆角",
"When not fullscreen": "非全屏时",
"Choose file": "选择文件",
"Random SFW Anime wallpaper from Konachan\nImage is saved to ~/Pictures/Wallpapers": "随机 Konachan SFW 动漫壁纸\n图片保存到 ~/Pictures/Wallpapers",
"Random SFW Anime wallpaper from Konachan\nImage is saved to ~/Pictures/Wallpapers": "随机 Konachan SFW 动漫壁纸\n图片保存到 ~/图片/Wallpapers",
"Be patient...": "请耐心等待...",
"Decorations & Effects": "装饰与特效",
"Tonal Spot": "色调点",
@@ -311,4 +311,4 @@
"Humidity": "湿度",
"Wind": "风",
"Precipitation": "降水量"
}
}