diff --git a/briar-desktop/build.gradle.kts b/briar-desktop/build.gradle.kts index e2ae578a9e241acc9a51877de0a8848254072bab..7003c3d9ba2710e950d090aba19e7fda674602c9 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 5c6ad92b29ad9b91eba23ada3efbb8b4ba47471f..65623e4bfebcd0d708158c41d4d9a250610d1be4 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 8dac0004af6cae62abc8c84b719c7ac57ac0878d..40f19e0f385f82727a5c6e354fda1040592f7c0b 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 c04b5b00d169af7eead34ae0345219003898226f..83e833d1361f16e0294805a80b6ba4e6aeb02ee2 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() }