From d7dc0e4bec3ff9c7e9eaee4d3125a16eea8a7846 Mon Sep 17 00:00:00 2001 From: Johannes Emerich Date: Thu, 2 May 2024 17:17:41 +0000 Subject: [PATCH] Allow using the kiosk on platforms without DBus We previously added support for using the kiosk without connman installed, but it still crashed when started on systems without DBus (i.e. any non-Linux platform). With this change we add a stub implementation of the core proxy abstraction, which is going to provide safe no-op responses on non-Linux platforms, allowing to use the kiosk, albeit without proxy support. --- kiosk/Readme.md | 6 ++++ kiosk/kiosk_browser/main_widget.py | 2 +- kiosk/kiosk_browser/proxy.py | 44 +++++++++++++++++++++++++++--- 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/kiosk/Readme.md b/kiosk/Readme.md index b02467e4..b5d28c67 100644 --- a/kiosk/Readme.md +++ b/kiosk/Readme.md @@ -28,3 +28,9 @@ Then, point a Chromium-based browser to `http://127.0.0.1:3355`. Additional documentation is available at: https://doc.qt.io/qt-6/qtwebengine-debugging.html + +## Supported platforms + +The kiosk is written with use within PlayOS in mind (implying connman and DBus as part of the system). To allow for testing web pages in the kiosk on developer machines, macOS is also supported, with the following limitations: + +- No proxy server support diff --git a/kiosk/kiosk_browser/main_widget.py b/kiosk/kiosk_browser/main_widget.py index 686edb6d..1a8aaa4d 100644 --- a/kiosk/kiosk_browser/main_widget.py +++ b/kiosk/kiosk_browser/main_widget.py @@ -14,7 +14,7 @@ def __init__(self, kiosk_url: str, settings_url: str, toggle_settings_key: str): super(MainWidget, self).__init__() # Proxy - proxy = proxy_module.Proxy() + proxy = proxy_module.init() proxy.start_monitoring_daemon() # Browser widget diff --git a/kiosk/kiosk_browser/proxy.py b/kiosk/kiosk_browser/proxy.py index 5c5c3dd6..60641867 100644 --- a/kiosk/kiosk_browser/proxy.py +++ b/kiosk/kiosk_browser/proxy.py @@ -4,6 +4,7 @@ import collections import dbus import logging +import platform import threading import urllib from PyQt6.QtNetwork import QNetworkProxy @@ -115,9 +116,47 @@ def set_no_proxy_in_qt_app(): logging.info(f"Set no proxy in Qt application") QNetworkProxy.setApplicationProxy(QNetworkProxy()) -class Proxy(): +def init(): + """Initialize a suitable Proxy instance for the current platform.""" + if platform.system() in ['Linux']: + return DBusProxy() + else: + return Proxy() + +class Proxy: + """Base class for proxy querying. + + The base class does not know how to query for proxy information and may be used as a fallback that always reports that no proxy is configured. + """ + _proxy: ProxyConf | None + + # For the base class, this is a pass, not knowing how to monitor in the general case. + def start_monitoring_daemon(self) -> None: + """Start a daemon monitoring for proxy changes. + + In the base class, no monitoring method is known, and starting a daemon is skipped. + """ + pass + + def get_current(self) -> ProxyConf | None: + """Get the currently configured proxy. + + This is always `None` in the base class. + """ + return self._proxy + +class DBusProxy(Proxy): + """A Proxy class for DBus/Linux systems. + + This class assumes that connman is the network manager and that it can be queried via DBus. + """ + + _proxy: ProxyConf | None + _bus: dbus.SystemBus def __init__(self): + super().__init__() + DBusGMainLoop(set_as_default=True) self._bus = dbus.SystemBus() self._proxy = get_current_proxy(self._bus) @@ -129,9 +168,6 @@ def start_monitoring_daemon(self): thread.daemon = True thread.start() - def get_current(self): - return self._proxy - def _monitor(self): self._bus.add_signal_receiver( handler_function = self._on_property_changed,