Skip to content

Commit cbff6d2

Browse files
committed
fix: improve performance on theme change
1 parent f2b2be1 commit cbff6d2

File tree

4 files changed

+131
-322
lines changed

4 files changed

+131
-322
lines changed

Configs/.local/lib/hyde/color.set.sh

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,27 +102,34 @@ preprocess_substitutions() {
102102
}
103103

104104
fn_wallbash() {
105-
local template="${1}"
106-
local temp_target_file exec_command
105+
local temp_target_file exec_command template wallbash_dirs_array
106+
template="${1}"
107+
shift
108+
wallbash_dirs_array=("${@}")
107109
WALLBASH_SCRIPTS="${template%%/wallbash/*}/wallbash/scripts"
108-
110+
109111
if [[ "${template}" == *.theme ]]; then
110112
# This is approach is to handle the theme files
111113
# We don't want themes to launch the exec_command or any arbitrary codes
112114
# To enable this we should have a *.dcol file as a companion to the theme file
113-
IFS=':' read -r -a wallbashDirs <<<"$WALLBASH_DIRS"
115+
# IFS=':' read -r -a wallbash_dirs_array <<<"$wallbash_dirs"
116+
local template_name
114117
template_name="${template##*/}"
115118
template_name="${template_name%.*}"
116-
# echo "${wallbashDirs[@]}"
117-
dcolTemplate=$(find -H "${wallbashDirs[@]}" -type f -path "*/theme*" -name "${template_name}.dcol" 2>/dev/null | awk '!seen[substr($0, match($0, /[^/]+$/))]++')
119+
dcolTemplate=$(find -H "${wallbash_dirs_array[@]}" -type f -path "*/theme*" -name "${template_name}.dcol" 2>/dev/null | awk '!seen[substr($0, match($0, /[^/]+$/))]++')
120+
# dcolTemplate="$(find "${wallbash_dirs_array[@]}" -H -type f -path "*/theme*" -name "${template_name}.dcol" -print -quit)"
118121
if [[ -n "${dcolTemplate}" ]]; then
119122
eval target_file="$(head -1 "${dcolTemplate}" | awk -F '|' '{print $1}')"
120123
exec_command="$(head -1 "${dcolTemplate}" | awk -F '|' '{print $2}')"
121124
WALLBASH_SCRIPTS="${dcolTemplate%%/wallbash/*}/wallbash/scripts"
122125
fi
123126
fi
124127

125-
[[ "${LOG_LEVEL}" == "debug" ]] && print_log -sec "wallbash" -stat "Template:" " ${template}"
128+
if [[ "${LOG_LEVEL}" == "debug" ]];then
129+
print_log -sec "wallbash" -stat "Template:" " ${template}"
130+
print_log -sec "wallbash" -stat "Wallbash Directories:" " ${wallbash_dirs_array[*]}"
131+
print_log -sec "wallbash" -stat "Wallbash Scripts:" " ${WALLBASH_SCRIPTS}"
132+
fi
126133

127134
# shellcheck disable=SC1091
128135
# shellcheck disable=SC2154
@@ -166,8 +173,6 @@ fn_wallbash() {
166173
bash -c "${exec_command}" &
167174
disown
168175
}
169-
170-
unset WALLBASH_SCRIPTS
171176
}
172177

173178
scrDir="$(dirname "$(realpath "$0")")"
@@ -291,6 +296,8 @@ fi
291296

292297
#// switch theme <//> wall based colors
293298

299+
print_log -sec "wallbash" -stat "wallbash directories" " $WALLBASH_DIRS"
300+
294301
# shellcheck disable=SC2154
295302
if [ "${enableWallDcol}" -eq 0 ] && [[ "${reload_flag}" -eq 1 ]]; then
296303

@@ -303,13 +310,14 @@ if [ "${enableWallDcol}" -eq 0 ] && [[ "${reload_flag}" -eq 1 ]]; then
303310
done < <(find -H "${wallbashDirs[@]}" -type f -path "*/theme*" -name "*.dcol" 2>/dev/null | awk '!seen[substr($0, match($0, /[^/]+$/))]++')
304311

305312
# Process templates in parallel
306-
parallel fn_wallbash ::: "${deployList[@]}" || true
313+
parallel fn_wallbash {} "$wallbashDirs[@]" ::: "${deployList[@]}" || true
314+
307315

308316
elif [ "${enableWallDcol}" -gt 0 ]; then
309317
print_log -sec "wallbash" -stat "apply ${dcol_mode} colors" "Wallbash theme"
310318
# This is the reason we avoid SPACES for the wallbash template names
311-
find -H "${wallbashDirs[@]}" -type f -path "*/theme*" -name "*.dcol" 2>/dev/null | awk '!seen[substr($0, match($0, /[^/]+$/))]++' | parallel fn_wallbash {} || true
319+
find -H "${wallbashDirs[@]}" -type f -path "*/theme*" -name "*.dcol" 2>/dev/null | awk '!seen[substr($0, match($0, /[^/]+$/))]++' | parallel fn_wallbash {} "${wallbashDirs[@]}" || true
312320
fi
313321

314322
# Process "always" templates in parallel
315-
find -H "${wallbashDirs[@]}" -type f -path "*/always*" -name "*.dcol" 2>/dev/null | awk '!seen[substr($0, match($0, /[^/]+$/))]++' | parallel fn_wallbash {} || true
323+
find -H "${wallbashDirs[@]}" -type f -path "*/always*" -name "*.dcol" 2>/dev/null | awk '!seen[substr($0, match($0, /[^/]+$/))]++' | parallel fn_wallbash {} "${wallbashDirs[@]}" || true

0 commit comments

Comments
 (0)