Add debug command

This commit is contained in:
Benedikt Heine 2019-08-12 20:47:13 +02:00 committed by Nikos Tsipinakis
parent e80e8e9eb5
commit a3342d0ced
2 changed files with 30 additions and 0 deletions

View File

@ -20,6 +20,7 @@ function show_help() {
history-pop Pop one notification from history history-pop Pop one notification from history
status Check if status Check if
status-set [true|false] Set the status status-set [true|false] Set the status
debug Print debugging information
help Show this help help Show this help
EOH EOH
} }
@ -66,6 +67,21 @@ case "${1:-}" in
"help"|"--help"|"-h") "help"|"--help"|"-h")
show_help show_help
;; ;;
"debug")
dbus-send --print-reply=literal --dest="${DBUS_NAME}" "${DBUS_PATH}" "${DBUS_IFAC_FDN}.GetServerInformation" >/dev/null 2>/dev/null \
|| die "Dunst is not running."
dbus-send --print-reply=literal --dest="${DBUS_NAME}" "${DBUS_PATH}" "${DBUS_IFAC_FDN}.GetServerInformation" \
| (
read name vendor version protocol_version
[ "${name}" == dunst ]
printf "dunst version: %s\n" "${version}"
) \
|| die "Another notification manager is running. It's not dunst"
dbus-send --print-reply=literal --dest="${DBUS_NAME}" "${DBUS_PATH}" "${DBUS_IFAC_DUNST}.Ping" >/dev/null 2>/dev/null \
|| die "Dunst controlling interface not available. Is the version too old?"
;;
"") "")
die "dunstctl: No command specified. Please consult the usage." die "dunstctl: No command specified. Please consult the usage."
;; ;;

View File

@ -76,6 +76,7 @@ static const char *introspection_xml =
" <method name=\"NotificationCloseLast\" />" " <method name=\"NotificationCloseLast\" />"
" <method name=\"NotificationCloseAll\" />" " <method name=\"NotificationCloseAll\" />"
" <method name=\"NotificationShow\" />" " <method name=\"NotificationShow\" />"
" <method name=\"Ping\" />"
" <property name=\"running\" type=\"b\" access=\"readwrite\">" " <property name=\"running\" type=\"b\" access=\"readwrite\">"
" <annotation name=\"org.freedesktop.DBus.Property.EmitsChangedSignal\" value=\"true\"/>" " <annotation name=\"org.freedesktop.DBus.Property.EmitsChangedSignal\" value=\"true\"/>"
@ -154,11 +155,13 @@ DBUS_METHOD(dunst_ContextMenuCall);
DBUS_METHOD(dunst_NotificationCloseAll); DBUS_METHOD(dunst_NotificationCloseAll);
DBUS_METHOD(dunst_NotificationCloseLast); DBUS_METHOD(dunst_NotificationCloseLast);
DBUS_METHOD(dunst_NotificationShow); DBUS_METHOD(dunst_NotificationShow);
DBUS_METHOD(dunst_Ping);
static struct dbus_method methods_dunst[] = { static struct dbus_method methods_dunst[] = {
{"ContextMenuCall", dbus_cb_dunst_ContextMenuCall}, {"ContextMenuCall", dbus_cb_dunst_ContextMenuCall},
{"NotificationCloseAll", dbus_cb_dunst_NotificationCloseAll}, {"NotificationCloseAll", dbus_cb_dunst_NotificationCloseAll},
{"NotificationCloseLast", dbus_cb_dunst_NotificationCloseLast}, {"NotificationCloseLast", dbus_cb_dunst_NotificationCloseLast},
{"NotificationShow", dbus_cb_dunst_NotificationShow}, {"NotificationShow", dbus_cb_dunst_NotificationShow},
{"Ping", dbus_cb_dunst_Ping},
}; };
void dbus_cb_dunst_methods(GDBusConnection *connection, void dbus_cb_dunst_methods(GDBusConnection *connection,
@ -241,6 +244,17 @@ static void dbus_cb_dunst_NotificationShow(GDBusConnection *connection,
g_dbus_connection_flush(connection, NULL, NULL, NULL); g_dbus_connection_flush(connection, NULL, NULL, NULL);
} }
/* Just a simple Ping command to give the ability to dunstctl to test for the existence of this interface
* Any other way requires parsing the XML of the Introspection or other foo. Just calling the Ping on an old dunst version will fail. */
static void dbus_cb_dunst_Ping(GDBusConnection *connection,
const gchar *sender,
GVariant *parameters,
GDBusMethodInvocation *invocation)
{
g_dbus_method_invocation_return_value(invocation, NULL);
g_dbus_connection_flush(connection, NULL, NULL, NULL);
}
static void dbus_cb_GetCapabilities( static void dbus_cb_GetCapabilities(
GDBusConnection *connection, GDBusConnection *connection,