Make getBackground async

This commit is contained in:
lilia 2015-05-11 14:22:15 -07:00
parent a57363f1c0
commit 76e170686a
6 changed files with 198 additions and 175 deletions

View file

@ -72,8 +72,18 @@
chrome.windows.remove(windowId); chrome.windows.remove(windowId);
}, },
getBackground: function() { getBackground: function(callback) {
return chrome.extension.getBackgroundPage(); if (chrome.extension) {
return new Promise(function(resolve) {
callback(chrome.extension.getBackgroundPage());
resolve();
});
} else if (chrome.runtime) {
return new Promise(function(resolve) {
chrome.runtime.getBackgroundPage(callback);
resolve();
});
}
}, },
getViews: function() { getViews: function() {
@ -96,4 +106,11 @@
return localStorage.getItem("chromiumRegistrationDone") !== null; return localStorage.getItem("chromiumRegistrationDone") !== null;
}, },
}; };
chrome.app.runtime.onLaunched.addListener(function() {
chrome.app.window.create('index.html', {
id: 'main',
bounds: { width: 620, height: 500 }
});
});
}()); }());

View file

@ -20,7 +20,7 @@
window.Whisper = window.Whisper || {}; window.Whisper = window.Whisper || {};
extension.windows.getCurrent(function (windowInfo) { extension.windows.getCurrent(function (windowInfo) {
var bg = extension.windows.getBackground(); extension.windows.getBackground(function(bg) {
window.$ = bg.$; window.$ = bg.$;
var body = $('body', document); var body = $('body', document);
var conversation = bg.getConversationForWindow(windowInfo.id); var conversation = bg.getConversationForWindow(windowInfo.id);
@ -35,4 +35,5 @@
$('<div>').text('Error').prependTo(body); $('<div>').text('Error').prependTo(body);
} }
}); });
});
}()); }());

View file

@ -16,12 +16,14 @@
*/ */
(function () { (function () {
'use strict'; 'use strict';
var bg = extension.windows.getBackground();
window.Whisper = window.Whisper || {}; window.Whisper = window.Whisper || {};
extension.windows.getBackground(function(bg) {
if (bg.textsecure.storage.user.getNumber() === undefined) { if (bg.textsecure.storage.user.getNumber() === undefined) {
window.location = '/options.html'; window.location = '/options.html';
} else { } else {
new bg.Whisper.InboxView().$el.prependTo(bg.$('body',document)); new bg.Whisper.InboxView().$el.prependTo(bg.$('body',document));
} }
});
}()); }());

View file

@ -69,7 +69,7 @@
}); });
$(function() { $(function() {
var bg = extension.windows.getBackground(); extension.windows.getBackground(function(bg) {
if (bg.textsecure.registration.isDone()) { if (bg.textsecure.registration.isDone()) {
$('#complete-number').text(bg.textsecure.storage.user.getNumber()); $('#complete-number').text(bg.textsecure.storage.user.getNumber());
$('#setup-complete').show().addClass('in'); $('#setup-complete').show().addClass('in');
@ -87,4 +87,5 @@
}); });
} }
}); });
});
})(); })();

View file

@ -16,7 +16,7 @@
;(function() { ;(function() {
'use strict'; 'use strict';
var bg = extension.windows.getBackground(); extension.windows.getBackground(function(bg) {
var accountManager = new bg.textsecure.AccountManager(); var accountManager = new bg.textsecure.AccountManager();
function log(s) { function log(s) {
@ -94,5 +94,6 @@
log(e); log(e);
}); });
}); });
});
})(); })();

View file

@ -17,8 +17,8 @@
'use strict'; 'use strict';
window.Whisper = window.Whisper || {}; window.Whisper = window.Whisper || {};
var bg = extension.windows.getBackground();
extension.windows.getBackground(function(bg) {
var SocketView = Whisper.View.extend({ var SocketView = Whisper.View.extend({
className: 'status', className: 'status',
initialize: function() { initialize: function() {
@ -98,5 +98,6 @@
this.$el.show(); this.$el.show();
} }
}); });
});
})(); })();