signaling.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. "use strict";
  2. // Global modules
  3. const Lang = imports.lang;
  4. // Helper to disconnect more signals at once
  5. var SignalConnector = new Lang.Class({
  6. Name: "WindowCornerPreview.SignalConnector",
  7. _init: function() {
  8. this._connections = [];
  9. },
  10. tryConnect: function(actor, signal, callback) {
  11. try {
  12. let handle = actor.connect(signal, callback);
  13. this._connections.push({
  14. actor: actor,
  15. handle: handle
  16. });
  17. }
  18. catch (e) {
  19. logError(e, "SignalConnector.tryConnect failed");
  20. }
  21. },
  22. tryConnectAfter: function(actor, signal, callback) {
  23. try {
  24. let handle = actor.connect_after(signal, callback);
  25. this._connections.push({
  26. actor: actor,
  27. handle: handle
  28. });
  29. }
  30. catch (e) {
  31. logError(e, "SignalConnector.tryConnectAfter failed");
  32. }
  33. },
  34. disconnectAll: function() {
  35. for (let i = 0; i < this._connections.length; i++) {
  36. try {
  37. let connection = this._connections[i];
  38. connection.actor.disconnect(connection.handle);
  39. this._connections[i] = null;
  40. }
  41. catch (e) {
  42. logError(e, "SignalConnector.disconnectAll failed");
  43. }
  44. }
  45. this._connections = [];
  46. }
  47. });