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 2, 2024
1 parent 3d022a8 commit c1a1722
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 8 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
52 changes: 45 additions & 7 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 All @@ -140,17 +176,19 @@ def _monitor(self):

# Update just after monitoring is on, so that we do not miss any proxy
# modification that could have happen before.
self._update(get_current_proxy(self._bus))
self._update()

loop = GLib.MainLoop()
loop.run()

def _on_property_changed(self, *args, **kwargs):
if len(args) >= 2 and args[0] == 'Proxy':
self._update(get_current_proxy(self._bus))
self._update()

def _update(self, new_proxy):
def _update(self):
"""Update the proxy and use in Qt application, if the value has changed."""
new_proxy = get_current_proxy(self._bus) if self._bus else None

if new_proxy != self._proxy:
self._proxy = new_proxy
self._use_in_qt_app()
Expand Down

0 comments on commit c1a1722

Please sign in to comment.