diff --git a/proton/vpn/cli/__init__.py b/proton/vpn/cli/__init__.py index 002c7bf..744c64d 100644 --- a/proton/vpn/cli/__init__.py +++ b/proton/vpn/cli/__init__.py @@ -51,22 +51,27 @@ async def _vpn_gui_running() -> bool: - bus = await MessageBus(bus_type=BusType.SESSION).connect() - - reply = await bus.call( - Message( - destination="org.freedesktop.DBus", - path="/org/freedesktop/DBus", - interface="org.freedesktop.DBus", - member="ListNames", + try: + bus = await MessageBus(bus_type=BusType.SESSION).connect() + + reply = await bus.call( + Message( + destination="org.freedesktop.DBus", + path="/org/freedesktop/DBus", + interface="org.freedesktop.DBus", + member="ListNames", + ) ) - ) - if reply.message_type == MessageType.ERROR: - return False + if reply.message_type == MessageType.ERROR: + return False - session_bus_names = reply.body[0] - return GTK_APP_ID in session_bus_names + session_bus_names = reply.body[0] + return GTK_APP_ID in session_bus_names + except Exception: + # No DBus session available (e.g. headless server). + # If DBus is not running, the GUI can't be running either. + return False _CLICK_CONTEXT_SETTINGS = {"help_option_names": ['--help', '-h']}