Fixed that cashed images are kept even when original does not exist anymore
This commit is contained in:
@@ -92,6 +92,7 @@ Row { // Workspace Row
|
|||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
// Default to the original icon
|
// Default to the original icon
|
||||||
let src = modelData.icon;
|
let src = modelData.icon;
|
||||||
|
// console.log("########## icon: " + modelData.icon)
|
||||||
|
|
||||||
// Check if there is a "?" in the URL (custom path)
|
// Check if there is a "?" in the URL (custom path)
|
||||||
if (src.includes('goxlr')) {
|
if (src.includes('goxlr')) {
|
||||||
|
|||||||
@@ -10,7 +10,9 @@ if [ ! -d $THUMB_DIR ]; then
|
|||||||
mkdir -p $THUMB_DIR;
|
mkdir -p $THUMB_DIR;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
shopt -s nullglob
|
||||||
|
files=( "$THUMB_DIR"/*.jpg "$THUMB_DIR"/*.jpeg "$THUMB_DIR"/*.png )
|
||||||
|
# printf ' %s\n' "${files[@]}"
|
||||||
# Make sure the thumb directory exists
|
# Make sure the thumb directory exists
|
||||||
mkdir -p "$THUMB_DIR"
|
mkdir -p "$THUMB_DIR"
|
||||||
|
|
||||||
@@ -19,6 +21,28 @@ MAX_DIM=300
|
|||||||
|
|
||||||
num=0
|
num=0
|
||||||
|
|
||||||
|
remove_from_array() {
|
||||||
|
local -n arr=$1
|
||||||
|
local elem=$2
|
||||||
|
local result=()
|
||||||
|
|
||||||
|
# echo "=== Removing element: '$elem' ==="
|
||||||
|
# echo "Original array has ${#arr[@]} elements"
|
||||||
|
|
||||||
|
for item in "${arr[@]}"; do
|
||||||
|
if [[ "$item" != "$elem" ]]; then
|
||||||
|
result+=( "$item" )
|
||||||
|
# echo "Keeping: '$item'"
|
||||||
|
# else
|
||||||
|
# echo "Removing: '$item'"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
arr=( "${result[@]}" )
|
||||||
|
# echo "New array has ${#arr[@]} elements"
|
||||||
|
# echo "-----------------------------------"
|
||||||
|
}
|
||||||
|
|
||||||
# Process each image
|
# Process each image
|
||||||
for img in "$WALLPAPER_DIR"/*.{jpg,jpeg,png}; do
|
for img in "$WALLPAPER_DIR"/*.{jpg,jpeg,png}; do
|
||||||
# Skip if no files match
|
# Skip if no files match
|
||||||
@@ -34,16 +58,18 @@ for img in "$WALLPAPER_DIR"/*.{jpg,jpeg,png}; do
|
|||||||
|
|
||||||
# Output path
|
# Output path
|
||||||
thumb="$THUMB_DIR/$fname"
|
thumb="$THUMB_DIR/$fname"
|
||||||
|
|
||||||
|
|
||||||
# If thumbnail already exists and is newer than the original, skip
|
# If thumbnail already exists and is newer than the original, skip
|
||||||
if [ -f "$thumb" ] && [ "$thumb" -nt "$img" ]; then
|
if [ -f "$thumb" ] && [ "$thumb" -nt "$img" ]; then
|
||||||
|
remove_from_array files "$thumb"
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
num+=1
|
num+=1
|
||||||
|
|
||||||
# Generate thumbnail using ImageMagick
|
# Generate thumbnail using ImageMagick
|
||||||
if [ -x "/usr/bin/magick" ] then
|
if [ -x "/usr/bin/magick" ]; then
|
||||||
magick "$img" -resize "${MAX_DIM}x${MAX_DIM}" "$thumb"
|
magick "$img" -resize "${MAX_DIM}x${MAX_DIM}" "$thumb"
|
||||||
rm $temp_image_name
|
rm $temp_image_name
|
||||||
else
|
else
|
||||||
@@ -52,6 +78,16 @@ for img in "$WALLPAPER_DIR"/*.{jpg,jpeg,png}; do
|
|||||||
fi
|
fi
|
||||||
cp $img $temp_image_name
|
cp $img $temp_image_name
|
||||||
fi
|
fi
|
||||||
|
remove_from_array files "$thumb"
|
||||||
|
done
|
||||||
|
|
||||||
|
# echo ""
|
||||||
|
|
||||||
|
# printf ' %s\n' "${files[@]}"
|
||||||
|
|
||||||
|
for img in $files; do
|
||||||
|
echo "$img"
|
||||||
|
rm $img
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "$num Thumbnails generated in $THUMB_DIR"
|
echo "$num Thumbnails generated in $THUMB_DIR"
|
||||||
Reference in New Issue
Block a user