diff --git a/archinstall/default_profiles/desktops/hyprland.py b/archinstall/default_profiles/desktops/hyprland.py index 0bf46b96db..d2f8ab250d 100644 --- a/archinstall/default_profiles/desktops/hyprland.py +++ b/archinstall/default_profiles/desktops/hyprland.py @@ -1,6 +1,6 @@ from typing import override -from archinstall.default_profiles.desktops.utils import select_seat_access +from archinstall.default_profiles.desktops.utils import SeatAccess, select_seat_access from archinstall.default_profiles.profile import CustomSetting, DisplayServerType, GreeterType, Profile, ProfileType @@ -41,8 +41,8 @@ def default_greeter_type(self) -> GreeterType: @property @override def services(self) -> list[str]: - if pref := self.custom_settings.get(CustomSetting.SeatAccess, None): - return [pref] + if self.custom_settings.get(CustomSetting.SeatAccess) == SeatAccess.Seatd: + return ['seatd'] return [] @override diff --git a/archinstall/default_profiles/desktops/labwc.py b/archinstall/default_profiles/desktops/labwc.py index 48fe344e13..9d1710c930 100644 --- a/archinstall/default_profiles/desktops/labwc.py +++ b/archinstall/default_profiles/desktops/labwc.py @@ -1,6 +1,6 @@ from typing import override -from archinstall.default_profiles.desktops.utils import select_seat_access +from archinstall.default_profiles.desktops.utils import SeatAccess, select_seat_access from archinstall.default_profiles.profile import CustomSetting, DisplayServerType, GreeterType, Profile, ProfileType @@ -35,8 +35,8 @@ def default_greeter_type(self) -> GreeterType: @property @override def services(self) -> list[str]: - if pref := self.custom_settings.get(CustomSetting.SeatAccess, None): - return [pref] + if self.custom_settings.get(CustomSetting.SeatAccess) == SeatAccess.Seatd: + return ['seatd'] return [] @override diff --git a/archinstall/default_profiles/desktops/niri.py b/archinstall/default_profiles/desktops/niri.py index d8db75f5da..893202bb84 100644 --- a/archinstall/default_profiles/desktops/niri.py +++ b/archinstall/default_profiles/desktops/niri.py @@ -1,6 +1,6 @@ from typing import override -from archinstall.default_profiles.desktops.utils import select_seat_access +from archinstall.default_profiles.desktops.utils import SeatAccess, select_seat_access from archinstall.default_profiles.profile import CustomSetting, DisplayServerType, GreeterType, Profile, ProfileType @@ -43,8 +43,8 @@ def default_greeter_type(self) -> GreeterType: @property @override def services(self) -> list[str]: - if pref := self.custom_settings.get(CustomSetting.SeatAccess, None): - return [pref] + if self.custom_settings.get(CustomSetting.SeatAccess) == SeatAccess.Seatd: + return ['seatd'] return [] @override diff --git a/archinstall/default_profiles/desktops/sway.py b/archinstall/default_profiles/desktops/sway.py index 7a038dc0ba..9b50eadfe1 100644 --- a/archinstall/default_profiles/desktops/sway.py +++ b/archinstall/default_profiles/desktops/sway.py @@ -1,6 +1,6 @@ from typing import override -from archinstall.default_profiles.desktops.utils import select_seat_access +from archinstall.default_profiles.desktops.utils import SeatAccess, select_seat_access from archinstall.default_profiles.profile import CustomSetting, DisplayServerType, GreeterType, Profile, ProfileType @@ -45,8 +45,8 @@ def default_greeter_type(self) -> GreeterType: @property @override def services(self) -> list[str]: - if pref := self.custom_settings.get(CustomSetting.SeatAccess, None): - return [pref] + if self.custom_settings.get(CustomSetting.SeatAccess) == SeatAccess.Seatd: + return ['seatd'] return [] @override diff --git a/archinstall/default_profiles/desktops/utils.py b/archinstall/default_profiles/desktops/utils.py index b179ad5061..496f0a1577 100644 --- a/archinstall/default_profiles/desktops/utils.py +++ b/archinstall/default_profiles/desktops/utils.py @@ -1,4 +1,4 @@ -from enum import Enum +from enum import StrEnum from archinstall.lib.installer import Installer from archinstall.lib.menu.helpers import Selection @@ -8,9 +8,9 @@ from archinstall.tui.result import ResultType -class SeatAccess(Enum): - seatd = 'seatd' - polkit = 'polkit' +class SeatAccess(StrEnum): + Seatd = 'seatd' + Logind = 'polkit' # Keep the saved configuration value. def provision_seat_access( @@ -18,7 +18,7 @@ def provision_seat_access( users: list[User], seat_access: str, ) -> None: - if seat_access == SeatAccess.seatd.value: + if seat_access == SeatAccess.Seatd: for user in users: install_session.arch_chroot(f'usermod -a -G seat {user.username}') @@ -28,10 +28,13 @@ async def select_seat_access(profile_name: str, default: str | None) -> SeatAcce header += f' ({tr("collection of hardware devices i.e. keyboard, mouse")})' + '\n' header += tr('Choose an option how to give {} access to your hardware').format(profile_name) - items = [MenuItem(s.value, value=s) for s in SeatAccess] + items = [ + MenuItem('seatd', value=SeatAccess.Seatd), + MenuItem('systemd-logind', value=SeatAccess.Logind), + ] group = MenuItemGroup(items, sort_items=True) - group.set_default_by_value(default) + group.set_focus_by_value(default or SeatAccess.Logind) result = await Selection[SeatAccess]( group, diff --git a/tests/test_seat_access.py b/tests/test_seat_access.py new file mode 100644 index 0000000000..7484e72d1a --- /dev/null +++ b/tests/test_seat_access.py @@ -0,0 +1,49 @@ +import asyncio +from collections.abc import Callable + +import pytest + +from archinstall.default_profiles.desktops.hyprland import HyprlandProfile +from archinstall.default_profiles.desktops.labwc import LabwcProfile +from archinstall.default_profiles.desktops.niri import NiriProfile +from archinstall.default_profiles.desktops.sway import SwayProfile +from archinstall.default_profiles.desktops.utils import SeatAccess +from archinstall.default_profiles.profile import CustomSetting, Profile +from archinstall.lib.menu.helpers import Selection +from archinstall.tui.result import Result + + +@pytest.mark.parametrize('profile_type', [HyprlandProfile, LabwcProfile, NiriProfile, SwayProfile]) +@pytest.mark.parametrize('default', [None, 'seatd', 'polkit']) +@pytest.mark.parametrize('choice', [None, 'seatd', 'polkit']) +def test_seat_access_selection( + monkeypatch: pytest.MonkeyPatch, + profile_type: Callable[[], Profile], + default: str | None, + choice: str | None, +) -> None: + async def show(selection: Selection[SeatAccess]) -> Result[SeatAccess]: + group = selection._group + assert [(item.text, item.get_value().value) for item in group.items] == [ + ('seatd', 'seatd'), + ('systemd-logind', 'polkit'), + ] + index = group.get_focused_index() + assert index == (0 if default == 'seatd' else 1) + if choice is None: + return Result[SeatAccess].selection(group.get_enabled_items()[index].get_value()) + return Result[SeatAccess].selection(next(item.get_value() for item in group.items if item.get_value().value == choice)) + + monkeypatch.setattr(Selection, 'show', show) + profile = profile_type() + profile.custom_settings[CustomSetting.SeatAccess] = default + asyncio.run(profile.do_on_select()) + assert profile.custom_settings[CustomSetting.SeatAccess] == (choice or default or 'polkit') + + +@pytest.mark.parametrize('profile_type', [HyprlandProfile, LabwcProfile, NiriProfile, SwayProfile]) +@pytest.mark.parametrize(('setting', 'services'), [(None, []), ('seatd', ['seatd']), ('polkit', [])]) +def test_seat_access_services(profile_type: Callable[[], Profile], setting: str | None, services: list[str]) -> None: + profile = profile_type() + profile.custom_settings[CustomSetting.SeatAccess] = setting + assert profile.services == services