CI / test (push) Failing after 17s
Chrome (and Firefox, Electron, GTK 4, Qt 6) read dark/light from xdg-desktop-portal's Settings
interface. With XDG_CURRENT_DESKTOP=chandra and no chandra-portals.conf, xdg-desktop-portal found
no Settings backend (gtk/gnome are UseIn=gnome, kde is UseIn=KDE) and exported no Settings
interface at all, so the gsettings color-scheme a790901 sets never reached Chrome.
- compositor/portal: the compositor is an org.freedesktop.impl.portal.Settings backend
(org.freedesktop.impl.portal.desktop.chandra on the session bus): Read/ReadAll of
org.freedesktop.appearance color-scheme (1 dark, 2 light), SettingChanged when the switch flips,
version property, introspection. Login session only; the main loop wakes on its socket.
- compositor/network/dbus.mbt: serve calls (on_call, reply, reply_error), emit and receive
signals, sender field, session bus address.
- session/chandra.portal + chandra-portals.conf, installed to /usr/share/xdg-desktop-portal by
install.py: Settings from chandra first, then gtk/kde/gnome; other portals from gtk/kde/gnome.
- chandra-session restarts a running xdg-desktop-portal so it reads the config for this desktop.
- scripts/test-portal-dbus.sh: end to end behind the real xdg-desktop-portal on a private bus
(ReadOne gives 1, flipping gives SettingChanged 2). docs/dark-mode.md: how to check it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hhkztRQM7vcSuHX4bB
180 lines
5.5 KiB
MoonBit
180 lines
5.5 KiB
MoonBit
///|
|
|
fn call(iface : String, meth : String, args : Array[@network.DValue]) -> @network.DMessage {
|
|
@network.DMessage::call(
|
|
@portal.bus_name,
|
|
@portal.object_path,
|
|
iface,
|
|
meth,
|
|
args,
|
|
)
|
|
}
|
|
|
|
///|
|
|
test "Read answers color-scheme: 1 when dark, 2 when light" {
|
|
let p = @portal.SettingsPortal::new(true)
|
|
let read = call(@portal.settings_iface, "Read", [
|
|
Str("org.freedesktop.appearance"),
|
|
Str("color-scheme"),
|
|
])
|
|
assert_eq(p.answer(read), Ok([Variant(U32(1))]))
|
|
p.set_dark(false)
|
|
assert_eq(p.answer(read), Ok([Variant(U32(2))]))
|
|
}
|
|
|
|
///|
|
|
test "Read of an unknown setting is NotFound (so xdg-desktop-portal asks the next backend)" {
|
|
let p = @portal.SettingsPortal::new(true)
|
|
let r = p.answer(
|
|
call(@portal.settings_iface, "Read", [Str("org.gnome.desktop.interface"), Str("gtk-theme")]),
|
|
)
|
|
match r {
|
|
Err((name, _)) => assert_eq(name, "org.freedesktop.portal.Error.NotFound")
|
|
Ok(_) => fail("expected an error")
|
|
}
|
|
}
|
|
|
|
///|
|
|
test "ReadAll filters namespaces, with globs" {
|
|
let p = @portal.SettingsPortal::new(true)
|
|
let want : Array[@network.DValue] = [
|
|
Arr("{sa{sv}}", [
|
|
Entry(
|
|
Str("org.freedesktop.appearance"),
|
|
@network.dict("v", [("color-scheme", Variant(U32(1)))]),
|
|
),
|
|
]),
|
|
]
|
|
let all = fn(pats : Array[String]) {
|
|
p.answer(
|
|
call(@portal.settings_iface, "ReadAll", [Arr("s", pats.map(s => @network.DValue::Str(s)))]),
|
|
)
|
|
}
|
|
assert_eq(all([]), Ok(want))
|
|
assert_eq(all(["org.freedesktop.*"]), Ok(want))
|
|
assert_eq(all(["org.freedesktop.appearance"]), Ok(want))
|
|
assert_eq(all(["org.gnome.*"]), Ok([Arr("{sa{sv}}", [])]))
|
|
}
|
|
|
|
///|
|
|
test "the version property, introspection and unknown methods" {
|
|
let p = @portal.SettingsPortal::new(false)
|
|
assert_eq(
|
|
p.answer(call("org.freedesktop.DBus.Properties", "Get", [Str(@portal.settings_iface), Str("version")])),
|
|
Ok([Variant(U32(2))]),
|
|
)
|
|
assert_eq(
|
|
p.answer(call("org.freedesktop.DBus.Properties", "GetAll", [Str(@portal.settings_iface)])),
|
|
Ok([@network.dict("v", [("version", Variant(U32(2)))])]),
|
|
)
|
|
match p.answer(call("org.freedesktop.DBus.Introspectable", "Introspect", [])) {
|
|
Ok([Str(xml)]) => assert_true(xml.contains("SettingChanged"))
|
|
_ => fail("no introspection")
|
|
}
|
|
assert_true(p.answer(call(@portal.settings_iface, "Frobnicate", [])) is Err(_))
|
|
}
|
|
|
|
///|
|
|
test "namespace patterns" {
|
|
assert_true(@portal.namespace_matches([], "org.freedesktop.appearance"))
|
|
assert_true(@portal.namespace_matches(["org.freedesktop.*"], "org.freedesktop.appearance"))
|
|
assert_false(@portal.namespace_matches(["org.kde.*"], "org.freedesktop.appearance"))
|
|
}
|
|
|
|
///|
|
|
test "no session bus: the backend stays off without errors" {
|
|
let p = @portal.SettingsPortal::new(true, bus_path="/nonexistent/bus")
|
|
p.tick(0UL)
|
|
assert_false(p.connected())
|
|
assert_eq(p.fd(), -1)
|
|
p.set_dark(false) // nothing to tell, no crash
|
|
}
|
|
|
|
///| Run `p`'s backend and `client` until `done` or `ms` pass.
|
|
fn spin(
|
|
p : @portal.SettingsPortal,
|
|
client : @network.DBus,
|
|
ms : Int,
|
|
done : () -> Bool,
|
|
) -> Bool {
|
|
let deadline = @sys.monotonic_ms() + ms.to_uint64()
|
|
while @sys.monotonic_ms() < deadline {
|
|
p.tick(@sys.monotonic_ms())
|
|
client.pump(timeout_ms=10)
|
|
if done() {
|
|
return true
|
|
}
|
|
}
|
|
false
|
|
}
|
|
|
|
///| Against a real session bus and the real xdg-desktop-portal with session/chandra.portal and
|
|
/// session/chandra-portals.conf, as apps see it: org.freedesktop.portal.Settings ReadOne gives our
|
|
/// color-scheme, and flipping the switch reaches apps as SettingChanged. Skipped unless
|
|
/// CHANDRA_PORTAL_E2E=1 (scripts/test-portal-dbus.sh sets it up).
|
|
test "apps read the color-scheme through xdg-desktop-portal, and see it change" {
|
|
if @sys.getenv("CHANDRA_PORTAL_E2E") != "1" {
|
|
return
|
|
}
|
|
let p = @portal.SettingsPortal::new(true)
|
|
p.tick(@sys.monotonic_ms())
|
|
assert_true(p.connected())
|
|
let client = @network.DBus::open(@network.session_bus_path()).unwrap()
|
|
// Listen like Chrome does.
|
|
let changed : Array[@network.DMessage] = []
|
|
client.set_on_signal(fn(m) {
|
|
if m.meth == "SettingChanged" {
|
|
changed.push(m)
|
|
}
|
|
})
|
|
let add_match = @network.DMessage::call(
|
|
"org.freedesktop.DBus",
|
|
"/org/freedesktop/DBus",
|
|
"org.freedesktop.DBus",
|
|
"AddMatch",
|
|
[
|
|
Str(
|
|
"type='signal',interface='org.freedesktop.portal.Settings',member='SettingChanged'",
|
|
),
|
|
],
|
|
)
|
|
ignore(client.call(add_match))
|
|
let read_one = fn() -> @network.DMessage? {
|
|
let got : Ref[@network.DMessage?] = { val: None }
|
|
ignore(
|
|
client.call(
|
|
@network.DMessage::call(
|
|
"org.freedesktop.portal.Desktop",
|
|
"/org/freedesktop/portal/desktop",
|
|
"org.freedesktop.portal.Settings",
|
|
"ReadOne",
|
|
[Str("org.freedesktop.appearance"), Str("color-scheme")],
|
|
),
|
|
on_reply=r => got.val = Some(r),
|
|
),
|
|
)
|
|
// The first call starts xdg-desktop-portal (D-Bus activation), which then asks us.
|
|
ignore(spin(p, client, 15000, () => got.val is Some(_)))
|
|
got.val
|
|
}
|
|
match read_one() {
|
|
Some(m) => {
|
|
assert_eq(m.error_name, "")
|
|
assert_eq(m.body, [Variant(U32(1))])
|
|
}
|
|
None => fail("no answer from xdg-desktop-portal")
|
|
}
|
|
p.set_dark(false)
|
|
assert_true(spin(p, client, 5000, () => changed.length() > 0))
|
|
assert_eq(changed[0].body, [
|
|
Str("org.freedesktop.appearance"),
|
|
Str("color-scheme"),
|
|
Variant(U32(2)),
|
|
])
|
|
match read_one() {
|
|
Some(m) => assert_eq(m.body, [Variant(U32(2))])
|
|
None => fail("no second answer")
|
|
}
|
|
p.close()
|
|
client.close()
|
|
}
|