Skip to content
Snippets Groups Projects
Verified Commit d47d7f60 authored by Sebastian's avatar Sebastian
Browse files

Common abstract base class for Linux and Windows notification providers

parent bb8f7856
No related branches found
No related tags found
No related merge requests found
Pipeline #12894 passed
/*
* 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
import org.briarproject.briar.desktop.utils.InternationalizationUtils.i18nF
import org.briarproject.briar.desktop.utils.InternationalizationUtils.i18nP
abstract class AbstractNotificationProvider : VisualNotificationProvider {
internal abstract fun sendNotification(text: String)
override fun notifyPrivateMessages(num: Int, contacts: Int) = sendNotification(
if (contacts == 1)
i18nP("notifications.message.private.one_chat", num)
else
i18nF("notifications.message.private.several_chats", num, contacts)
)
override fun notifyForumPosts(num: Int, forums: Int) = sendNotification(
if (forums == 1)
i18nP("notifications.message.forum.one_forum", num)
else
i18nF("notifications.message.forum.several_forums", num, forums)
)
}
......@@ -22,14 +22,12 @@ 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.notification.AbstractNotificationProvider
import org.briarproject.briar.desktop.utils.InternationalizationUtils.i18n
import org.briarproject.briar.desktop.utils.InternationalizationUtils.i18nF
import org.briarproject.briar.desktop.utils.InternationalizationUtils.i18nP
import org.briarproject.briar.desktop.utils.KLoggerUtils.e
import org.briarproject.briar.desktop.utils.KLoggerUtils.i
object LibnotifyNotificationProvider : VisualNotificationProvider {
object LibnotifyNotificationProvider : AbstractNotificationProvider() {
private val LOG = KotlinLogging.logger {}
......@@ -82,7 +80,7 @@ object LibnotifyNotificationProvider : VisualNotificationProvider {
}
}
private fun sendNotification(text: String) {
override fun sendNotification(text: String) {
if (!available) return
/**
......@@ -131,20 +129,6 @@ object LibnotifyNotificationProvider : VisualNotificationProvider {
}
}
override fun notifyPrivateMessages(num: Int, contacts: Int) = sendNotification(
if (contacts == 1)
i18nP("notifications.message.private.one_chat", num)
else
i18nF("notifications.message.private.several_chats", num, contacts)
)
override fun notifyForumPosts(num: Int, forums: Int) = sendNotification(
if (forums == 1)
i18nP("notifications.message.forum.one_forum", num)
else
i18nF("notifications.message.forum.several_forums", num, forums)
)
/**
* Functions as defined in the source code at
* https://www.freedesktop.org/software/gstreamer-sdk/data/docs/latest/glib/glib-GVariant.html
......
......@@ -23,13 +23,11 @@ import de.mobanisto.toast4j.Toaster
import de.mobanisto.wintoast.WinToastTemplate.WinToastTemplateType
import mu.KotlinLogging
import org.briarproject.briar.desktop.BuildData
import org.briarproject.briar.desktop.notification.VisualNotificationProvider
import org.briarproject.briar.desktop.notification.AbstractNotificationProvider
import org.briarproject.briar.desktop.utils.InternationalizationUtils.i18n
import org.briarproject.briar.desktop.utils.InternationalizationUtils.i18nF
import org.briarproject.briar.desktop.utils.InternationalizationUtils.i18nP
import org.briarproject.briar.desktop.utils.KLoggerUtils.e
object Toast4jNotificationProvider : VisualNotificationProvider {
object Toast4jNotificationProvider : AbstractNotificationProvider() {
private val LOG = KotlinLogging.logger {}
......@@ -62,27 +60,13 @@ object Toast4jNotificationProvider : VisualNotificationProvider {
currentToast?.hide()
}
var currentToast: ToastHandle? = null
private var currentToast: ToastHandle? = null
private fun sendNotification(text: String) {
override fun sendNotification(text: String) {
currentToast?.hide()
currentToast = toaster.showToast(
ToastBuilder(WinToastTemplateType.ToastText01).setSilent()
.setLine1(text).build()
)
}
override fun notifyPrivateMessages(num: Int, contacts: Int) = sendNotification(
if (contacts == 1)
i18nP("notifications.message.private.one_chat", num)
else
i18nF("notifications.message.private.several_chats", num, contacts)
)
override fun notifyForumPosts(num: Int, forums: Int) = sendNotification(
if (forums == 1)
i18nP("notifications.message.forum.one_forum", num)
else
i18nF("notifications.message.forum.several_forums", num, forums)
)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment