Skip to content

Commit 0895d3d

Browse files
committed
Refactor profile seat access selection
1 parent b842e54 commit 0895d3d

6 files changed

Lines changed: 49 additions & 110 deletions

File tree

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +0,0 @@
1-
from enum import Enum
2-
3-
4-
class SeatAccess(Enum):
5-
seatd = 'seatd'
6-
polkit = 'polkit'

archinstall/default_profiles/desktops/hyprland.py

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
from typing import override
22

3-
from archinstall.default_profiles.desktops import SeatAccess
3+
from archinstall.default_profiles.desktops.utils import select_seat_access
44
from archinstall.default_profiles.profile import CustomSetting, DisplayServerType, GreeterType, Profile, ProfileType
5-
from archinstall.lib.menu.helpers import Selection
6-
from archinstall.lib.translationhandler import tr
7-
from archinstall.tui.ui.menu_item import MenuItem, MenuItemGroup
8-
from archinstall.tui.ui.result import ResultType
95

106

117
class HyprlandProfile(Profile):
@@ -49,26 +45,8 @@ def services(self) -> list[str]:
4945
return [pref]
5046
return []
5147

52-
async def _select_seat_access(self) -> None:
53-
# need to activate seat service and add to seat group
54-
header = tr('Hyprland needs access to your seat (collection of hardware devices i.e. keyboard, mouse, etc)')
55-
header += '\n' + tr('Choose an option to give Hyprland access to your hardware') + '\n'
56-
57-
items = [MenuItem(s.value, value=s) for s in SeatAccess]
58-
group = MenuItemGroup(items, sort_items=True)
59-
60-
default = self.custom_settings.get(CustomSetting.SeatAccess, None)
61-
group.set_default_by_value(default)
62-
63-
result = await Selection[SeatAccess](
64-
group,
65-
header=header,
66-
allow_skip=False,
67-
).show()
68-
69-
if result.type_ == ResultType.Selection:
70-
self.custom_settings[CustomSetting.SeatAccess] = result.get_value().value
71-
7248
@override
7349
async def do_on_select(self) -> None:
74-
await self._select_seat_access()
50+
default = self.custom_settings.get(CustomSetting.SeatAccess, None)
51+
seat_access = await select_seat_access(self.name, default)
52+
self.custom_settings[CustomSetting.SeatAccess] = seat_access.value

archinstall/default_profiles/desktops/labwc.py

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
from typing import override
22

3-
from archinstall.default_profiles.desktops import SeatAccess
3+
from archinstall.default_profiles.desktops.utils import select_seat_access
44
from archinstall.default_profiles.profile import CustomSetting, DisplayServerType, GreeterType, Profile, ProfileType
5-
from archinstall.lib.menu.helpers import Selection
6-
from archinstall.lib.translationhandler import tr
7-
from archinstall.tui.ui.menu_item import MenuItem, MenuItemGroup
8-
from archinstall.tui.ui.result import ResultType
95

106

117
class LabwcProfile(Profile):
@@ -43,26 +39,8 @@ def services(self) -> list[str]:
4339
return [pref]
4440
return []
4541

46-
async def _select_seat_access(self) -> None:
47-
# need to activate seat service and add to seat group
48-
header = tr('labwc needs access to your seat (collection of hardware devices i.e. keyboard, mouse, etc)')
49-
header += '\n' + tr('Choose an option to give labwc access to your hardware') + '\n'
50-
51-
items = [MenuItem(s.value, value=s) for s in SeatAccess]
52-
group = MenuItemGroup(items, sort_items=True)
53-
54-
default = self.custom_settings.get(CustomSetting.SeatAccess, None)
55-
group.set_default_by_value(default)
56-
57-
result = await Selection[SeatAccess](
58-
group,
59-
header=header,
60-
allow_skip=False,
61-
).show()
62-
63-
if result.type_ == ResultType.Selection:
64-
self.custom_settings[CustomSetting.SeatAccess] = result.get_value().value
65-
6642
@override
6743
async def do_on_select(self) -> None:
68-
await self._select_seat_access()
44+
default = self.custom_settings.get(CustomSetting.SeatAccess, None)
45+
seat_access = await select_seat_access(self.name, default)
46+
self.custom_settings[CustomSetting.SeatAccess] = seat_access.value

archinstall/default_profiles/desktops/niri.py

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
from typing import override
22

3-
from archinstall.default_profiles.desktops import SeatAccess
3+
from archinstall.default_profiles.desktops.utils import select_seat_access
44
from archinstall.default_profiles.profile import CustomSetting, DisplayServerType, GreeterType, Profile, ProfileType
5-
from archinstall.lib.menu.helpers import Selection
6-
from archinstall.lib.translationhandler import tr
7-
from archinstall.tui.ui.menu_item import MenuItem, MenuItemGroup
8-
from archinstall.tui.ui.result import ResultType
95

106

117
class NiriProfile(Profile):
@@ -51,26 +47,8 @@ def services(self) -> list[str]:
5147
return [pref]
5248
return []
5349

54-
async def _select_seat_access(self) -> None:
55-
# need to activate seat service and add to seat group
56-
header = tr('niri needs access to your seat (collection of hardware devices i.e. keyboard, mouse, etc)')
57-
header += '\n' + tr('Choose an option to give niri access to your hardware') + '\n'
58-
59-
items = [MenuItem(s.value, value=s) for s in SeatAccess]
60-
group = MenuItemGroup(items, sort_items=True)
61-
62-
default = self.custom_settings.get(CustomSetting.SeatAccess, None)
63-
group.set_default_by_value(default)
64-
65-
result = await Selection[SeatAccess](
66-
group,
67-
header=header,
68-
allow_skip=False,
69-
).show()
70-
71-
if result.type_ == ResultType.Selection:
72-
self.custom_settings[CustomSetting.SeatAccess] = result.get_value().value
73-
7450
@override
7551
async def do_on_select(self) -> None:
76-
await self._select_seat_access()
52+
default = self.custom_settings.get(CustomSetting.SeatAccess, None)
53+
seat_access = await select_seat_access(self.name, default)
54+
self.custom_settings[CustomSetting.SeatAccess] = seat_access.value

archinstall/default_profiles/desktops/sway.py

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
from typing import override
22

3-
from archinstall.default_profiles.desktops import SeatAccess
3+
from archinstall.default_profiles.desktops.utils import select_seat_access
44
from archinstall.default_profiles.profile import CustomSetting, DisplayServerType, GreeterType, Profile, ProfileType
5-
from archinstall.lib.menu.helpers import Selection
6-
from archinstall.lib.translationhandler import tr
7-
from archinstall.tui.ui.menu_item import MenuItem, MenuItemGroup
8-
from archinstall.tui.ui.result import ResultType
95

106

117
class SwayProfile(Profile):
@@ -53,26 +49,8 @@ def services(self) -> list[str]:
5349
return [pref]
5450
return []
5551

56-
async def _select_seat_access(self) -> None:
57-
# need to activate seat service and add to seat group
58-
header = tr('Sway needs access to your seat (collection of hardware devices i.e. keyboard, mouse, etc)')
59-
header += '\n' + tr('Choose an option to give Sway access to your hardware') + '\n'
60-
61-
items = [MenuItem(s.value, value=s) for s in SeatAccess]
62-
group = MenuItemGroup(items, sort_items=True)
63-
64-
default = self.custom_settings.get(CustomSetting.SeatAccess, None)
65-
group.set_default_by_value(default)
66-
67-
result = await Selection[SeatAccess](
68-
group,
69-
header=header,
70-
allow_skip=False,
71-
).show()
72-
73-
if result.type_ == ResultType.Selection:
74-
self.custom_settings[CustomSetting.SeatAccess] = result.get_value().value
75-
7652
@override
7753
async def do_on_select(self) -> None:
78-
await self._select_seat_access()
54+
default = self.custom_settings.get(CustomSetting.SeatAccess, None)
55+
seat_access = await select_seat_access(self.name, default)
56+
self.custom_settings[CustomSetting.SeatAccess] = seat_access.value
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from enum import Enum
2+
3+
from archinstall.lib.menu.helpers import Selection
4+
from archinstall.lib.translationhandler import tr
5+
from archinstall.tui.ui.menu_item import MenuItem, MenuItemGroup
6+
from archinstall.tui.ui.result import ResultType
7+
8+
9+
class SeatAccess(Enum):
10+
seatd = 'seatd'
11+
polkit = 'polkit'
12+
13+
14+
async def select_seat_access(profile_name: str, default: str | None) -> SeatAccess:
15+
header = tr('{} needs access to your seat').format(profile_name)
16+
header += f' ({tr("collection of hardware devices i.e. keyboard, mouse")})' + '\n'
17+
header += tr('Choose an option how to give access to your hardware')
18+
19+
items = [MenuItem(s.value, value=s) for s in SeatAccess]
20+
group = MenuItemGroup(items, sort_items=True)
21+
22+
group.set_default_by_value(default)
23+
24+
result = await Selection[SeatAccess](
25+
group,
26+
header=header,
27+
allow_skip=False,
28+
).show()
29+
30+
if result.type_ == ResultType.Selection:
31+
return result.get_value()
32+
else:
33+
raise ValueError('Unexpected result type from seat access selection')

0 commit comments

Comments
 (0)