From 886557a2aadf6e03e7765f9997fb7e1600ad4f37 Mon Sep 17 00:00:00 2001 From: lilia Date: Mon, 27 Feb 2017 14:41:51 -0800 Subject: [PATCH] Drop chrome.runtime.onMessage events We can use Backbone.Events instead. // FREEBIE --- js/background.js | 6 ++++-- js/chromium.js | 17 ----------------- js/rotate_signed_prekey_listener.js | 2 +- 3 files changed, 5 insertions(+), 20 deletions(-) diff --git a/js/background.js b/js/background.js index da3ca4499a5..a893a8d6f6f 100644 --- a/js/background.js +++ b/js/background.js @@ -44,6 +44,7 @@ return -1; } }; + window.events = _.clone(Backbone.Events); var accountManager; window.getAccountManager = function() { if (!accountManager) { @@ -58,12 +59,13 @@ } Whisper.Registration.markDone(); console.log("dispatching registration event"); - extension.trigger('registration_done'); + events.trigger('registration_done'); }); } return accountManager; }; + storage.fetch(); storage.onready(function() { window.dispatchEvent(new Event('storage_ready')); @@ -75,7 +77,7 @@ } console.log("listening for registration events"); - extension.on('registration_done', function() { + events.on('registration_done', function() { console.log("handling registration event"); extension.keepAwake(); init(true); diff --git a/js/chromium.js b/js/chromium.js index 47574a4d1da..2912d3c613e 100644 --- a/js/chromium.js +++ b/js/chromium.js @@ -27,23 +27,6 @@ return self; }()); - window.extension.trigger = function (name, object) { - chrome.runtime.sendMessage(null, { name: name, data: object }); - }; - - window.extension.on = function (name, callback) { - // this causes every listener to fire on every message. - // if we eventually end up with lots of listeners (lol) - // might be worth making a map of 'name' -> [callbacks, ...] - // so we can fire a single listener that calls only the necessary - // calllbacks for that message name - chrome.runtime.onMessage.addListener(function(e) { - if (e.name === name) { - callback(e.data); - } - }); - }; - extension.windows = { open: function(options, callback) { if (chrome.windows) { diff --git a/js/rotate_signed_prekey_listener.js b/js/rotate_signed_prekey_listener.js index 5204cf9d9b0..aab636ff8da 100644 --- a/js/rotate_signed_prekey_listener.js +++ b/js/rotate_signed_prekey_listener.js @@ -49,7 +49,7 @@ if (Whisper.Registration.isDone()) { setTimeoutForNextRun(); } - extension.on('registration_done', function() { + window.events.on('registration_done', function() { scheduleNextRotation(); setTimeoutForNextRun(); });