aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2013-04-04 06:38:50 +0200
committerLars Uebernickel <lars.uebernickel@canonical.com>2013-04-04 06:38:50 +0200
commit6fabe993476761f2bb1852c3380ca2e5be1e0ac4 (patch)
treef1c863fe83e54f334583339a71444428e8ecda6c /src
parente38bff2ef074638c05aa8d57c2c4d09ed7c31780 (diff)
downloadayatana-indicator-sound-6fabe993476761f2bb1852c3380ca2e5be1e0ac4.tar.gz
ayatana-indicator-sound-6fabe993476761f2bb1852c3380ca2e5be1e0ac4.tar.bz2
ayatana-indicator-sound-6fabe993476761f2bb1852c3380ca2e5be1e0ac4.zip
Service: create player action right away, not lazily in an idle
Diffstat (limited to 'src')
-rw-r--r--src/service.vala25
1 files changed, 12 insertions, 13 deletions
diff --git a/src/service.vala b/src/service.vala
index 03b72a6..a291f2d 100644
--- a/src/service.vala
+++ b/src/service.vala
@@ -143,21 +143,17 @@ public class IndicatorSound.Service {
this.loop.quit ();
}
+ Variant action_state_for_player (MediaPlayer player) {
+ var builder = new VariantBuilder (new VariantType ("a{sv}"));
+ builder.add ("{sv}", "running", new Variant ("b", player.is_running));
+ return builder.end ();
+ }
+
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);
- }
+ if (action != null)
+ action.set_state (this.action_state_for_player (player));
}
this.player_action_update_id = 0;
@@ -174,7 +170,10 @@ 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_actions ();
+ SimpleAction action = new SimpleAction.stateful (player.id, null, this.action_state_for_player (player));
+ action.activate.connect ( () => { player.launch (); });
+ this.actions.insert (action);
+
player.notify.connect (this.eventually_update_player_actions);
}