refactor: theme_enable and create_desktop_shortcut in steps; make test skips the hardware test
Sync git.upriser.nl mirror / sync (push) Skipped

This commit is contained in:
theupriser committed 2026-10-03 13:19:24 +02:00
1 parent 095e7bca5c
commit ac0e5e28b3
4 files changed
+61 -44

No files matched your search

+30 -29
View File
@@ -2,41 +2,46 @@
# "Return to Gaming Mode" desktop shortcut and the sudoers rule it needs.
# Sourced by steamify.sh; not meant to be run on its own.
create_desktop_shortcut() {
# Determine the home directory of the target user
local user_home
shortcut_desktop_dir() {
# The target user's Desktop folder, from their user-dirs.dirs.
local user_home desktop_dir
user_home="$(getent passwd "$TARGET_USER" | cut -d: -f6)"
# Locate the correct Desktop directory
local desktop_dir
if [[ -f "$user_home/.config/user-dirs.dirs" ]]; then
desktop_dir=$(grep '^XDG_DESKTOP_DIR=' "$user_home/.config/user-dirs.dirs" | cut -d '"' -f 2)
desktop_dir="${desktop_dir/\$HOME/$user_home}"
fi
desktop_dir="${desktop_dir:-$user_home/Desktop}"
echo "${desktop_dir:-$user_home/Desktop}"
}
shortcut_install_sudoers() {
# plasma-login-manager needs the sync bridge run and a restart, which the
# shortcut can't sudo for interactively (Terminal=false), so it gets a
# password-less rule scoped to exactly those two commands.
local sudoers_tmp
sudoers_tmp="$(mktemp)"
cat > "$sudoers_tmp" << EOF
$TARGET_USER ALL=(root) NOPASSWD: /usr/bin/systemctl start sync-steamos-session.service, /usr/bin/systemctl restart plasmalogin
EOF
if sudo visudo -cf "$sudoers_tmp" >/dev/null; then
sudo install -m 0440 -o root -g root "$sudoers_tmp" /etc/sudoers.d/gamescope-session-switch
ok "Installed /etc/sudoers.d/gamescope-session-switch for the shortcut."
else
warn "Generated sudoers rule failed validation; the shortcut will not be able to restart plasmalogin."
fi
rm -f "$sudoers_tmp"
}
create_desktop_shortcut() {
local desktop_dir
desktop_dir="$(shortcut_desktop_dir)"
mkdir -p "$desktop_dir"
# On SDDM, steamos-session-select logging out is enough: Relogin=true
# logs straight back in to the newly selected session, like SteamOS.
# plasma-login-manager needs the sync bridge run and a restart, which
# the shortcut can't sudo for interactively (Terminal=false), so it gets
# a password-less rule scoped to exactly those two commands.
local exec_line="steamos-session-select gamescope"
if [[ "$LOGIN_MANAGER" == "plasmalogin" ]]; then
exec_line="sh -c 'steamos-session-select gamescope && sudo -n /usr/bin/systemctl start sync-steamos-session.service && sudo -n /usr/bin/systemctl restart plasmalogin'"
local sudoers_tmp
sudoers_tmp="$(mktemp)"
cat > "$sudoers_tmp" << EOF
$TARGET_USER ALL=(root) NOPASSWD: /usr/bin/systemctl start sync-steamos-session.service, /usr/bin/systemctl restart plasmalogin
EOF
if sudo visudo -cf "$sudoers_tmp" >/dev/null; then
sudo install -m 0440 -o root -g root "$sudoers_tmp" /etc/sudoers.d/gamescope-session-switch
ok "Installed /etc/sudoers.d/gamescope-session-switch for the shortcut."
else
warn "Generated sudoers rule failed validation; the shortcut will not be able to restart plasmalogin."
fi
rm -f "$sudoers_tmp"
shortcut_install_sudoers
else
sudo rm -f /etc/sudoers.d/gamescope-session-switch
fi
@@ -49,11 +54,11 @@ EOF
[[ -f /usr/local/share/icons/hicolor/scalable/actions/gaming-return.svg ]] &&
shortcut_icon="gaming-return"
# 2. Generate the .desktop shortcut with instant session switcher strings
local shortcut_path="$desktop_dir/Return to Gaming Mode.desktop"
info "Creating 'Return to Gaming Mode' desktop shortcut at: $shortcut_path"
cat << EOF > "$shortcut_path"
# Written with its mode already set: Plasma opens a desktop icon it first
# saw non-executable in an editor.
install_executable "$shortcut_path" 755 << EOF
[Desktop Entry]
Name=Return to Gaming Mode
Comment=Switch session back to Gamescope
@@ -63,10 +68,6 @@ Terminal=false
Type=Application
Categories=System;
EOF
# Fix permissions for the target user and KDE Plasma desktop ecosystem
chmod +x "$shortcut_path"
ok "Desktop shortcut created successfully."
}
+28 -14
View File
@@ -47,26 +47,27 @@ theme_status() {
[[ "$(kreadconfig6 --file kdeglobals --group KDE --key LookAndFeelPackage)" == "$VAPOR_LOOKANDFEEL" ]]
}
theme_enable() {
if ! pacman -Q cachyos-vapor >/dev/null 2>&1; then
info "Installing cachyos-vapor..."
sudo pacman -S --needed --noconfirm cachyos-vapor || { err "Installing cachyos-vapor failed."; return 1; }
# Only remove it again on disable if we were the ones installing it.
state_set theme installed_pkg 1
fi
theme_install_package() {
pacman -Q cachyos-vapor >/dev/null 2>&1 && return 0
info "Installing cachyos-vapor..."
sudo pacman -S --needed --noconfirm cachyos-vapor || { err "Installing cachyos-vapor failed."; return 1; }
# Only remove it again on disable if we were the ones installing it.
state_set theme installed_pkg 1
}
theme_check_offline() {
# Without a session (the ISO's installer), for a user who has never
# logged in: the layout still CachyOS's default from /etc/skel is
# removed (after the backup below), and Plasma builds its first layout
# from the look-and-feel package, as --resetLayout does below.
local offline=false layout=~/.config/plasma-org.kde.plasma.desktop-appletsrc
if [[ -z "${WAYLAND_DISPLAY:-}${DISPLAY:-}" ]]; then
if [[ -e "$layout" ]] && ! cmp -s "$layout" "/etc/skel/.config/${layout##*/}"; then
err "Run this from the Plasma desktop: applying the Vapor layout needs a running Plasma session."
return 1
fi
offline=true
local layout=~/.config/plasma-org.kde.plasma.desktop-appletsrc
if [[ -e "$layout" ]] && ! cmp -s "$layout" "/etc/skel/.config/${layout##*/}"; then
err "Run this from the Plasma desktop: applying the Vapor layout needs a running Plasma session."
return 1
fi
}
theme_backup_originals() {
# Only the first time, so a re-apply doesn't overwrite the originals.
local backup="$STATE_DIR/theme-layout" f
if [[ ! -d "$backup" ]]; then
@@ -84,7 +85,9 @@ theme_enable() {
[[ -f "$f" ]] && kset theme "$f" Settings gtk-cursor-theme-name \
"$(kreadconfig6 --file "$f" --group Settings --key gtk-cursor-theme-name)"
done
}
theme_set_look() {
kset theme kdeglobals KDE LookAndFeelPackage "$VAPOR_LOOKANDFEEL"
# Vapor is a dark theme: register it as the dark one, or Plasma's Dark
# Mode toggle shows "off" and offers to switch to Breeze Dark.
@@ -94,6 +97,17 @@ theme_enable() {
# scheme that is already named in the config, without writing its colors.
kset theme kdeglobals General ColorScheme --delete
plasma-apply-colorscheme Vapor >/dev/null 2>&1 || true
}
theme_enable() {
theme_install_package || return 1
local offline=false
if [[ -z "${WAYLAND_DISPLAY:-}${DISPLAY:-}" ]]; then
theme_check_offline || return 1
offline=true
fi
theme_backup_originals
theme_set_look
if [[ "$offline" == true ]]; then
rm -f ~/.config/plasma-org.kde.plasma.desktop-appletsrc ~/.config/plasmashellrc