aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Tari <robert@tari.in>2023-11-22 21:28:00 +0100
committerRobert Tari <robert@tari.in>2023-11-28 20:33:25 +0100
commita87ed3b20459a9f067718e0212306008f2dfdaef (patch)
treec35fb032ebcfc90658c863164d55e7bc9a20a48a
parent3e8aab9eaf85ec528d6a0465a162c017934b3b5d (diff)
downloadayatana-indicator-sound-a87ed3b20459a9f067718e0212306008f2dfdaef.tar.gz
ayatana-indicator-sound-a87ed3b20459a9f067718e0212306008f2dfdaef.tar.bz2
ayatana-indicator-sound-a87ed3b20459a9f067718e0212306008f2dfdaef.zip
Use different code path for Lomiri notifications
-rwxr-xr-x[-rw-r--r--]src/info-notification.vala47
-rw-r--r--src/warn-notification.vala5
-rw-r--r--tests/integration/indicator-sound-test-base.cpp8
-rw-r--r--tests/notifications-mock.h2
-rw-r--r--tests/notifications-test.cc8
5 files changed, 50 insertions, 20 deletions
diff --git a/src/info-notification.vala b/src/info-notification.vala
index 5e67be1..3915ebb 100644..100755
--- a/src/info-notification.vala
+++ b/src/info-notification.vala
@@ -25,10 +25,12 @@ public class IndicatorSound.InfoNotification: Notification
{
private string sReaderSchema = "org.gnome.desktop.a11y.applications";
private string sReaderKey = "screen-reader-enabled";
+ private bool bHints = false;
protected override Notify.Notification create_notification ()
{
string sUser = GLib.Environment.get_user_name ();
+ this.bHints = notify_server_supports ("x-lomiri-private-synchronous");
if (sUser == "lightdm")
{
@@ -39,6 +41,7 @@ public class IndicatorSound.InfoNotification: Notification
return new Notify.Notification (_("Volume"), "", "audio-volume-muted");
}
+
public void show (VolumeControl.ActiveOutput active_output,
double volume,
bool is_high_volume) {
@@ -51,37 +54,45 @@ public class IndicatorSound.InfoNotification: Notification
/* Reset the notification */
var n = _notification;
- volume_label += "\n";
int32 nValue = ((int32)((volume * 100.0) + 0.5)).clamp(0, 100);
- SettingsSchemaSource pSource = SettingsSchemaSource.get_default ();
- SettingsSchema pSchema = pSource.lookup (this.sReaderSchema, false);
- bool bOrcaActive = false;
- if (pSchema != null)
+ if (!this.bHints)
{
- Settings pSettings = new Settings (this.sReaderSchema);
- bOrcaActive = pSettings.get_boolean (this.sReaderKey);
- }
+ volume_label += "\n";
+ SettingsSchemaSource pSource = SettingsSchemaSource.get_default ();
+ SettingsSchema pSchema = pSource.lookup (this.sReaderSchema, false);
+ bool bOrcaActive = false;
- if (bOrcaActive)
- {
- string sValue = nValue.to_string ();
- volume_label += sValue + "%";
- }
- else
- {
- uint nChars = ((int32)((volume * 20) + 0.5)).clamp(0, 20);
+ if (pSchema != null)
+ {
+ Settings pSettings = new Settings (this.sReaderSchema);
+ bOrcaActive = pSettings.get_boolean (this.sReaderKey);
+ }
- for (uint nChar = 0; nChar < nChars; nChar++)
+ if (bOrcaActive)
{
- volume_label += "◼";
+ string sValue = nValue.to_string ();
+ volume_label += sValue + "%";
+ }
+ else
+ {
+ uint nChars = ((int32)((volume * 20) + 0.5)).clamp(0, 20);
+
+ for (uint nChar = 0; nChar < nChars; nChar++)
+ {
+ volume_label += "◼";
+ }
}
}
n.update (_("Volume"), volume_label, icon);
n.clear_hints();
+ n.set_hint ("x-lomiri-non-shaped-icon", "true");
+ n.set_hint ("x-lomiri-private-synchronous", "true");
+ n.set_hint ("x-lomiri-value-bar-tint", is_high_volume ? "true" : "false");
n.set_hint ("value", nValue);
+
show_notification ();
}
diff --git a/src/warn-notification.vala b/src/warn-notification.vala
index 203758e..ae19571 100644
--- a/src/warn-notification.vala
+++ b/src/warn-notification.vala
@@ -33,6 +33,11 @@ public class IndicatorSound.WarnNotification: Notification
_("Volume"),
_("Allow volume above safe level?\nHigh volume can damage your hearing."),
"audio-volume-high");
+
+ n.set_hint ("x-lomiri-non-shaped-icon", "true");
+ n.set_hint ("x-lomiri-snap-decisions", "true");
+ n.set_hint ("x-lomiri-private-affirmative-tint", "true");
+
n.closed.connect ((n) => {
n.clear_actions ();
});
diff --git a/tests/integration/indicator-sound-test-base.cpp b/tests/integration/indicator-sound-test-base.cpp
index eb4ee8c..bec21b4 100644
--- a/tests/integration/indicator-sound-test-base.cpp
+++ b/tests/integration/indicator-sound-test-base.cpp
@@ -72,7 +72,7 @@ void IndicatorSoundTestBase::SetUp()
"GetCapabilities",
"",
"as",
- "ret = ['actions', 'body', 'body-markup', 'icon-static', 'image/svg+xml', 'private-synchronous', 'append', 'private-icon-only', 'truncation']"
+ "ret = ['actions', 'body', 'body-markup', 'icon-static', 'image/svg+xml', 'x-lomiri-private-synchronous', 'x-lomiri-private-icon-only', 'x-lomiri-truncation', 'private-synchronous', 'append', 'private-icon-only', 'truncation']"
).waitForFinished();
int waitedTime = 0;
@@ -647,8 +647,14 @@ void IndicatorSoundTestBase::checkVolumeNotification(double volume, QString cons
QVariantMap hints;
ASSERT_TRUE(qDBusArgumentToMap(args.at(6), hints));
ASSERT_TRUE(hints.contains("value"));
+ ASSERT_TRUE (hints.contains ("x-lomiri-non-shaped-icon"));
+ ASSERT_TRUE (hints.contains ("x-lomiri-value-bar-tint"));
+ ASSERT_TRUE (hints.contains ("x-lomiri-private-synchronous"));
EXPECT_EQ(volume*100, hints["value"]);
+ EXPECT_EQ (true, hints["x-lomiri-non-shaped-icon"]);
+ EXPECT_EQ (isLoud, hints["x-lomiri-value-bar-tint"]);
+ EXPECT_EQ (true, hints["x-lomiri-private-synchronous"]);
}
void IndicatorSoundTestBase::checkHighVolumeNotification(QVariantList call)
diff --git a/tests/notifications-mock.h b/tests/notifications-mock.h
index 3ae8da5..ef39d8c 100644
--- a/tests/notifications-mock.h
+++ b/tests/notifications-mock.h
@@ -31,7 +31,7 @@ class NotificationsMock
DbusTestDbusMockObject * baseobj = nullptr;
public:
- NotificationsMock (const std::vector<std::string>& capabilities = {"actions", "body", "body-markup", "icon-static", "image/svg+xml", "private-synchronous", "append", "private-icon-only", "truncation"}) {
+ NotificationsMock (const std::vector<std::string>& capabilities = {"actions", "body", "body-markup", "icon-static", "image/svg+xml", "x-lomiri-private-synchronous", "x-lomiri-private-icon-only", "x-lomiri-truncation", "private-synchronous", "append", "private-icon-only", "truncation"}) {
mock = dbus_test_dbus_mock_new("org.freedesktop.Notifications");
dbus_test_task_set_bus(DBUS_TEST_TASK(mock), DBUS_TEST_SERVICE_BUS_SESSION);
dbus_test_task_set_name(DBUS_TEST_TASK(mock), "Notify");
diff --git a/tests/notifications-test.cc b/tests/notifications-test.cc
index 0233ca6..c29c8fb 100644
--- a/tests/notifications-test.cc
+++ b/tests/notifications-test.cc
@@ -259,6 +259,7 @@ TEST_F(NotificationsTest, VolumeChanges) {
EXPECT_EQ("ayatana-indicator-sound", notev[0].app_name);
EXPECT_EQ("Volume", notev[0].summary);
EXPECT_EQ(0, notev[0].actions.size());
+ EXPECT_GVARIANT_EQ ("@s 'true'", notev[0].hints["x-lomiri-private-synchronous"]);
EXPECT_GVARIANT_EQ("@i 50", notev[0].hints["value"]);
/* Set a different volume */
@@ -431,6 +432,7 @@ TEST_F(NotificationsTest, DISABLED_HighVolume) {
ASSERT_EQ(1, notev.size());
EXPECT_EQ("Volume", notev[0].summary);
EXPECT_EQ("Speakers", notev[0].body);
+ EXPECT_GVARIANT_EQ ("@s 'false'", notev[0].hints["x-lomiri-value-bar-tint"]);
/* Set high volume with volume change */
notifications->clearNotifications();
@@ -441,6 +443,7 @@ TEST_F(NotificationsTest, DISABLED_HighVolume) {
ASSERT_LT(0, notev.size()); /* This passes with one or two since it would just be an update to the first if a second was sent */
EXPECT_EQ("Volume", notev[0].summary);
EXPECT_EQ("Speakers", notev[0].body);
+ EXPECT_GVARIANT_EQ ("@s 'true'", notev[0].hints["x-lomiri-value-bar-tint"]);
/* Move it back */
volume_warning_mock_set_high_volume(VOLUME_WARNING_MOCK(volumeWarning.get()), false);
@@ -510,6 +513,7 @@ TEST_F(NotificationsTest, DISABLED_ExtendendVolumeNotification) {
EXPECT_EQ("Volume", notev[0].summary);
EXPECT_EQ(0, notev[0].actions.size());
EXPECT_GVARIANT_EQ("@i 50", notev[0].hints["value"]);
+ EXPECT_GVARIANT_EQ ("@s 'true'", notev[0].hints["x-lomiri-private-synchronous"]);
/* Allow an amplified volume */
notifications->clearNotifications();
@@ -623,10 +627,14 @@ TEST_F(NotificationsTest, DISABLED_TriggerWarning) {
if (warning_expected) {
EXPECT_TRUE(volume_warning_get_active(volumeWarning.get()));
ASSERT_EQ(1, notev.size());
+ EXPECT_GVARIANT_EQ ("@s 'true'", notev[0].hints["x-lomiri-snap-decisions"]);
+ EXPECT_GVARIANT_EQ (nullptr, notev[0].hints["x-lomiri-private-synchronous"]);
}
else {
EXPECT_FALSE(volume_warning_get_active(volumeWarning.get()));
ASSERT_EQ(1, notev.size());
+ EXPECT_GVARIANT_EQ (nullptr, notev[0].hints["x-lomiri-snap-decisions"]);
+ EXPECT_GVARIANT_EQ("@s 'true'", notev[0].hints["x-lomiri-private-synchronous"]);
}
} // multimedia_active