OnePlatform.DBus is a D-Bus client written from the D-Bus specification using only the .NET base library. OnePlatform.Shell builds
the desktop services apps need on top of it. Everything is typed code: no reflection, no runtime code generation, trimmable and
NativeAOT-clean.
D-Bus client (OnePlatform.DBus)
DBusConnection.ConnectSession()/Connect(address):unix:path=andunix:abstract=addresses (a;list is tried in order), SASLEXTERNAL,Hello. One reader thread blocks on the socket; nothing polls.Call(blocking),CallAsync,Send,EmitSignal,Subscribe(match rules),RequestName/ReleaseName.Export(path, DBusInterfaceHandler)serves method calls;org.freedesktop.DBus.Properties,IntrospectableandPeerare answered by the connection.Dispatcheris anAction<Action>: signal handlers, exported methods andCallAsynccompletions are passed to it so an app can run them on its UI thread. Left null, they run on the reader thread.DBusValueis the typed value tree (all types, variants, structs, dictionaries).DBusMessage.Parsereads untrusted bytes with bounds checks, both byte orders, and throws onlyDBusProtocolException.
Implemented from the specification: type system and signatures, marshalling and alignment, message and header-field format, the
authentication handshake (EXTERNAL), name and match-rule handling on the message bus, the standard interfaces named above.
Not implemented: Unix file descriptor passing (h values marshal as indices only), DBUS_COOKIE_SHA1 authentication, TCP and unixexec
transports, systemd: addresses, the server side of the bus. Messages are limited to 32 MiB.
Services (OnePlatform.Shell)
| Type | Interface |
|---|---|
SingleInstance | org.freedesktop.Application on a bus name equal to the app id |
FileChooserPortal | org.freedesktop.portal.FileChooser |
ScreenshotPortal | org.freedesktop.portal.Screenshot |
GlobalShortcutsSession | org.freedesktop.portal.GlobalShortcuts |
NotificationService | org.freedesktop.portal.Notification, falling back to org.freedesktop.Notifications |
TrayIcon | org.kde.StatusNotifierItem with a com.canonical.dbusmenu menu, registered with the StatusNotifierWatcher; icon from a themed name, or from IconImage pictures published as IconPixmap (see desktop-windows.md, "Window icons") |
A service or interface that is not on the bus throws DBusServiceUnavailableException, whose message names both, for example
org.freedesktop.portal.GlobalShortcuts not available on the session bus (service org.freedesktop.portal.Desktop).
Telling the portal which app is calling
xdg-desktop-portal attributes each request to an application id. It works the id out from how the program was started (a
.desktop activation or a systemd scope named app-<id>…). A program started directly, such as an AppImage that was never installed or a
build output, has neither, and the portal refuses global shortcuts with org.freedesktop.portal.Error.NotAllowed: An app id is required.
The portal's org.freedesktop.host.portal.Registry interface lets a program that is not sandboxed declare its id on its own bus
connection. Set DBusConnection.PortalAppId right after connecting; the first call made through FileChooserPortal, ScreenshotPortal,
GlobalShortcutsSession or NotificationService on that connection registers it first (the portal accepts the call only before any other
portal call, and only once). DBusConnection.PortalRegistration reports Registered, Unavailable (a portal without the interface: the
calls behave as before) or Failed (the portal refused, with its reason).
The portal only accepts an id that matches an applications/<id>.desktop file in the user's or the system's data directories ("App info
not found"). Set DBusConnection.PortalCreateDesktopEntry = true to have a hidden entry (NoDisplay=true, Exec the running program or
$APPIMAGE, Name from PortalAppName) written to $XDG_DATA_HOME/applications first when none exists. It is never overwritten or
removed, and nothing is written unless the app sets the property. The desktop shows PortalAppName in its shortcut dialog.
When the portal still answers "An app id is required", the call throws PortalAppIdRequiredException (a DBusException; the portal's
DBusErrorException is its InnerException) whose message says whether an id was declared and why registering did not work.
tests/OnePlatform.ShortcutProof binds a shortcut this way from a directly started program.
Tests
Tests start their own dbus-daemon with a minimal configuration (no service activation) and pass its address explicitly; they skip
when the daemon is not installed. The portals, the tray watcher and the notification server are fakes in the tests, written from the
interface documentation. tests/OnePlatform.DBusFuzz is a mutation fuzzer for the message reader.