diff options
author | Dmitry Shachnev <mitya57@ubuntu.com> | 2016-04-05 23:28:26 +0200 |
---|---|---|
committer | Dmitry Shachnev <mitya57@ubuntu.com> | 2016-04-05 23:28:26 +0200 |
commit | 3d3a9b5b084ebecc06c2b67b220f0d2a8fecd839 (patch) | |
tree | 3d67caa40dc14b3eba6b2511fb606b4a010f22e5 /src | |
parent | c4039b86ab3829e439e3e44fe6663f6e31b2df69 (diff) | |
download | ayatana-indicator-sound-3d3a9b5b084ebecc06c2b67b220f0d2a8fecd839.tar.gz ayatana-indicator-sound-3d3a9b5b084ebecc06c2b67b220f0d2a8fecd839.tar.bz2 ayatana-indicator-sound-3d3a9b5b084ebecc06c2b67b220f0d2a8fecd839.zip |
Move Unity detection into a separate function, and add caching
Diffstat (limited to 'src')
-rw-r--r-- | src/service.vala | 30 |
1 files 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); |