@@ -295,49 +295,6 @@ def render_keybinding(inp_str: str) -> str:
295295 return "+" .join (key_tokens )
296296
297297
298- class RootUserBusModal (ModalScreen [bool ]):
299- """
300- Present a simple screen to inform the user that they
301- are about to access the `root --user` service bus,
302- which usually leads to a crash.
303-
304- Returns their selection.
305- """
306-
307- BINDINGS = [
308- Binding ("escape" , "close" , "Close" , show = True ),
309- ]
310- AUTO_FOCUS = "#no"
311-
312- def __init__ (
313- self ,
314- ** kwargs ,
315- ):
316- super ().__init__ (** kwargs )
317-
318- def compose (self ) -> ComposeResult :
319- with VerticalGroup ():
320- yield Markdown (
321- "# About to access **root --user** bus\n "
322- + "Usually the `root` user does _not_ have a dedicated `--user` bus. "
323- + "The application will crash if you try to connect to a non-existing bus. "
324- + "Are you sure you want to connect to it?\n \n "
325- + "You can update the settings to auto-accept this question if this is what you want."
326- )
327- with HorizontalGroup ():
328- yield Button ("No" , id = "no" , variant = "primary" )
329- yield Button ("Yes" , id = "yes" , variant = "warning" )
330- yield Footer ()
331-
332- def action_close (self ) -> None :
333- self .dismiss (False )
334-
335- def on_button_pressed (self , event : Button .Pressed ) -> None :
336- if event .button .id == "no" :
337- self .dismiss (False )
338- self .dismiss (True )
339-
340-
341298class SystemctlActionScreen (ModalScreen [Optional [str ]]):
342299 """
343300 Present a screen with the configured systemctl actions.
@@ -923,15 +880,6 @@ class Settings(BaseSettings):
923880 Note: The output is not trimmed when a pager or editor is opened!""" ),
924881 )
925882
926- auto_accept_connection_to_root_user_bus : bool = Field (
927- default = False ,
928- description = dedent ("""\
929- By default, the user is asked if they actually want to connect
930- to the `root --user` bus, as this usually crashes the running program.
931- If this option is `True`, the question is skipped.
932- """ ),
933- )
934-
935883 # https://github.com/tinted-theming/home?tab=readme-ov-file
936884 @classmethod
937885 def settings_customise_sources (
@@ -2183,20 +2131,7 @@ def action_copy_unit_path(self) -> None:
21832131 self .app .copy_to_clipboard (path )
21842132 self .notify (f"Copied '{ path } ' to the clipboard." )
21852133
2186- async def wants_root_user_bus (self ) -> bool :
2187- """
2188- Ask the user if they know what they actually want to connect to the
2189- user-bus of the `root` user.
2190- """
2191- prev_focus = self .focused
2192- self .set_focus (None )
2193- do_switch = await self .app .push_screen_wait (RootUserBusModal ())
2194- self .set_focus (prev_focus )
2195- return do_switch
2196-
2197- # `work` is required to push the screen for `wants_root_user_bus`.
2198- @work
2199- async def action_toggle_mode (self ) -> None :
2134+ def action_toggle_mode (self ) -> None :
22002135 """
22012136 Toggle the current `bus`.
22022137 Try to protect the user from accidentally crashing the program by trying
@@ -2205,12 +2140,22 @@ async def action_toggle_mode(self) -> None:
22052140
22062141 - <https://github.com/isd-project/isd/issues/30>
22072142 """
2208- if (
2209- is_root ()
2210- and self .mode == "system"
2211- and not self .settings .auto_accept_connection_to_root_user_bus
2212- ):
2213- if not (await self .wants_root_user_bus ()):
2143+ if is_root () and self .mode == "system" :
2144+ # Test if `root` user can actually connect to a `--user` bus.
2145+ proc = subprocess .run (
2146+ systemctl_args_builder ("is-system-running" , mode = "user" , units = []),
2147+ capture_output = True ,
2148+ text = True ,
2149+ )
2150+ if proc .returncode != 0 :
2151+ self .notify (
2152+ "Could not connect to `root` users `--user` bus.\n "
2153+ + "Usually, this does not work, as the `root` user does not have any `user` services.\n "
2154+ + "The connection was tested via `systemctl --user is-system-running` as `root` user with the full error message below:\n \n "
2155+ + proc .stderr ,
2156+ severity = "error" ,
2157+ timeout = 60 ,
2158+ )
22142159 return
22152160
22162161 self .mode = "system" if self .mode == "user" else "user"
0 commit comments