Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions biglinux-livecd/usr/bin/startbiglive
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,39 @@ _split_xkb_layout() {
fi
}

_fcitx5_keyboard_input_method() {
if [[ -n $2 ]]; then
printf 'keyboard-%s-%s\n' "$1" "$2"
else
printf 'keyboard-%s\n' "$1"
fi
}

_configure_fcitx5_keyboard_profile() {
local layout=$1 variant=$2 input_method profile_directory
input_method=$(_fcitx5_keyboard_input_method "$layout" "$variant")
profile_directory=$HOME/.config/fcitx5
mkdir -p -- "$profile_directory"
cat >"$profile_directory/profile" <<EOF
[Groups/0]
# Group Name
Name="Live Keyboard"
# Layout
Default Layout=$layout
# Default Input Method
DefaultIM=$input_method

[Groups/0/Items/0]
# Name
Name=$input_method
# Layout
Layout=

[GroupOrder]
0="Live Keyboard"
EOF
}

#-------------------------------------------------------------------------------
# Anti-loop protection: prevent infinite SDDM restart loops
# Tracks how many times startbiglive has been invoked. If the session keeps
Expand Down Expand Up @@ -553,6 +586,9 @@ ResetOldOptions=true
Use=true
VariantList=$xkb_variant
EOF
if [[ $display_manager == sddm ]]; then
_configure_fcitx5_keyboard_profile "$xkb_layout" "$xkb_variant"
fi
else
_log "ERROR - Ignoring invalid live keyboard selection"
fi
Expand Down Expand Up @@ -642,6 +678,22 @@ if [[ -f "$installer_shortcut" ]]; then
gio set "$installer_shortcut" metadata::trusted true 2>/dev/null || true
fi

_reset_gnome_portals() {
# The wizard can activate the portal before the GNOME environment exists.
# Reset it so the desktop session selects the GNOME Settings backend.
dbus-update-activation-environment --systemd \
DESKTOP_SESSION XDG_SESSION_DESKTOP GDMSESSION XDG_CURRENT_DESKTOP \
2>/dev/null || true
systemctl --user import-environment \
DESKTOP_SESSION XDG_SESSION_DESKTOP GDMSESSION XDG_CURRENT_DESKTOP \
2>/dev/null || true
systemctl --user stop \
xdg-desktop-portal.service \
xdg-desktop-portal-gtk.service \
xdg-desktop-portal-gnome.service \
2>/dev/null || true
}

# libadwaita apps use their own color-scheme setting and can ignore GTK INI files
# in non-GNOME sessions. GNOME reads color-scheme from dconf directly, and the
# forced override would fight the wizard's choice there, so skip it on gdm.
Expand Down Expand Up @@ -675,6 +727,7 @@ elif [[ "$display_manager" == "gdm" ]]; then
# GNOME: Clean up and start gnome-session
rm -f "$HOME/Empty Bash" "$HOME/Empty Desktop File.desktop" "$HOME/Empty File"
xdg-user-dirs-update
_reset_gnome_portals
exec startgnome-community

elif [[ -e /usr/share/wayland-sessions/hyprland.desktop ]]; then
Expand Down
7 changes: 7 additions & 0 deletions tests/test_livecd_keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def test_startbiglive_applies_saved_keyboard_layout(tmp_path: Path) -> None:
result = run_bash(
f"""
_log() {{ :; }}
display_manager=sddm
live_state_path() {{ printf '%s\\n' "$STATE_FILE"; }}
setxkbmap() {{ printf 'setxkbmap:%s\\n' "$*" >>"$COMMAND_LOG"; }}
sudo() {{ printf 'sudo:%s\\n' "$*" >>"$COMMAND_LOG"; }}
Expand All @@ -105,6 +106,7 @@ def test_startbiglive_applies_saved_keyboard_layout(tmp_path: Path) -> None:

assert result.returncode == 0, result.stderr
kxkbrc = (home / ".config/kxkbrc").read_text(encoding="utf-8")
fcitx_profile = (home / ".config/fcitx5/profile").read_text(encoding="utf-8")
commands = command_log.read_text(encoding="utf-8")
assert "setxkbmap:us -variant intl\n" in commands
assert (
Expand All @@ -113,3 +115,8 @@ def test_startbiglive_applies_saved_keyboard_layout(tmp_path: Path) -> None:
)
assert "LayoutList=us\n" in kxkbrc
assert "VariantList=intl\n" in kxkbrc
assert 'Name="Live Keyboard"\n' in fcitx_profile
assert "Default Layout=us\n" in fcitx_profile
assert "DefaultIM=keyboard-us-intl\n" in fcitx_profile
assert "Name=keyboard-us-intl\n" in fcitx_profile
assert '0="Live Keyboard"\n' in fcitx_profile
41 changes: 41 additions & 0 deletions tests/test_livecd_security.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,47 @@ def test_startbiglive_defers_noncritical_work_until_after_wizard() -> None:
assert wizard_launch < theme_sync


def test_startbiglive_resets_early_portals_before_gnome(tmp_path: Path) -> None:
source = STARTBIGLIVE.read_text(encoding="utf-8")
function_start = source.index("_reset_gnome_portals() {")
function_end = source.index("\n}\n", function_start) + 3
function = source[function_start:function_end]
command_log = tmp_path / "commands"
result = run_bash(
f"""
dbus-update-activation-environment() {{
printf 'dbus:%s\\n' "$*" >>"$COMMAND_LOG"
}}
systemctl() {{
printf 'systemctl:%s\\n' "$*" >>"$COMMAND_LOG"
}}
{function}
_reset_gnome_portals
""",
environment={"COMMAND_LOG": str(command_log)},
)
assert result.returncode == 0, result.stderr
assert command_log.read_text(encoding="utf-8").splitlines() == [
(
"dbus:--systemd DESKTOP_SESSION XDG_SESSION_DESKTOP "
"GDMSESSION XDG_CURRENT_DESKTOP"
),
(
"systemctl:--user import-environment DESKTOP_SESSION "
"XDG_SESSION_DESKTOP GDMSESSION XDG_CURRENT_DESKTOP"
),
(
"systemctl:--user stop xdg-desktop-portal.service "
"xdg-desktop-portal-gtk.service "
"xdg-desktop-portal-gnome.service"
),
]
gnome_branch = source.index('elif [[ "$display_manager" == "gdm" ]]')
reset = source.index("_reset_gnome_portals", gnome_branch)
session = source.index("exec startgnome-community", gnome_branch)
assert reset < session


def test_wizard_defers_noninitial_pages_and_accessibility_backends() -> None:
app_window = (
PACKAGE / "usr/share/biglinux/livecd/ui/app_window.py"
Expand Down
Loading