Drop chrome.runtime.onMessage events
We can use Backbone.Events instead. // FREEBIE
This commit is contained in:
parent
bba25b22e2
commit
886557a2aa
3 changed files with 5 additions and 20 deletions
|
@ -44,6 +44,7 @@
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
window.events = _.clone(Backbone.Events);
|
||||||
var accountManager;
|
var accountManager;
|
||||||
window.getAccountManager = function() {
|
window.getAccountManager = function() {
|
||||||
if (!accountManager) {
|
if (!accountManager) {
|
||||||
|
@ -58,12 +59,13 @@
|
||||||
}
|
}
|
||||||
Whisper.Registration.markDone();
|
Whisper.Registration.markDone();
|
||||||
console.log("dispatching registration event");
|
console.log("dispatching registration event");
|
||||||
extension.trigger('registration_done');
|
events.trigger('registration_done');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return accountManager;
|
return accountManager;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
storage.fetch();
|
storage.fetch();
|
||||||
storage.onready(function() {
|
storage.onready(function() {
|
||||||
window.dispatchEvent(new Event('storage_ready'));
|
window.dispatchEvent(new Event('storage_ready'));
|
||||||
|
@ -75,7 +77,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("listening for registration events");
|
console.log("listening for registration events");
|
||||||
extension.on('registration_done', function() {
|
events.on('registration_done', function() {
|
||||||
console.log("handling registration event");
|
console.log("handling registration event");
|
||||||
extension.keepAwake();
|
extension.keepAwake();
|
||||||
init(true);
|
init(true);
|
||||||
|
|
|
@ -27,23 +27,6 @@
|
||||||
return self;
|
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 = {
|
extension.windows = {
|
||||||
open: function(options, callback) {
|
open: function(options, callback) {
|
||||||
if (chrome.windows) {
|
if (chrome.windows) {
|
||||||
|
|
|
@ -49,7 +49,7 @@
|
||||||
if (Whisper.Registration.isDone()) {
|
if (Whisper.Registration.isDone()) {
|
||||||
setTimeoutForNextRun();
|
setTimeoutForNextRun();
|
||||||
}
|
}
|
||||||
extension.on('registration_done', function() {
|
window.events.on('registration_done', function() {
|
||||||
scheduleNextRotation();
|
scheduleNextRotation();
|
||||||
setTimeoutForNextRun();
|
setTimeoutForNextRun();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue