From 8de44d4398285f52d1c060ac168763f34e88fe87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20K=C3=BCrten?= <sebastian@mobanisto.de> Date: Wed, 7 Sep 2022 09:51:27 +0200 Subject: [PATCH] Get errors back from libnotify --- .../notification/linux/GErrorStruct.kt | 45 +++++++++++++++++++ .../linux/LibnotifyNotificationProvider.kt | 9 ++-- 2 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/notification/linux/GErrorStruct.kt diff --git a/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/notification/linux/GErrorStruct.kt b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/notification/linux/GErrorStruct.kt new file mode 100644 index 0000000000..95356744fa --- /dev/null +++ b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/notification/linux/GErrorStruct.kt @@ -0,0 +1,45 @@ +/* + * Briar Desktop + * Copyright (C) 2021-2022 The Briar Project + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ +package org.briarproject.briar.desktop.notification.linux + +import com.sun.jna.Pointer +import com.sun.jna.Structure +import com.sun.jna.Structure.FieldOrder + +@FieldOrder("domain", "code", "message") // NON-NLS +class GErrorStruct : Structure { + @JvmField + @Volatile + var domain /* GQuark */ = 0 + + @JvmField + @Volatile + var code = 0 + + @JvmField + @Volatile + var message: String? = null + + constructor() { + clear() + } + + constructor(ptr: Pointer?) : super(ptr) { + read() + } +} diff --git a/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/notification/linux/LibnotifyNotificationProvider.kt b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/notification/linux/LibnotifyNotificationProvider.kt index 3a0c44f4e0..5527fa230c 100644 --- a/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/notification/linux/LibnotifyNotificationProvider.kt +++ b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/notification/linux/LibnotifyNotificationProvider.kt @@ -20,6 +20,7 @@ package org.briarproject.briar.desktop.notification.linux import com.sun.jna.Library import com.sun.jna.Native import com.sun.jna.Pointer +import com.sun.jna.ptr.PointerByReference import mu.KotlinLogging import org.briarproject.briar.desktop.notification.VisualNotificationProvider import org.briarproject.briar.desktop.utils.InternationalizationUtils.i18n @@ -126,9 +127,11 @@ object LibnotifyNotificationProvider : VisualNotificationProvider { */ libNotify.notify_notification_set_category(notification, "im.received") - if (!libNotify.notify_notification_show(notification, null)) { - // todo: error handling + val errorPointer = PointerByReference() + if (!libNotify.notify_notification_show(notification, errorPointer)) { LOG.e { "error while sending notification via libnotify" } + val error = GErrorStruct(errorPointer.value) + LOG.e { "error code: ${error.code}, message: '${error.message}'" } } } @@ -210,7 +213,7 @@ object LibnotifyNotificationProvider : VisualNotificationProvider { * * @return true if successful. On error, this will return false and set [error]. */ - fun notify_notification_show(notification: Pointer, error: Pointer?): Boolean + fun notify_notification_show(notification: Pointer, error: PointerByReference?): Boolean /** * Sets a hint for [key] with value [value]. If [value] is null, -- GitLab