Skip to content

Commit 10dab7c

Browse files
committed
esthemes - added support for theme branches so we can manage our carbon themes more easily
1 parent 3ce6420 commit 10dab7c

File tree

1 file changed

+49
-28
lines changed

1 file changed

+49
-28
lines changed

scriptmodules/supplementary/esthemes.sh

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,42 +22,45 @@ function depends_esthemes() {
2222
}
2323

2424
function _has_pixel_pos_esthemes() {
25+
local pixel_pos=0
2526
# get the version of emulationstation installed so we can check whether to show
26-
# themes that use the new pixel based positioning capabilities
27-
local supp_path="$rootdir/supplementary"
28-
local es_path="$supp_path/emulationstation"
29-
local esdev_path="${es_path}-dev"
30-
# check if emulationstation-dev is installed
31-
if [[ -d "$esdev_path" ]]; then
32-
es_path="$esdev_path"
33-
fi
34-
# extract the version number from emulationstation --help
35-
local es_ver="$("$es_path/emulationstation" --help | grep -oP "Version \K[^,]+")"
36-
# if emulationstation is newer than 2.10 enable pixel based themes
27+
# themes that use the new pixel based positioning - we run as $user as the
28+
# emulationstation launch script will exit if run as root
29+
local es_ver="$(sudo -u $user /usr/bin/emulationstation --help | grep -oP "Version \K[^,]+")"
30+
# if emulationstation is newer than 2.10, enable pixel based themes
3731
compareVersions "$es_ver" ge "2.10" && pixel_pos=1
3832
echo "$pixel_pos"
3933
}
4034

4135
function install_theme_esthemes() {
4236
local theme="$1"
4337
local repo="$2"
44-
local default_branch
38+
local branch="$3"
4539

4640
local pixel_pos="$(_has_pixel_pos_esthemes)"
4741

4842
if [[ -z "$repo" ]]; then
4943
repo="RetroPie"
5044
fi
45+
5146
if [[ -z "$theme" ]]; then
5247
theme="carbon"
5348
repo="RetroPie"
5449
[[ "$pixel_pos" -eq 1 ]] && theme+="-2021"
5550
fi
56-
# Get the name of the default branch, fallback to 'master' if not found
57-
default_branch=$(runCmd git ls-remote --symref --exit-code "https://github.com/$repo/es-theme-$theme.git" HEAD | grep -oP ".*/\K[^\t]+")
58-
[[ -z "$default_branch" ]] && default_branch="master"
51+
52+
local name="$theme"
53+
54+
if [[ -z "$branch" ]]; then
55+
# Get the name of the default branch, fallback to 'master' if not found
56+
branch=$(runCmd git ls-remote --symref --exit-code "https://github.com/$repo/es-theme-$theme.git" HEAD | grep -oP ".*/\K[^\t]+")
57+
[[ -z "$branch" ]] && branch="master"
58+
else
59+
name+="-$branch"
60+
fi
61+
5962
mkdir -p "/etc/emulationstation/themes"
60-
gitPullOrClone "/etc/emulationstation/themes/$theme" "https://github.com/$repo/es-theme-$theme.git" "$default_branch"
63+
gitPullOrClone "/etc/emulationstation/themes/$name" "https://github.com/$repo/es-theme-$theme.git" "$branch"
6164
}
6265

6366
function uninstall_theme_esthemes() {
@@ -75,8 +78,8 @@ function gui_esthemes() {
7578
if [[ "$pixel_pos" -eq 1 ]]; then
7679
themes+=(
7780
'RetroPie carbon-2021'
78-
'RetroPie carbon-centered-2021'
79-
'RetroPie carbon-nometa-2021'
81+
'RetroPie carbon-2021 centered'
82+
'RetroPie carbon-2021 nometa'
8083
)
8184
fi
8285

@@ -295,6 +298,10 @@ function gui_esthemes() {
295298
)
296299
while true; do
297300
local theme
301+
local theme_dir
302+
local branch
303+
local name
304+
298305
local installed_themes=()
299306
local repo
300307
local options=()
@@ -317,13 +324,20 @@ function gui_esthemes() {
317324
theme=($theme)
318325
repo="${theme[0]}"
319326
theme="${theme[1]}"
320-
if [[ -d "/etc/emulationstation/themes/$theme" ]]; then
327+
branch="${theme[2]}"
328+
name="$repo/$theme"
329+
theme_dir="$theme"
330+
if [[ -n "$branch" ]]; then
331+
name+=" ($branch)"
332+
theme_dir+="-$branch"
333+
fi
334+
if [[ -d "/etc/emulationstation/themes/$theme_dir" ]]; then
321335
status+=("i")
322-
options+=("$i" "Update or Uninstall $repo/$theme (installed)")
323-
installed_themes+=("$theme $repo")
336+
options+=("$i" "Update or Uninstall $name (installed)")
337+
installed_themes+=("$theme $repo $branch")
324338
else
325339
status+=("n")
326-
options+=("$i" "Install $repo/$theme")
340+
options+=("$i" "Install $name")
327341
fi
328342
((i++))
329343
done
@@ -362,27 +376,34 @@ function gui_esthemes() {
362376
U)
363377
for theme in "${installed_themes[@]}"; do
364378
theme=($theme)
365-
rp_callModule esthemes install_theme "${theme[0]}" "${theme[1]}"
379+
rp_callModule esthemes install_theme "${theme[0]}" "${theme[1]}" "${theme[2]}"
366380
done
367381
;;
368382
*)
369383
theme=(${themes[choice-1]})
370384
repo="${theme[0]}"
371385
theme="${theme[1]}"
386+
branch="${theme[2]}"
387+
name="$repo/$theme"
388+
theme_dir="$theme"
389+
if [[ -n "$branch" ]]; then
390+
name+=" ($branch)"
391+
theme_dir+="-$branch"
392+
fi
372393
if [[ "${status[choice]}" == "i" ]]; then
373-
options=(1 "Update $repo/$theme" 2 "Uninstall $repo/$theme")
374-
cmd=(dialog --backtitle "$__backtitle" --menu "Choose an option for theme" 12 40 06)
394+
options=(1 "Update $name" 2 "Uninstall $name")
395+
cmd=(dialog --backtitle "$__backtitle" --menu "Choose an option for theme" 12 60 06)
375396
local choice=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
376397
case "$choice" in
377398
1)
378-
rp_callModule esthemes install_theme "$theme" "$repo"
399+
rp_callModule esthemes install_theme "$theme" "$repo" "$branch"
379400
;;
380401
2)
381-
rp_callModule esthemes uninstall_theme "$theme"
402+
rp_callModule esthemes uninstall_theme "$theme_dir"
382403
;;
383404
esac
384405
else
385-
rp_callModule esthemes install_theme "$theme" "$repo"
406+
rp_callModule esthemes install_theme "$theme" "$repo" "$branch"
386407
fi
387408
;;
388409
esac

0 commit comments

Comments
 (0)