diff options
author | Lars Uebernickel <lars.uebernickel@canonical.com> | 2013-04-03 22:30:03 -0400 |
---|---|---|
committer | Lars Uebernickel <lars.uebernickel@canonical.com> | 2013-04-03 22:30:03 -0400 |
commit | 7519d2eb92c06b5a88d79a9a8f28b53c33b96c3b (patch) | |
tree | 89129ef76c6761e497c06f6e87c62ff8fb2ed72a /src | |
parent | e1d7602cdeabfd4267a6279ec59971905e615a43 (diff) | |
download | ayatana-indicator-sound-7519d2eb92c06b5a88d79a9a8f28b53c33b96c3b.tar.gz ayatana-indicator-sound-7519d2eb92c06b5a88d79a9a8f28b53c33b96c3b.tar.bz2 ayatana-indicator-sound-7519d2eb92c06b5a88d79a9a8f28b53c33b96c3b.zip |
Always update all player actions
This fixes a bug: only the first player that changed (or was added) in a single
main context iteration was updated in update_player_action(). That's because
only one source id was used for all idles.
Another fix to this would be to keep track of which actions need to be updated.
This patch is a bit more brute-force, but that will probably not matter much,
as the amount of players is generally small.
Diffstat (limited to 'src')
-rw-r--r-- | src/service.vala | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/src/service.vala b/src/service.vala index 8f5280e..1590844 100644 --- a/src/service.vala +++ b/src/service.vala @@ -124,28 +124,30 @@ public class IndicatorSound.Service { this.loop.quit (); } - bool update_player_action (MediaPlayer player) { - var builder = new VariantBuilder (new VariantType ("a{sv}")); - builder.add ("{sv}", "running", new Variant ("b", player.is_running)); - var state = builder.end (); - - SimpleAction? action = this.actions.lookup (player.id) as SimpleAction; - if (action == null) { - action = new SimpleAction.stateful (player.id, null, state); - action.activate.connect ( () => { player.launch (); }); - this.actions.insert (action); - } - else { - action.set_state (state); + bool update_player_actions () { + foreach (var player in this.players) { + var builder = new VariantBuilder (new VariantType ("a{sv}")); + builder.add ("{sv}", "running", new Variant ("b", player.is_running)); + var state = builder.end (); + + SimpleAction? action = this.actions.lookup (player.id) as SimpleAction; + if (action == null) { + action = new SimpleAction.stateful (player.id, null, state); + action.activate.connect ( () => { player.launch (); }); + this.actions.insert (action); + } + else { + action.set_state (state); + } } this.player_action_update_id = 0; return false; } - void eventually_update_player_action (MediaPlayer player) { + void eventually_update_player_actions () { if (player_action_update_id == 0) - this.player_action_update_id = Idle.add ( () => this.update_player_action (player) ); + this.player_action_update_id = Idle.add (this.update_player_actions); } void player_added (MediaPlayer player) { @@ -153,7 +155,7 @@ public class IndicatorSound.Service { item.set_attribute ("x-canonical-type", "s", "com.canonical.unity.media-player"); this.menu.insert_item (this.menu.get_n_items () -1, item); - eventually_update_player_action (player); - player.notify.connect ( () => eventually_update_player_action (player) ); + eventually_update_player_actions (); + player.notify.connect (this.eventually_update_player_actions); } } |