Fix notifications: GNOME needs a desktop file it can resolve
This commit is contained in:
4 files changed
+209
-27
No files matched your search
+50
-9
@@ -104,6 +104,40 @@ PASSPHRASE_FILE="$TMP_HOME/passphrase"
|
||||
printf '%s' "$PASSPHRASE" >"$PASSPHRASE_FILE"
|
||||
chmod 600 "$PASSPHRASE_FILE"
|
||||
|
||||
printf '\n== the desktop file GNOME has to find ==\n'
|
||||
# GIO validates `Exec` while parsing a desktop file and drops the whole file when
|
||||
# the program cannot be found. GNOME Shell then cannot resolve the app and
|
||||
# refuses every notification from it — and GLib's gtk backend discards that
|
||||
# error, so the only symptom is silence. Install the shipped file the way
|
||||
# `regent-deploy` does, and prove GIO indexes it.
|
||||
APPS_DIR="$HOME/.local/share/applications"
|
||||
mkdir -p "$APPS_DIR"
|
||||
sed "s|^Exec=regent|Exec=$ROOT/$BUILD/regent|" \
|
||||
"$ROOT/data/$DATA_DIR.desktop" > "$APPS_DIR/$DATA_DIR.desktop"
|
||||
|
||||
python3 - "$DATA_DIR.desktop" <<'PY'
|
||||
import sys
|
||||
from gi.repository import Gio
|
||||
wanted = sys.argv[1]
|
||||
assert any(app.get_id() == wanted for app in Gio.AppInfo.get_all()), \
|
||||
"GIO does not index {}".format(wanted)
|
||||
PY
|
||||
check $? "GIO indexes the installed desktop file"
|
||||
|
||||
# The failure this guards against: an Exec that does not resolve is dropped
|
||||
# entirely, which is exactly how notifications went missing.
|
||||
sed "s|^Exec=.*|Exec=/nonexistent/regent|" \
|
||||
"$ROOT/data/$DATA_DIR.desktop" > "$APPS_DIR/$DATA_DIR.broken.desktop"
|
||||
python3 - "$DATA_DIR.broken.desktop" <<'PY'
|
||||
import sys
|
||||
from gi.repository import Gio
|
||||
wanted = sys.argv[1]
|
||||
assert not any(app.get_id() == wanted for app in Gio.AppInfo.get_all()), \
|
||||
"GIO indexed a desktop file whose Exec does not resolve"
|
||||
PY
|
||||
check $? "a desktop file with an unresolvable Exec is dropped"
|
||||
rm -f "$APPS_DIR/$DATA_DIR.broken.desktop"
|
||||
|
||||
# An already-approved client, so a request can reach a prompt without pairing:
|
||||
# the pairing secret is deliberately never logged, and the in-app pairing flow
|
||||
# would need a click. The client is bound to the seeded identity and has no
|
||||
@@ -149,6 +183,12 @@ check $? "the app started the signer ($(grep -m1 'signer listening' "$TMP_HOME/a
|
||||
grep -q '"device"' "$VAULT"
|
||||
check $? "a device key was created in the vault"
|
||||
|
||||
# The startup check must be satisfied: a desktop file GNOME cannot resolve means
|
||||
# it refuses every notification, so the app says so and this proves it does not
|
||||
# have to.
|
||||
! grep -q 'cannot resolve' "$TMP_HOME/app.log"
|
||||
check $? "the app does not warn that GNOME cannot find it"
|
||||
|
||||
printf '\n== notifications ==\n'
|
||||
# `REGENT_NOTIFY_ALWAYS` makes the app treat the window as away: Broadway has no
|
||||
# window manager, so `is_active()` is true even when nothing is focused.
|
||||
@@ -164,20 +204,21 @@ nak event --sec "$NOTIFY_CLIENT_SEC" -k 24133 -p "$DEVICE_HEX" -c "$CIPHERTEXT"
|
||||
"ws://127.0.0.1:$PORT" >/dev/null 2>&1
|
||||
sleep 3
|
||||
|
||||
grep -qF 'summary=Regent' "$NOTIFY_LOG"
|
||||
check $? "a waiting prompt raises a notification"
|
||||
grep -qF 'AddNotification app=org.kosmos.raucao.Regent' "$NOTIFY_LOG"
|
||||
check $? "a waiting prompt raises a notification on the gtk path GNOME uses"
|
||||
|
||||
grep -qF 'body=An application is asking for a signature' "$NOTIFY_LOG"
|
||||
grep -qF 'title=Regent' "$NOTIFY_LOG" &&
|
||||
grep -qF 'body=An application is asking for a signature' "$NOTIFY_LOG"
|
||||
check $? "the notification names the request and nothing about the client"
|
||||
|
||||
grep -qF 'hints=desktop-entry:org.kosmos.raucao.Regent' "$NOTIFY_LOG"
|
||||
check $? "the notification is attributed to Regent"
|
||||
|
||||
grep -qF 'urgency:1' "$NOTIFY_LOG"
|
||||
grep -qF 'priority=high' "$NOTIFY_LOG"
|
||||
check $? "the notification is high priority"
|
||||
|
||||
grep -qF 'actions=default' "$NOTIFY_LOG"
|
||||
check $? "clicking the notification has a default action"
|
||||
grep -qF 'icon=yes' "$NOTIFY_LOG"
|
||||
check $? "the notification carries Regent's icon"
|
||||
|
||||
grep -qF 'default-action=app.focus' "$NOTIFY_LOG"
|
||||
check $? "clicking the notification activates app.focus"
|
||||
|
||||
grep -q 'regent: bringing the window to the front' "$TMP_HOME/app.log"
|
||||
check $? "clicking the notification brings the window to the front"
|
||||
|
||||
+89
-18
@@ -1,13 +1,23 @@
|
||||
#!/usr/bin/env python3
|
||||
"""A stub `org.freedesktop.Notifications`, for the acceptance test only.
|
||||
"""A stub notification daemon, for the acceptance test only.
|
||||
|
||||
GLib's `GApplication::send_notification` talks the freedesktop interface
|
||||
directly, so owning the name is enough to observe what Regent would put on
|
||||
screen. Every call is appended to `$NOTIFY_LOG` as one `key=value` line, and
|
||||
when `NOTIFY_ACTION_ID=1` a click is simulated by emitting `ActionInvoked`
|
||||
shortly after each `Notify` — which is exactly what GNOME Shell does when the
|
||||
body of a notification is clicked, and what makes GLib activate the app's
|
||||
default action.
|
||||
GLib picks its notification backend by priority, and the choice changes what is
|
||||
on the wire:
|
||||
|
||||
* `org.gtk.Notifications` (priority 100) is used whenever that name is owned —
|
||||
which is the case on any real GNOME session, where GNOME Shell provides it.
|
||||
The payload is `AddNotification(app_id, id, a{sv})`, and GNOME Shell refuses
|
||||
it outright unless it can resolve `<app_id>.desktop` in its app index.
|
||||
* `org.freedesktop.Notifications` (priority 0) is the fallback, used when
|
||||
nothing owns the gtk name. The payload is the classic `Notify(...)`, and the
|
||||
shell shows it even for an app it does not know.
|
||||
|
||||
This stub owns **both**, so GLib takes the gtk path — the one that matters on the
|
||||
machine Regent actually runs on. Every call is appended to `$NOTIFY_LOG`, and
|
||||
when `NOTIFY_ACTION_ID=1` a click is simulated the way each backend expects:
|
||||
`ActivateAction("focus")` on the app for the gtk path (what GNOME Shell does),
|
||||
and an `ActionInvoked` signal for the freedesktop one (which GLib maps back to
|
||||
the app's default action in-process).
|
||||
|
||||
Not a Regent dependency: it exists so the notification path has a test.
|
||||
"""
|
||||
@@ -23,10 +33,8 @@ LOG = os.environ["NOTIFY_LOG"]
|
||||
CLICK = os.environ.get("NOTIFY_ACTION_ID") == "1"
|
||||
|
||||
|
||||
class Notifications(dbus.service.Object):
|
||||
def __init__(self, bus):
|
||||
super().__init__(bus, "/org/freedesktop/Notifications")
|
||||
self.next_id = 1
|
||||
class Stub:
|
||||
"""Logging and click simulation, shared by both interfaces."""
|
||||
|
||||
def log(self, line):
|
||||
with open(LOG, "a") as handle:
|
||||
@@ -40,6 +48,66 @@ class Notifications(dbus.service.Object):
|
||||
return str(int(value))
|
||||
return str(value)
|
||||
|
||||
def activate_app(self, app_id):
|
||||
"""The gtk path's click: GNOME Shell activates the app's action."""
|
||||
if not CLICK:
|
||||
return
|
||||
GLib.timeout_add(700, self._activate_app, app_id)
|
||||
|
||||
def _activate_app(self, app_id):
|
||||
try:
|
||||
self.bus.call_blocking(
|
||||
app_id,
|
||||
"/" + app_id.replace(".", "/"),
|
||||
"org.freedesktop.Application",
|
||||
"ActivateAction",
|
||||
"sava{sv}",
|
||||
("focus", [], {}),
|
||||
timeout=3,
|
||||
)
|
||||
except Exception as error: # a test helper logs and moves on
|
||||
self.log("ActivateAction failed: {}".format(error))
|
||||
return False
|
||||
|
||||
|
||||
class GtkNotifications(Stub, dbus.service.Object):
|
||||
"""`org.gtk.Notifications`, at `/org/gtk/Notifications`."""
|
||||
|
||||
def __init__(self, bus):
|
||||
super().__init__(bus, "/org/gtk/Notifications")
|
||||
self.bus = bus
|
||||
|
||||
@dbus.service.method(
|
||||
"org.gtk.Notifications", in_signature="ssa{sv}", out_signature=""
|
||||
)
|
||||
def AddNotification(self, app_id, notification_id, notification):
|
||||
self.log(
|
||||
"AddNotification app={} id={} title={} body={} priority={} "
|
||||
"default-action={} icon={}".format(
|
||||
app_id,
|
||||
notification_id,
|
||||
notification.get("title", ""),
|
||||
notification.get("body", ""),
|
||||
notification.get("priority", "(normal)"),
|
||||
notification.get("default-action", ""),
|
||||
"yes" if "icon" in notification else "no",
|
||||
)
|
||||
)
|
||||
self.activate_app(str(app_id))
|
||||
|
||||
@dbus.service.method("org.gtk.Notifications", in_signature="ss", out_signature="")
|
||||
def RemoveNotification(self, app_id, notification_id):
|
||||
self.log("RemoveNotification app={} id={}".format(app_id, notification_id))
|
||||
|
||||
|
||||
class FdoNotifications(Stub, dbus.service.Object):
|
||||
"""`org.freedesktop.Notifications`, at `/org/freedesktop/Notifications`."""
|
||||
|
||||
def __init__(self, bus):
|
||||
super().__init__(bus, "/org/freedesktop/Notifications")
|
||||
self.bus = bus
|
||||
self.next_id = 1
|
||||
|
||||
@dbus.service.method(
|
||||
"org.freedesktop.Notifications",
|
||||
in_signature="susssasa{sv}i",
|
||||
@@ -59,10 +127,11 @@ class Notifications(dbus.service.Object):
|
||||
)
|
||||
)
|
||||
if CLICK:
|
||||
GLib.timeout_add(700, self._click, notify_id)
|
||||
GLib.timeout_add(700, self._invoke_default, notify_id)
|
||||
return dbus.UInt32(notify_id)
|
||||
|
||||
def _click(self, notify_id):
|
||||
def _invoke_default(self, notify_id):
|
||||
# GLib maps this back to the app's default action in-process.
|
||||
self.ActionInvoked(dbus.UInt32(notify_id), "default")
|
||||
return False
|
||||
|
||||
@@ -92,10 +161,12 @@ def main():
|
||||
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
|
||||
bus = dbus.SessionBus()
|
||||
loop = GLib.MainLoop()
|
||||
# Keep both alive: dbus-python releases the name when the BusName object is
|
||||
# collected, and unregisters the object when it is.
|
||||
loop.bus_name = dbus.service.BusName("org.freedesktop.Notifications", bus)
|
||||
loop.server = Notifications(bus)
|
||||
# Keep every one of these alive: dbus-python releases a name when its
|
||||
# BusName object is collected, and unregisters an object when it is.
|
||||
loop.gtk_name = dbus.service.BusName("org.gtk.Notifications", bus)
|
||||
loop.fdo_name = dbus.service.BusName("org.freedesktop.Notifications", bus)
|
||||
loop.gtk = GtkNotifications(bus)
|
||||
loop.fdo = FdoNotifications(bus)
|
||||
loop.run()
|
||||
|
||||
|
||||
|
||||
@@ -16,10 +16,51 @@ set -euo pipefail
|
||||
HOST=${REGENT_BUILD_HOST:-nuc-zt}
|
||||
REPO=${REGENT_REPO_PATH:-'~/src/regent'}
|
||||
REMOTE="$REPO/build-aux/deploy-dev.sh"
|
||||
APP_ID=org.kosmos.raucao.Regent
|
||||
|
||||
say() { printf 'regent-deploy: %s\n' "$*"; }
|
||||
die() { printf 'regent-deploy: %s\n' "$*" >&2; exit 1; }
|
||||
|
||||
# The staged tree is rooted at /usr, so its desktop file says `Exec=regent`. That
|
||||
# is right for a system install — /usr/bin is on the session's PATH — but wrong
|
||||
# for this one: the binary just landed in ~/.local/bin, which a GNOME session
|
||||
# does not have on its PATH (a systemd user session's PATH is typically
|
||||
# /usr/local/bin:/usr/bin).
|
||||
#
|
||||
# GIO validates `Exec` while parsing a desktop file and drops the whole file when
|
||||
# the program cannot be found, so the shell never learns the app exists and
|
||||
# refuses every notification from it with `InvalidApp`. GLib's
|
||||
# org.gtk.Notifications backend discards that error, so nothing is logged: the
|
||||
# only symptom is that notifications never appear. Point the installed copy at
|
||||
# the absolute path instead.
|
||||
fix_desktop_file() {
|
||||
local desktop="$HOME/.local/share/applications/$APP_ID.desktop"
|
||||
[ -f "$desktop" ] || return 0
|
||||
[ -x "$HOME/.local/bin/regent" ] || return 0
|
||||
|
||||
sed -i "s|^Exec=regent|Exec=$HOME/.local/bin/regent|" "$desktop"
|
||||
}
|
||||
|
||||
# Prove the shell can actually find the app, rather than shipping a desktop file
|
||||
# that is silently ignored.
|
||||
check_desktop_file() {
|
||||
command -v python3 >/dev/null 2>&1 || return 0
|
||||
python3 -c 'import gi' 2>/dev/null || return 0
|
||||
|
||||
if python3 - "$APP_ID.desktop" <<'PY'
|
||||
import sys
|
||||
from gi.repository import Gio
|
||||
wanted = sys.argv[1]
|
||||
sys.exit(0 if any(app.get_id() == wanted for app in Gio.AppInfo.get_all()) else 1)
|
||||
PY
|
||||
then
|
||||
say "GNOME can resolve $APP_ID.desktop"
|
||||
else
|
||||
say "WARNING: GNOME cannot resolve $APP_ID.desktop, so it will not show notifications" >&2
|
||||
say " its Exec must resolve on the session's PATH; see the desktop file" >&2
|
||||
fi
|
||||
}
|
||||
|
||||
command -v ssh >/dev/null || die "ssh not found"
|
||||
command -v pkg-config >/dev/null || die "pkg-config not found"
|
||||
command -v tar >/dev/null || die "tar not found"
|
||||
@@ -53,6 +94,8 @@ else
|
||||
ssh "$HOST" "$REMOTE --emit" | tar -x --zstd -C "$HOME/.local"
|
||||
glib-compile-schemas "$HOME/.local/share/glib-2.0/schemas"
|
||||
update-desktop-database "$HOME/.local/share/applications" >/dev/null 2>&1 || true
|
||||
fix_desktop_file
|
||||
check_desktop_file
|
||||
fi
|
||||
|
||||
if [ -x "$HOME/.local/bin/regent" ]; then
|
||||
|
||||
@@ -26,6 +26,8 @@ pub fn run() -> glib::ExitCode {
|
||||
// same registry and signer.
|
||||
let state = AppState::new();
|
||||
|
||||
warn_if_the_desktop_is_missing();
|
||||
|
||||
// Lock or unlock the key vault. Unlocking asks for the passphrase; a locked
|
||||
// vault fails closed, so this never signs anything. The user is present (they
|
||||
// just clicked), so the dialog has no deadline.
|
||||
@@ -98,6 +100,31 @@ pub fn run() -> glib::ExitCode {
|
||||
app.run_with_args::<&str>(&[])
|
||||
}
|
||||
|
||||
/// Warn once if the desktop cannot find this installation's desktop file.
|
||||
///
|
||||
/// GNOME Shell refuses a notification whose app id is not in its app index, and
|
||||
/// GLib's `org.gtk.Notifications` backend **discards that error** — so a desktop
|
||||
/// file GIO will not parse means notifications never appear and nothing is ever
|
||||
/// logged. GIO drops a desktop file whose `Exec` does not resolve, which is the
|
||||
/// usual cause for a `~/.local` install: a session's PATH has no `~/.local/bin`.
|
||||
/// This is the only place that failure can be made visible.
|
||||
fn warn_if_the_desktop_is_missing() {
|
||||
let wanted = format!("{APP_ID}.desktop");
|
||||
let resolvable = gio::AppInfo::all()
|
||||
.iter()
|
||||
.any(|app| app.id().is_some_and(|id| id.as_str() == wanted.as_str()));
|
||||
|
||||
if !resolvable {
|
||||
eprintln!(
|
||||
"regent: warning: GNOME cannot resolve {wanted}, so it will not show \
|
||||
notifications from this app. Install it where the session looks for \
|
||||
applications, with an `Exec` that resolves on the session's PATH (a run \
|
||||
from the build directory is expected to warn; `regent-deploy` fixes a \
|
||||
~/.local install)."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn load_css() {
|
||||
let provider = gtk::CssProvider::new();
|
||||
provider.load_from_resource(&format!("{RESOURCE_PATH}/style.css"));
|
||||
|
||||
Reference in new issue
Block a user