From 081386911c65aa7759abd98583d52a83dcc3bbda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20K=C3=BCrten?= <sebastian@mobanisto.de> Date: Thu, 1 Sep 2022 12:20:07 +0200 Subject: [PATCH] add Gradle task to build notification test as separate jar --- briar-desktop/build.gradle.kts | 24 +++++++++++++++++++ .../linux/LibnotifyNotificationProvider.kt | 2 +- .../briar/desktop/utils/AudioUtils.kt | 4 +++- .../linux/TestNativeNotifications.kt | 9 +++++-- 4 files changed, 35 insertions(+), 4 deletions(-) rename briar-desktop/src/{main => test}/kotlin/org/briarproject/briar/desktop/notification/linux/TestNativeNotifications.kt (78%) diff --git a/briar-desktop/build.gradle.kts b/briar-desktop/build.gradle.kts index e2ae578a9e..7003c3d9ba 100644 --- a/briar-desktop/build.gradle.kts +++ b/briar-desktop/build.gradle.kts @@ -123,3 +123,27 @@ compose.desktop { } } } + +tasks.register<Jar>("notificationTest") { + dependsOn.addAll( + listOf( + "compileJava", + "compileKotlin", + "processResources" + ) + ) // We need this for Gradle optimization to work + archiveClassifier.set("notificationTest") // Naming the jar + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + manifest { + attributes("Main-Class" to "org.briarproject.briar.desktop.notification.linux.TestNativeNotificationsKt") + } // Provided we set it up in the application plugin configuration + val sourcesTest = sourceSets.test.get() + val contents = configurations.runtimeClasspath.get() + .map { if (it.isDirectory) it else zipTree(it) } + from(contents) + // add normal jar outputs + with(tasks["jar"] as CopySpec) + // add testing output, too + from(sourceSets["test"].output) + from(sourceSets["main"].output) +} 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 5c6ad92b29..65623e4bfe 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 @@ -150,7 +150,7 @@ object LibnotifyNotificationProvider : NotificationProvider { LOG.e { "error while sending notification via libnotify" } } - sound.play() + if (soundAvailable) sound.play() } /** diff --git a/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/utils/AudioUtils.kt b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/utils/AudioUtils.kt index 8dac0004af..40f19e0f38 100644 --- a/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/utils/AudioUtils.kt +++ b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/utils/AudioUtils.kt @@ -19,6 +19,7 @@ package org.briarproject.briar.desktop.utils import org.briarproject.briar.desktop.utils.ResourceUtils.getResourceAsStream +import java.io.BufferedInputStream import javax.sound.sampled.AudioSystem import javax.sound.sampled.Clip @@ -26,7 +27,8 @@ object AudioUtils { fun loadAudioFromResource(name: String): Clip? { val resourceStream = getResourceAsStream(name) ?: return null - val audioInputStream = AudioSystem.getAudioInputStream(resourceStream) + val bufferedStream = BufferedInputStream(resourceStream) // add buffer for mark/reset support + val audioInputStream = AudioSystem.getAudioInputStream(bufferedStream) val sound = AudioSystem.getClip() sound.open(audioInputStream) return sound diff --git a/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/notification/linux/TestNativeNotifications.kt b/briar-desktop/src/test/kotlin/org/briarproject/briar/desktop/notification/linux/TestNativeNotifications.kt similarity index 78% rename from briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/notification/linux/TestNativeNotifications.kt rename to briar-desktop/src/test/kotlin/org/briarproject/briar/desktop/notification/linux/TestNativeNotifications.kt index c04b5b00d1..83e833d136 100644 --- a/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/notification/linux/TestNativeNotifications.kt +++ b/briar-desktop/src/test/kotlin/org/briarproject/briar/desktop/notification/linux/TestNativeNotifications.kt @@ -17,15 +17,20 @@ */ package org.briarproject.briar.desktop.notification.linux +/** + * Small program to test notification support for Linux. + * Build with ./gradlew briar-desktop:notificationTest + * and run as java -jar briar-desktop/build/libs/briar-desktop-*-notificationTest.jar + */ fun main() { LibnotifyNotificationProvider.apply { init() notifyPrivateMessages(9) - - Thread.sleep(100) + Thread.sleep(1000) notifyPrivateMessages(10) + Thread.sleep(1000) uninit() } -- GitLab