diff options
-rw-r--r-- | debian/control | 2 | ||||
-rw-r--r-- | src/service.vala | 14 | ||||
-rw-r--r-- | tests/notifications-test.cc | 90 |
3 files changed, 101 insertions, 5 deletions
diff --git a/debian/control b/debian/control index cdb1267..3585713 100644 --- a/debian/control +++ b/debian/control @@ -39,7 +39,7 @@ Depends: ${shlibs:Depends}, ${misc:Depends}, pulseaudio, gsettings-ubuntu-schemas (>= 0.0.1+14.04.20140224), -Recommends: unity-control-center | gnome-control-center | ubuntu-system-settings | pavucontrol, +Recommends: unity-control-center | gnome-control-center | ubuntu-system-settings | pavucontrol | mate-media, accountsservice, Suggests: unity-greeter-session-broadcast, Description: System sound indicator. diff --git a/src/service.vala b/src/service.vala index 0c82538..488b993 100644 --- a/src/service.vala +++ b/src/service.vala @@ -97,12 +97,16 @@ public class IndicatorSound.Service: Object { /* Hide the notification when the menu is shown */ var shown_action = actions.lookup_action ("indicator-shown") as SimpleAction; shown_action.change_state.connect ((state) => { - if (state.get_boolean()) { + block_notifications = state.get_boolean(); + if (block_notifications) { + debug("Indicator is shown"); try { sync_notification.close(); } catch (Error e) { warning("Unable to close synchronous volume notification: %s", e.message); } + } else { + debug("Indicator is hidden"); } }); @@ -216,6 +220,8 @@ public class IndicatorSound.Service: Object { string cmd; if (env == "xubuntu" || env == "ubuntustudio") cmd = "pavucontrol"; + else if (env == "mate") + cmd = "mate-volume-control"; else { if (Environment.get_variable ("XDG_CURRENT_DESKTOP") == "Unity" && Environment.find_program_in_path ("unity-control-center") != null) @@ -280,6 +286,7 @@ public class IndicatorSound.Service: Object { private bool check_sync_notification = false; private bool support_sync_notification = false; + private bool block_notifications = false; void update_sync_notification () { if (!check_sync_notification) { @@ -294,8 +301,7 @@ public class IndicatorSound.Service: Object { if (!support_sync_notification) return; - var shown_action = actions.lookup_action ("indicator-shown") as SimpleAction; - if (shown_action != null && shown_action.get_state().get_boolean()) + if (block_notifications) return; /* Determine Label */ @@ -322,7 +328,7 @@ public class IndicatorSound.Service: Object { /* Put it all into the notification */ sync_notification.clear_hints (); sync_notification.update (_("Volume"), volume_label, icon); - sync_notification.set_hint ("value", (int32)Math.round(volume_control.volume.volume * 100.0)); + sync_notification.set_hint ("value", (int32)Math.round(volume_control.volume.volume / this.max_volume * 100.0)); sync_notification.set_hint ("x-canonical-value-bar-tint", tint); sync_notification.set_hint ("x-canonical-private-synchronous", "true"); sync_notification.set_hint ("x-canonical-non-shaped-icon", "true"); diff --git a/tests/notifications-test.cc b/tests/notifications-test.cc index 88ed6c6..1f7e178 100644 --- a/tests/notifications-test.cc +++ b/tests/notifications-test.cc @@ -146,6 +146,25 @@ class NotificationsTest : public ::testing::Test volume_control_set_volume(volumeControl.get(), vol); g_object_unref(vol); } + + void setIndicatorShown (bool shown) { + auto bus = g_bus_get_sync(G_BUS_TYPE_SESSION, nullptr, nullptr); + + g_dbus_connection_call(bus, + g_dbus_connection_get_unique_name(bus), + "/com/canonical/indicator/sound", + "org.gtk.Actions", + "SetState", + g_variant_new("(sva{sv})", "indicator-shown", g_variant_new_boolean(shown), nullptr), + nullptr, + G_DBUS_CALL_FLAGS_NONE, + -1, + nullptr, + nullptr, + nullptr); + + g_clear_object(&bus); + } }; TEST_F(NotificationsTest, BasicObject) { @@ -356,3 +375,74 @@ TEST_F(NotificationsTest, HighVolume) { EXPECT_EQ("High volume", notev[0].body); EXPECT_GVARIANT_EQ("@s 'true'", notev[0].hints["x-canonical-value-bar-tint"]); } + +TEST_F(NotificationsTest, MenuHide) { + auto volumeControl = volumeControlMock(); + auto soundService = standardService(volumeControl, playerListMock()); + + /* Set a volume */ + notifications->clearNotifications(); + setMockVolume(volumeControl, 0.50); + loop(50); + auto notev = notifications->getNotifications(); + EXPECT_EQ(1, notev.size()); + + /* Set the indicator to shown, and set a new volume */ + notifications->clearNotifications(); + setIndicatorShown(true); + loop(50); + setMockVolume(volumeControl, 0.60); + loop(50); + notev = notifications->getNotifications(); + EXPECT_EQ(0, notev.size()); + + /* Set the indicator to hidden, and set a new volume */ + notifications->clearNotifications(); + setIndicatorShown(false); + loop(50); + setMockVolume(volumeControl, 0.70); + loop(50); + notev = notifications->getNotifications(); + EXPECT_EQ(1, notev.size()); +} + +TEST_F(NotificationsTest, ExtendendVolumeNotification) { + auto volumeControl = volumeControlMock(); + auto soundService = standardService(volumeControl, playerListMock()); + + /* Set a volume */ + notifications->clearNotifications(); + setMockVolume(volumeControl, 0.50); + loop(50); + auto notev = notifications->getNotifications(); + ASSERT_EQ(1, notev.size()); + EXPECT_EQ("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-canonical-private-synchronous"]); + EXPECT_GVARIANT_EQ("@i 50", notev[0].hints["value"]); + + /* Allow an amplified volume */ + notifications->clearNotifications(); + indicator_sound_service_set_allow_amplified_volume(soundService.get(), TRUE); + loop(50); + notev = notifications->getNotifications(); + ASSERT_EQ(1, notev.size()); + EXPECT_GVARIANT_EQ("@i 33", notev[0].hints["value"]); + + /* Set to 'over max' */ + notifications->clearNotifications(); + setMockVolume(volumeControl, 1.525); + loop(50); + notev = notifications->getNotifications(); + ASSERT_EQ(1, notev.size()); + EXPECT_GVARIANT_EQ("@i 100", notev[0].hints["value"]); + + /* Put back */ + notifications->clearNotifications(); + indicator_sound_service_set_allow_amplified_volume(soundService.get(), FALSE); + loop(50); + notev = notifications->getNotifications(); + ASSERT_EQ(1, notev.size()); + EXPECT_GVARIANT_EQ("@i 100", notev[0].hints["value"]); +} |