From 3d3a9b5b084ebecc06c2b67b220f0d2a8fecd839 Mon Sep 17 00:00:00 2001 From: Dmitry Shachnev Date: Tue, 5 Apr 2016 23:28:26 +0200 Subject: Move Unity detection into a separate function, and add caching --- src/service.vala | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/service.vala b/src/service.vala index e07e9fd..33008a1 100644 --- a/src/service.vala +++ b/src/service.vala @@ -206,6 +206,7 @@ public class IndicatorSound.Service: Object { private VolumeWarning _volume_warning; private IndicatorSound.InfoNotification _info_notification = new IndicatorSound.InfoNotification(); private AccountsServiceAccess _accounts_service_access; + bool? is_unity = null; const double volume_step_percentage = 0.06; @@ -224,9 +225,26 @@ public class IndicatorSound.Service: Object { } } + private bool desktop_is_unity() { + if (is_unity != null) { + return is_unity; + } + + is_unity = false; + unowned string desktop = Environment.get_variable ("XDG_CURRENT_DESKTOP"); + + foreach (var name in desktop.split(":")) { + if (name == "Unity") { + is_unity = true; + break; + } + } + + return is_unity; + } + void activate_desktop_settings (SimpleAction action, Variant? param) { unowned string env = Environment.get_variable ("DESKTOP_SESSION"); - unowned string desktop = Environment.get_variable ("XDG_CURRENT_DESKTOP"); string cmd; if (Environment.get_variable ("MIR_SOCKET") != null) @@ -239,16 +257,10 @@ public class IndicatorSound.Service: Object { cmd = "pavucontrol"; else if (env == "mate") cmd = "mate-volume-control"; + else if (desktop_is_unity() && Environment.find_program_in_path ("unity-control-center") != null) + cmd = "unity-control-center sound"; else - { cmd = "gnome-control-center sound"; - foreach (var name in desktop.split(":")) { - if (name == "Unity" && Environment.find_program_in_path ("unity-control-center") != null) { - cmd = "unity-control-center sound"; - break; - } - } - } try { Process.spawn_command_line_async (cmd); -- cgit v1.2.3