From 1948181e36fe38b3601af786cf3bc82dd8ddb2e5 Mon Sep 17 00:00:00 2001 From: Alain Zscheile Date: Sun, 3 Sep 2023 13:39:15 +0200 Subject: [PATCH] fix obvious errors when NetworkManager is missing --- eduvpn/cli.py | 3 ++- eduvpn/nm.py | 10 ++++------ eduvpn/ui/ui.py | 1 - 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/eduvpn/cli.py b/eduvpn/cli.py index 25234cd8..33256e15 100644 --- a/eduvpn/cli.py +++ b/eduvpn/cli.py @@ -488,7 +488,8 @@ def update_state_callback(callback): # This exits the main loop and gives back control to the CLI callback() - nm.action_with_mainloop(update_state_callback) + if self.nm_manager.available: + nm.action_with_mainloop(update_state_callback) def interactive(self, _): # Show a title and the help diff --git a/eduvpn/nm.py b/eduvpn/nm.py index b77ec672..e944200a 100644 --- a/eduvpn/nm.py +++ b/eduvpn/nm.py @@ -19,7 +19,7 @@ from eduvpn.utils import run_in_glib_thread from eduvpn.variants import ApplicationVariant -gi.require_version("NM", "1.0") # noqa: E402 +from gi.repository import GLib # type: ignore from gi.repository.Gio import Task # type: ignore _logger = logging.getLogger(__name__) @@ -27,10 +27,8 @@ LINUX_NET_FOLDER = Path("/sys/class/net") try: - import gi - gi.require_version("NM", "1.0") - from gi.repository import NM, GLib # type: ignore + from gi.repository import NM # type: ignore except (ImportError, ValueError): _logger.warning("Network Manager not available") NM = None @@ -238,7 +236,7 @@ def iface(self) -> Optional[str]: return devices[0].get_iface() @property - def ipv4_config(self) -> Optional[NM.IPConfig]: + def ipv4_config(self) -> Optional["NM.IPConfig"]: """ Get the ipv4 config for the active VPN connection """ @@ -792,7 +790,7 @@ def quit_loop(*args, **kwargs): def add_connection_callback( - client: NM.Client, result: Task, user_data: Tuple[NMManager, Optional[Callable]] + client: "NM.Client", result: Task, user_data: Tuple[NMManager, Optional[Callable]] ) -> None: object, callback = user_data new_con = client.add_connection_finish(result) diff --git a/eduvpn/ui/ui.py b/eduvpn/ui/ui.py index 0b439167..2d62e052 100644 --- a/eduvpn/ui/ui.py +++ b/eduvpn/ui/ui.py @@ -11,7 +11,6 @@ import gi gi.require_version("Gtk", "3.0") # noqa: E402 -gi.require_version("NM", "1.0") # noqa: E402 from datetime import datetime from functools import partial