Skip to content

Commit

Permalink
Allow using the kiosk on platforms without DBus
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
knuton committed May 3, 2024
1 parent 8511097 commit d7dc0e4
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
6 changes: 6 additions & 0 deletions kiosk/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion kiosk/kiosk_browser/main_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 40 additions & 4 deletions kiosk/kiosk_browser/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import collections
import dbus
import logging
import platform
import threading
import urllib
from PyQt6.QtNetwork import QNetworkProxy
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down

0 comments on commit d7dc0e4

Please sign in to comment.