Jgbrowser loading time, files... +(mb-setvar)

Hi @napcok,

  • I added the function: Set Wallpaper directory(first or second display’s) For my own pleasure…
  • And added a file count when loading the entries. I have set it to 100 items. (Could be more probably)

IDEA=“Adding a file count to jgbrowser, for speeding up loading time.”

WHY?

Of course i am crazy with sometimes more than 5000 of (anim)images in one wallpaper directory.
When i used the menu to go to a folder it took ages to load.
I don’t necessarily need to scroll to a picture, only able to choose the directory to set wallpaper path.
For my other stuff i don’t have more than 100 items in a folder.

What do you think of the “$IDEA”.

Or (fancy)… at the bottom … next page of X files.

Jgbrowser: edited version…

#!/usr/bin/env bash
# Daniel Napora 2020 - 2023 <napcok@gmail.com>

# Set the maximum number of files to load.
MAX_FILES=100  

. "$HOME"/.config/mabox/mabox.conf

CONFIG_DIR="$HOME/.config/mbwallpaper"
CONF_FILE="$CONFIG_DIR/mbwallpaper.conf"
CONF_FILE2="$CONFIG_DIR/mbwallpaper2mon.conf"


source <(grep = "$CONF_FILE")


case $LANG in
    pl*)
        DIRECTORIES="Katalogi"
        FILES="Pliki"
        ADDBOOKMARK="Dodaj do zakładek"
        OPENDIR="Otwórz w menadżerze plików"
        OPENTERM="Otwórz w terminalu"
        ;;
    es*)
        DIRECTORIES="Directorios"
        FILES="Archivos"
        ADDBOOKMARK="Agregar a marcadores"
        OPENDIR="Abrir Gestor de archivos aquí"
        OPENTERM="Abrir terminal aquí"
        ;;
    *)
        DIRECTORIES="Directories"
        FILES="Files"
        ADDBOOKMARK="Add to Bookmarks"
        OPENDIR="Open filemanager here"
        OPENTERM="Open terminal here"
        SET_WDIR="Set wallpaper dir for                                  0"
        SET_WDIR2="Set wallpaper dir for                                  1"
     ;;
esac
    
: "${JGMENU_RESOURCE_OPENER="xdg-open"}"

    
    DIRECTORY=${1:-$HOME}

    # If '$DIRECTORY' is '/', unset it to avoid '//'.
    [[ $DIRECTORY == / ]] && DIRECTORY=

if [ "$jgbrowser_show_hidden" == false ]; then
    count=0  # Counter to keep track of processed items
    for item in "$DIRECTORY"/*; do
        if [[ -d $item ]]; then
            dirs+=("${item##*/},^pipe(jgbrowser \"$DIRECTORY/${item##*/}\")")
        else
            if [[ -f $item ]]; then
                files+=("${item##*/},xdg-open \"$DIRECTORY/${item##*/}\"")
                ((count++))
            fi
        fi

        # Check if the maximum number of files has been reached
        if [ $count -eq $MAX_FILES ]; then
            break
        fi
    done
else
    count=0
    for item in "$DIRECTORY"/* "$DIRECTORY"/.[^.]*; do
        if [[ -d $item ]]; then
            dirs+=("${item##*/},^pipe(jgbrowser \"$DIRECTORY/${item##*/}\")")
        else
            if [[ -f $item ]]; then
                files+=("${item##*/},xdg-open \"$DIRECTORY/${item##*/}\"")
                ((count++))
            fi
        fi

        if [ $count -eq $MAX_FILES ]; then
            break
        fi
    done
fi


printf "%b\n" "^sep(<small><i>${DIRECTORY:-/}</i></small>)"
printf "%b\n" "  ${ADDBOOKMARK},\"\"\"echo \"  ${DIRECTORY##*/},^pipe(jgbrowser ${DIRECTORY:-/})\" >> $HOME/.config/mabox/places.csv;mb-places -s\"\"\""
printf "%b\n" "^sep()"
printf "%b\n" " $SET_WDIR,awk -v newdir='${DIRECTORY:-/}' '/^wallpaper_dir=/{\$1=\"wallpaper_dir=\"newdir}1' $CONF_FILE > $CONF_FILE.tmp && mv $CONF_FILE.tmp $CONF_FILE ; "
printf "%b\n" " $SET_WDIR2,awk -v newdir='${DIRECTORY:-/}' '/^wallpaper_dir2=/{\$1=\"wallpaper_dir2=\"newdir}1' $CONF_FILE2 > $CONF_FILE2.tmp && mv $CONF_FILE2.tmp $CONF_FILE2"
printf "%b\n" "^sep()"
printf "%b\n" " $OPENDIR,${JGMENU_RESOURCE_OPENER} \"${DIRECTORY:-/}\""
printf "%b\n" "<big></big> $OPENTERM,exo-open --launch TerminalEmulator --working-directory=\"${DIRECTORY:-/}\""
#printf "%b\n" "    $OPENTERM,terminator --working-directory=\"${DIRECTORY:-/}\""
if [ ${#dirs[@]} -ne 0 ]; then
    printf "%b\n" "^sep($DIRECTORIES <small>(${#dirs[@]})</small>)"
    printf "%s\n" "${dirs[@]/&/&amp;}"
fi
if [ ${#files[@]} -ne 0 ]; then
    printf "%b\n" "^sep($FILES <small>(${#files[@]})</small>)"
    #printf "%s\n" "${files[@]}"
    #okfiles=("${files[@]/</ &lt;}")
    printf "%s\n" "${files[@]/&/&amp;}"
    
fi

Side question: about mb-setvar.
I tried something like this:

`printf "%b\n" " Set Wallpaper dir 1,mb-setvar wallpaper_dir='${DIRECTORY:-/}' $CONF_FILE"`

This did’t work. That’s why i changed it to awk .
But i rather use ‘mb-setvar’. (nice and short)

What can i do to use mb-setvar instead.

:bird:

1 Like

Hi @muzqs
Try something like:

printf "%b\n" " Set Wallpaper dir 1,mb-setvar wallpaper_dir=${DIRECTORY:-/} $CONF_FILE"
#### or
printf "%b\n" " Set Wallpaper dir 1,mb-setvar wallpaper_dir=\"${DIRECTORY:-/}\" $CONF_FILE"

Why?

Single quotes (’ ') operate similarly to double quotes, but do not permit referencing variables, since the special meaning of $ is turned off. Within single quotes, every special character except ’ gets interpreted literally.

About MAX_FILES…
jgbrowser pipemenu doesn’t handle directories with huge amounts of files well, but that’s not its role. I rather use it to quickly look into directories and possibly open them in the file manager or console. Sometimes I use it to check how many files there are in a given directory :slight_smile: I’d rather leave it as it is.

Using jgbrowser modified, accesing directories goes quick enough now.
It’s even wors using Pcmanfm entering an images directory.
That’s why i like jgbrowser to use. (editable)


A better view on my situation. (crazy amounth of images)

With Pcmanfm loading a directory with about 5467 images of 2mb-3mb, takes about 1.25 minutes.

With jgbrowser set with 2000 items max load. (load time a view sec)

# Set the maximum number of files to load.
MAX_FILES=2000 

*Más o menos, 2000 items (1Mb -5Mb)loading seems doable for jgbrowser/hardware.
Above 2000 already gets a bit slower on my machine.


To keep total item count of a folder i changed this part in jgbrowser.
Total files in folder: good point. :slight_smile:

# Count the total number of files in the folder
total_files=$(find "$DIRECTORY" -type f | wc -l)

if [ ${#files[@]} -ne 0 ]; then
    printf "%b\n" "^sep($FILES <small>($total_files)</small>)"
    #printf "%s\n" "${files[@]}"
    #okfiles=("${files[@]/</ &lt;}")
    printf "%s\n" "${files[@]/&/&amp;}"
    
fi

Thanks for the feedback, it helped me fine tuning.
It looks like this is workable for me.


Mb-setvar is working, but not with what it should be for “$DIRECTORY”.
I leave that for now. It’s working with awk.

:bird: