"Fix dirty hack" (runtime.reload) in chromium.js
Runtime reload is overkill and causes a jarring ux. Instead, send and receive messages across the runtime. Also, if we need to jump between the main ui and options pages, simply navigate within the current tab rather than spawning a new one.
This commit is contained in:
@@ -17,20 +17,25 @@
|
||||
;(function() {
|
||||
'use strict';
|
||||
|
||||
if (!localStorage.getItem('first_install_ran')) {
|
||||
localStorage.setItem('first_install_ran', 1);
|
||||
extension.navigator.tabs.create("options.html");
|
||||
} else {
|
||||
if (isRegistrationDone()) {
|
||||
textsecure.subscribeToPush(function(message) {
|
||||
Whisper.Messages.addIncomingMessage(message).then(function() {
|
||||
console.log("Got message from " + message.pushMessage.source + "." + message.pushMessage.sourceDevice +
|
||||
': "' + getString(message.message.body) + '"');
|
||||
var newUnreadCount = textsecure.storage.getUnencrypted("unreadCount", 0) + 1;
|
||||
textsecure.storage.putUnencrypted("unreadCount", newUnreadCount);
|
||||
extension.navigator.setBadgeText(newUnreadCount);
|
||||
function init() {
|
||||
if (!localStorage.getItem('first_install_ran')) {
|
||||
localStorage.setItem('first_install_ran', 1);
|
||||
extension.navigator.tabs.create("options.html");
|
||||
} else {
|
||||
if (isRegistrationDone()) {
|
||||
textsecure.subscribeToPush(function(message) {
|
||||
Whisper.Messages.addIncomingMessage(message).then(function() {
|
||||
console.log("Got message from " + message.pushMessage.source + "." + message.pushMessage.sourceDevice +
|
||||
': "' + getString(message.message.body) + '"');
|
||||
var newUnreadCount = textsecure.storage.getUnencrypted("unreadCount", 0) + 1;
|
||||
textsecure.storage.putUnencrypted("unreadCount", newUnreadCount);
|
||||
extension.navigator.setBadgeText(newUnreadCount);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
addRegistrationListener(init);
|
||||
init();
|
||||
})();
|
||||
|
@@ -36,10 +36,18 @@ window.extension.navigator = function() {
|
||||
|
||||
function registrationDone() {
|
||||
localStorage.setItem("chromiumRegistrationDone", "");
|
||||
//TODO: Fix dirty hack:
|
||||
chrome.runtime.reload();
|
||||
chrome.runtime.sendMessage('registration_done');
|
||||
window.location = '/index.html';
|
||||
}
|
||||
|
||||
function isRegistrationDone() {
|
||||
return localStorage.getItem("chromiumRegistrationDone") !== null;
|
||||
}
|
||||
|
||||
function addRegistrationListener(callback) {
|
||||
chrome.runtime.onMessage.addListener(function(message) {
|
||||
if (message === 'registration_done') {
|
||||
callback();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
@@ -63,7 +63,7 @@ Whisper.Layout = new (Backbone.View.extend({
|
||||
}))({el: document});
|
||||
|
||||
if (textsecure.storage.getUnencrypted("number_id") === undefined) {
|
||||
extension.navigator.tabs.create("options.html");
|
||||
window.location = '/options.html';
|
||||
} else {
|
||||
textsecure.storage.putUnencrypted("unreadCount", 0);
|
||||
extension.navigator.setBadgeText("");
|
||||
|
Reference in New Issue
Block a user