"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() {
|
;(function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
if (!localStorage.getItem('first_install_ran')) {
|
function init() {
|
||||||
localStorage.setItem('first_install_ran', 1);
|
if (!localStorage.getItem('first_install_ran')) {
|
||||||
extension.navigator.tabs.create("options.html");
|
localStorage.setItem('first_install_ran', 1);
|
||||||
} else {
|
extension.navigator.tabs.create("options.html");
|
||||||
if (isRegistrationDone()) {
|
} else {
|
||||||
textsecure.subscribeToPush(function(message) {
|
if (isRegistrationDone()) {
|
||||||
Whisper.Messages.addIncomingMessage(message).then(function() {
|
textsecure.subscribeToPush(function(message) {
|
||||||
console.log("Got message from " + message.pushMessage.source + "." + message.pushMessage.sourceDevice +
|
Whisper.Messages.addIncomingMessage(message).then(function() {
|
||||||
': "' + getString(message.message.body) + '"');
|
console.log("Got message from " + message.pushMessage.source + "." + message.pushMessage.sourceDevice +
|
||||||
var newUnreadCount = textsecure.storage.getUnencrypted("unreadCount", 0) + 1;
|
': "' + getString(message.message.body) + '"');
|
||||||
textsecure.storage.putUnencrypted("unreadCount", newUnreadCount);
|
var newUnreadCount = textsecure.storage.getUnencrypted("unreadCount", 0) + 1;
|
||||||
extension.navigator.setBadgeText(newUnreadCount);
|
textsecure.storage.putUnencrypted("unreadCount", newUnreadCount);
|
||||||
|
extension.navigator.setBadgeText(newUnreadCount);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
|
addRegistrationListener(init);
|
||||||
|
init();
|
||||||
})();
|
})();
|
||||||
|
@@ -36,10 +36,18 @@ window.extension.navigator = function() {
|
|||||||
|
|
||||||
function registrationDone() {
|
function registrationDone() {
|
||||||
localStorage.setItem("chromiumRegistrationDone", "");
|
localStorage.setItem("chromiumRegistrationDone", "");
|
||||||
//TODO: Fix dirty hack:
|
chrome.runtime.sendMessage('registration_done');
|
||||||
chrome.runtime.reload();
|
window.location = '/index.html';
|
||||||
}
|
}
|
||||||
|
|
||||||
function isRegistrationDone() {
|
function isRegistrationDone() {
|
||||||
return localStorage.getItem("chromiumRegistrationDone") !== null;
|
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});
|
}))({el: document});
|
||||||
|
|
||||||
if (textsecure.storage.getUnencrypted("number_id") === undefined) {
|
if (textsecure.storage.getUnencrypted("number_id") === undefined) {
|
||||||
extension.navigator.tabs.create("options.html");
|
window.location = '/options.html';
|
||||||
} else {
|
} else {
|
||||||
textsecure.storage.putUnencrypted("unreadCount", 0);
|
textsecure.storage.putUnencrypted("unreadCount", 0);
|
||||||
extension.navigator.setBadgeText("");
|
extension.navigator.setBadgeText("");
|
||||||
|
Reference in New Issue
Block a user