Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch to fix temporary files leakage and minor updates #2

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ pkgdesc="Custom STL thumbnails for Tumbler"
arch=('any')
url="https://github.com/j-james/thunar-stl-thumbnails"
license=('BSD')
depends=('tumbler' 'openscad')
depends=('tumbler' 'openscad' 'imagemagick')
source=('stl.thumbnailer'
'stl-thumbnailer.sh')
sha256sums=('fd4a8c44e4a35418e894241a3e6fefcab83279570b5e91296dde1f1179b0a0cc'
'0b6a39b7facae2c7d036a0017010a86f6a3ebcb2a572312174d7d4cff1af8325')
'998ba171b426278a168c16f480b4eb975c6b91552020199525ac554cb9d2696a')

package() {
install -Dvm644 "stl.thumbnailer" "$pkgdir/usr/share/thumbnailers/stl.thumbnailer"
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# thunar-stl-thumbnails

Generate thumbnails for STLs with Tumbler. Requires OpenSCAD to be installed.
Generate thumbnails for STLs with Tumbler. Requires OpenSCAD and ImageMagick to be installed.

![thunar](https://user-images.githubusercontent.com/35242550/182044826-e9520fed-98f5-47e9-8000-ea5c9ea56e3e.png)


NOTE: Remember to run `systemctl --user restart tumblerd` and restart Thunar to apply changes.
20 changes: 13 additions & 7 deletions stl-thumbnailer.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

if [[ $# -lt 3 ]]; then
echo "$0: input_file_name output_file_name size"
Expand All @@ -8,13 +8,19 @@ fi
INPUT_FILE=$1
OUTPUT_FILE=$2
SIZE=$3
MEM_LIMIT_KiB=$(( 300 * 1024 )) # Limit the memory usage to 300 MiB

TEMP="$(mktemp --directory --tmpdir tumbler-stl-XXXXXXX)"
cp "$INPUT_FILE" "$TEMP/source.stl"
# Use a sub shell to enclose the commands in case it aborts and skip the last cleanup action
# Sub shell BEG
(
ulimit -v $MEM_LIMIT_KiB
cp "$INPUT_FILE" "$TEMP/source.stl"

echo "import(\"source.stl\", convexity=10);" > "$TEMP/thumbnail.scad"
openscad --imgsize "500,500" -o "$TEMP/thumbnail.png" "$TEMP/thumbnail.scad" 2>/dev/null
echo "import(\"source.stl\", convexity=10);" >"$TEMP/thumbnail.scad"
openscad --imgsize "500,500" -o "$TEMP/thumbnail.png" "$TEMP/thumbnail.scad" 2>/dev/null

convert -thumbnail "$SIZE" "$TEMP/thumbnail.png" "$OUTPUT_FILE" 1>/dev/null 2>&1

rm -rf $TEMP
convert -thumbnail "$SIZE" "$TEMP/thumbnail.png" "$OUTPUT_FILE" 1>/dev/null 2>&1
)
# Sub shell END
[ -d $TEMP ] && rm -rf $TEMP