Skip to content

Commit 7a8f528

Browse files
authored
Merge pull request #3413 from joolswills/es_210_prep
esthemes preparations for new ES stable 2.10
2 parents b3acb00 + 10dab7c commit 7a8f528

File tree

1 file changed

+70
-16
lines changed

1 file changed

+70
-16
lines changed

scriptmodules/supplementary/esthemes.sh

Lines changed: 70 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,46 @@ function depends_esthemes() {
2121
fi
2222
}
2323

24+
function _has_pixel_pos_esthemes() {
25+
local pixel_pos=0
26+
# get the version of emulationstation installed so we can check whether to show
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
31+
compareVersions "$es_ver" ge "2.10" && pixel_pos=1
32+
echo "$pixel_pos"
33+
}
34+
2435
function install_theme_esthemes() {
2536
local theme="$1"
2637
local repo="$2"
27-
local default_branch
38+
local branch="$3"
39+
40+
local pixel_pos="$(_has_pixel_pos_esthemes)"
41+
2842
if [[ -z "$repo" ]]; then
2943
repo="RetroPie"
3044
fi
45+
3146
if [[ -z "$theme" ]]; then
3247
theme="carbon"
3348
repo="RetroPie"
49+
[[ "$pixel_pos" -eq 1 ]] && theme+="-2021"
50+
fi
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"
3460
fi
35-
# Get the name of the default branch, fallback to 'master' if not found
36-
default_branch=$(runCmd git ls-remote --symref --exit-code "https://github.com/$repo/es-theme-$theme.git" HEAD | grep -oP ".*/\K[^\t]+")
37-
[[ -z "$default_branch" ]] && default_branch="master"
61+
3862
mkdir -p "/etc/emulationstation/themes"
39-
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"
4064
}
4165

4266
function uninstall_theme_esthemes() {
@@ -47,7 +71,19 @@ function uninstall_theme_esthemes() {
4771
}
4872

4973
function gui_esthemes() {
50-
local themes=(
74+
local themes=()
75+
76+
local pixel_pos="$(_has_pixel_pos_esthemes)"
77+
78+
if [[ "$pixel_pos" -eq 1 ]]; then
79+
themes+=(
80+
'RetroPie carbon-2021'
81+
'RetroPie carbon-2021 centered'
82+
'RetroPie carbon-2021 nometa'
83+
)
84+
fi
85+
86+
local themes+=(
5187
'RetroPie carbon'
5288
'RetroPie carbon-centered'
5389
'RetroPie carbon-nometa'
@@ -262,6 +298,10 @@ function gui_esthemes() {
262298
)
263299
while true; do
264300
local theme
301+
local theme_dir
302+
local branch
303+
local name
304+
265305
local installed_themes=()
266306
local repo
267307
local options=()
@@ -284,13 +324,20 @@ function gui_esthemes() {
284324
theme=($theme)
285325
repo="${theme[0]}"
286326
theme="${theme[1]}"
287-
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
288335
status+=("i")
289-
options+=("$i" "Update or Uninstall $repo/$theme (installed)")
290-
installed_themes+=("$theme $repo")
336+
options+=("$i" "Update or Uninstall $name (installed)")
337+
installed_themes+=("$theme $repo $branch")
291338
else
292339
status+=("n")
293-
options+=("$i" "Install $repo/$theme")
340+
options+=("$i" "Install $name")
294341
fi
295342
((i++))
296343
done
@@ -329,27 +376,34 @@ function gui_esthemes() {
329376
U)
330377
for theme in "${installed_themes[@]}"; do
331378
theme=($theme)
332-
rp_callModule esthemes install_theme "${theme[0]}" "${theme[1]}"
379+
rp_callModule esthemes install_theme "${theme[0]}" "${theme[1]}" "${theme[2]}"
333380
done
334381
;;
335382
*)
336383
theme=(${themes[choice-1]})
337384
repo="${theme[0]}"
338385
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
339393
if [[ "${status[choice]}" == "i" ]]; then
340-
options=(1 "Update $repo/$theme" 2 "Uninstall $repo/$theme")
341-
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)
342396
local choice=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
343397
case "$choice" in
344398
1)
345-
rp_callModule esthemes install_theme "$theme" "$repo"
399+
rp_callModule esthemes install_theme "$theme" "$repo" "$branch"
346400
;;
347401
2)
348-
rp_callModule esthemes uninstall_theme "$theme"
402+
rp_callModule esthemes uninstall_theme "$theme_dir"
349403
;;
350404
esac
351405
else
352-
rp_callModule esthemes install_theme "$theme" "$repo"
406+
rp_callModule esthemes install_theme "$theme" "$repo" "$branch"
353407
fi
354408
;;
355409
esac

0 commit comments

Comments
 (0)