Refactor app view
Introduce a top level view for navigating between the inbox and the installer, enabling an in-window relink flow. Navigation is driven through the openInbox and openInstaller global events. // FREEBIE
This commit is contained in:
parent
3f5505907f
commit
e4e41140c4
7 changed files with 111 additions and 115 deletions
|
@ -58,18 +58,11 @@
|
|||
return accountManager;
|
||||
};
|
||||
|
||||
|
||||
storage.fetch();
|
||||
storage.onready(function() {
|
||||
ConversationController.load();
|
||||
|
||||
window.dispatchEvent(new Event('storage_ready'));
|
||||
setUnreadCount(storage.get("unreadCount", 0));
|
||||
|
||||
if (Whisper.Registration.isDone()) {
|
||||
extension.keepAwake();
|
||||
init();
|
||||
}
|
||||
|
||||
console.log("listening for registration events");
|
||||
Whisper.events.on('registration_done', function() {
|
||||
|
@ -78,8 +71,12 @@
|
|||
init(true);
|
||||
});
|
||||
|
||||
var appView = window.owsDesktopApp.appView = new Whisper.AppView({el: $('body'), events: Whisper.events});
|
||||
|
||||
if (open) {
|
||||
openInbox();
|
||||
openInbox({
|
||||
initialLoadComplete: initialLoadComplete
|
||||
});
|
||||
}
|
||||
|
||||
Whisper.WallClockListener.init(Whisper.events);
|
||||
|
@ -87,11 +84,21 @@
|
|||
Whisper.ExpiringMessagesListener.init(Whisper.events);
|
||||
|
||||
if (Whisper.Registration.everDone()) {
|
||||
openInbox();
|
||||
}
|
||||
if (!Whisper.Registration.isDone()) {
|
||||
extension.install();
|
||||
init();
|
||||
appView.openInbox({
|
||||
initialLoadComplete: initialLoadComplete
|
||||
});
|
||||
} else {
|
||||
appView.openInstaller();
|
||||
}
|
||||
|
||||
Whisper.events.on('unauthorized', function() {
|
||||
appView.inboxView.networkStatusView.update();
|
||||
});
|
||||
Whisper.events.on('reconnectTimer', function() {
|
||||
appView.inboxView.networkStatusView.setSocketReconnectInterval(60000);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
window.getSyncRequest = function() {
|
||||
|
@ -111,6 +118,7 @@
|
|||
|
||||
function init(firstRun) {
|
||||
window.removeEventListener('online', init);
|
||||
|
||||
if (!Whisper.Registration.isDone()) { return; }
|
||||
if (Whisper.Migration.inProgress()) { return; }
|
||||
|
||||
|
@ -173,7 +181,7 @@
|
|||
initialLoadComplete = true;
|
||||
|
||||
var interval = setInterval(function() {
|
||||
var view = window.owsDesktopApp.inboxView;
|
||||
var view = window.owsDesktopApp.appView;
|
||||
if (view) {
|
||||
clearInterval(interval);
|
||||
interval = null;
|
||||
|
@ -184,7 +192,7 @@
|
|||
function onProgress(ev) {
|
||||
var count = ev.count;
|
||||
|
||||
var view = window.owsDesktopApp.inboxView;
|
||||
var view = window.owsDesktopApp.appView;
|
||||
if (view) {
|
||||
view.onProgress(count);
|
||||
}
|
||||
|
@ -373,7 +381,6 @@
|
|||
if (error.name === 'HTTPError' && (error.code == 401 || error.code == 403)) {
|
||||
Whisper.Registration.remove();
|
||||
Whisper.events.trigger('unauthorized');
|
||||
extension.install();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -523,50 +530,4 @@
|
|||
// Calling this directly so we can wait for completion
|
||||
return Whisper.DeliveryReceipts.onReceipt(receipt);
|
||||
}
|
||||
|
||||
window.owsDesktopApp = {
|
||||
getAppView: function(destWindow) {
|
||||
var self = this;
|
||||
|
||||
return ConversationController.loadPromise().then(function() {
|
||||
try {
|
||||
if (self.inboxView) { self.inboxView.remove(); }
|
||||
self.inboxView = new Whisper.InboxView({
|
||||
model: self,
|
||||
window: destWindow,
|
||||
initialLoadComplete: initialLoadComplete
|
||||
});
|
||||
self.openConversation(getOpenConversation());
|
||||
|
||||
return self.inboxView;
|
||||
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
});
|
||||
},
|
||||
openConversation: function(conversation) {
|
||||
if (this.inboxView && conversation) {
|
||||
this.inboxView.openConversation(null, conversation);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Whisper.events.on('unauthorized', function() {
|
||||
if (owsDesktopApp.inboxView) {
|
||||
owsDesktopApp.inboxView.networkStatusView.update();
|
||||
}
|
||||
});
|
||||
Whisper.events.on('reconnectTimer', function() {
|
||||
if (owsDesktopApp.inboxView) {
|
||||
owsDesktopApp.inboxView.networkStatusView.setSocketReconnectInterval(60000);
|
||||
}
|
||||
});
|
||||
|
||||
chrome.commands.onCommand.addListener(function(command) {
|
||||
if (command === 'show_signal') {
|
||||
openInbox();
|
||||
}
|
||||
});
|
||||
|
||||
})();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue