2017-04-12 21:20:56 +00:00
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
window.Whisper = window.Whisper || {};
|
|
|
|
|
|
|
|
Whisper.AppView = Backbone.View.extend({
|
|
|
|
initialize: function(options) {
|
|
|
|
this.inboxView = null;
|
|
|
|
this.installView = null;
|
2017-09-14 22:03:53 +00:00
|
|
|
this.applyTheme();
|
2017-10-13 18:39:18 +00:00
|
|
|
this.applyHideMenu();
|
2017-04-25 00:59:11 +00:00
|
|
|
},
|
|
|
|
events: {
|
2017-04-25 01:45:18 +00:00
|
|
|
'click .openInstaller': 'openInstaller',
|
|
|
|
'click .openStandalone': 'openStandalone',
|
2017-04-25 00:59:11 +00:00
|
|
|
'openInbox': 'openInbox',
|
2017-10-13 18:39:18 +00:00
|
|
|
'change-theme': 'applyTheme',
|
|
|
|
'change-hide-menu': 'applyHideMenu',
|
2017-09-14 22:03:53 +00:00
|
|
|
},
|
|
|
|
applyTheme: function() {
|
|
|
|
var theme = storage.get('theme-setting') || 'android';
|
|
|
|
this.$el.removeClass('ios')
|
|
|
|
.removeClass('android-dark')
|
|
|
|
.removeClass('android')
|
|
|
|
.addClass(theme);
|
2017-04-12 21:20:56 +00:00
|
|
|
},
|
2017-10-13 18:39:18 +00:00
|
|
|
applyHideMenu: function() {
|
|
|
|
var hideMenuBar = storage.get('hide-menu-bar', false);
|
|
|
|
window.setAutoHideMenuBar(hideMenuBar);
|
|
|
|
window.setMenuBarVisibility(!hideMenuBar);
|
|
|
|
},
|
2017-04-19 17:34:19 +00:00
|
|
|
openView: function(view) {
|
|
|
|
this.el.innerHTML = "";
|
|
|
|
this.el.append(view.el);
|
2017-04-25 00:59:11 +00:00
|
|
|
this.delegateEvents();
|
2017-04-19 17:34:19 +00:00
|
|
|
},
|
2017-07-24 15:09:26 +00:00
|
|
|
openDebugLog: function() {
|
|
|
|
this.closeDebugLog();
|
|
|
|
this.debugLogView = new Whisper.DebugLogView();
|
|
|
|
this.debugLogView.$el.appendTo(this.el);
|
|
|
|
},
|
|
|
|
closeDebugLog: function() {
|
|
|
|
if (this.debugLogView) {
|
|
|
|
this.debugLogView.remove();
|
|
|
|
this.debugLogView = null;
|
|
|
|
}
|
|
|
|
},
|
2017-08-08 00:24:59 +00:00
|
|
|
openInstallChoice: function() {
|
|
|
|
this.closeInstallChoice();
|
|
|
|
var installChoice = this.installChoice = new Whisper.InstallChoiceView();
|
|
|
|
|
|
|
|
this.listenTo(installChoice, 'install-new', this.openInstaller.bind(this));
|
|
|
|
this.listenTo(installChoice, 'install-import', this.openImporter.bind(this));
|
|
|
|
|
|
|
|
this.openView(this.installChoice);
|
|
|
|
},
|
|
|
|
closeInstallChoice: function() {
|
|
|
|
if (this.installChoice) {
|
|
|
|
this.installChoice.remove();
|
|
|
|
this.installChoice = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
openImporter: function() {
|
|
|
|
this.closeImporter();
|
|
|
|
this.closeInstallChoice();
|
|
|
|
var importView = this.importView = new Whisper.ImportView();
|
|
|
|
this.listenTo(importView, 'cancel', this.openInstallChoice.bind(this));
|
|
|
|
this.openView(this.importView);
|
|
|
|
},
|
|
|
|
closeImporter: function() {
|
|
|
|
if (this.importView) {
|
|
|
|
this.importView.remove();
|
|
|
|
this.importView = null;
|
|
|
|
}
|
|
|
|
},
|
2017-04-12 21:20:56 +00:00
|
|
|
openInstaller: function() {
|
2017-04-19 17:34:19 +00:00
|
|
|
this.closeInstaller();
|
2017-08-08 00:24:59 +00:00
|
|
|
this.closeInstallChoice();
|
|
|
|
var installView = this.installView = new Whisper.InstallView();
|
|
|
|
this.listenTo(installView, 'cancel', this.openInstallChoice.bind(this));
|
2017-04-19 17:34:19 +00:00
|
|
|
this.openView(this.installView);
|
|
|
|
},
|
2017-08-08 00:24:59 +00:00
|
|
|
closeInstaller: function() {
|
|
|
|
if (this.installView) {
|
|
|
|
this.installView.remove();
|
|
|
|
this.installView = null;
|
|
|
|
}
|
|
|
|
},
|
2017-04-25 00:59:11 +00:00
|
|
|
openStandalone: function() {
|
|
|
|
if (window.config.environment !== 'production') {
|
|
|
|
this.closeInstaller();
|
|
|
|
this.installView = new Whisper.StandaloneRegistrationView();
|
|
|
|
this.openView(this.installView);
|
|
|
|
}
|
2017-04-19 17:34:19 +00:00
|
|
|
},
|
2017-04-12 21:20:56 +00:00
|
|
|
openInbox: function(options) {
|
|
|
|
options = options || {};
|
2017-08-10 22:56:47 +00:00
|
|
|
// The inbox can be created before the 'empty' event fires or afterwards. If
|
|
|
|
// before, it's straightforward: the onEmpty() handler below updates the
|
|
|
|
// view directly, and we're in good shape. If we create the inbox late, we
|
|
|
|
// need to be sure that the current value of initialLoadComplete is provided
|
|
|
|
// so its loading screen doesn't stick around forever.
|
|
|
|
|
|
|
|
// Two primary techniques at play for this situation:
|
|
|
|
// - background.js has two openInbox() calls, and passes initalLoadComplete
|
|
|
|
// directly via the options parameter.
|
|
|
|
// - in other situations openInbox() will be called with no options. So this
|
|
|
|
// view keeps track of whether onEmpty() has ever been called with
|
|
|
|
// this.initialLoadComplete. An example of this: on a phone-pairing setup.
|
|
|
|
_.defaults(options, {initialLoadComplete: this.initialLoadComplete});
|
2017-04-12 21:20:56 +00:00
|
|
|
|
|
|
|
console.log('open inbox');
|
2017-04-19 17:34:19 +00:00
|
|
|
this.closeInstaller();
|
2017-04-12 21:20:56 +00:00
|
|
|
|
|
|
|
if (!this.inboxView) {
|
2017-08-10 22:56:47 +00:00
|
|
|
// We create the inbox immediately so we don't miss an update to
|
|
|
|
// this.initialLoadComplete between the start of this method and the
|
|
|
|
// creation of inboxView.
|
2017-07-29 00:15:41 +00:00
|
|
|
this.inboxView = new Whisper.InboxView({
|
|
|
|
model: self,
|
|
|
|
window: window,
|
|
|
|
initialLoadComplete: options.initialLoadComplete
|
|
|
|
});
|
2017-04-12 21:20:56 +00:00
|
|
|
return ConversationController.loadPromise().then(function() {
|
2017-04-19 17:34:19 +00:00
|
|
|
this.openView(this.inboxView);
|
2017-04-12 21:20:56 +00:00
|
|
|
}.bind(this));
|
|
|
|
} else {
|
2017-05-02 23:27:26 +00:00
|
|
|
if (!$.contains(this.el, this.inboxView.el)) {
|
2017-04-19 17:34:19 +00:00
|
|
|
this.openView(this.inboxView);
|
2017-04-12 21:20:56 +00:00
|
|
|
}
|
|
|
|
window.focus(); // FIXME
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onEmpty: function() {
|
|
|
|
var view = this.inboxView;
|
2017-08-10 22:56:47 +00:00
|
|
|
|
|
|
|
this.initialLoadComplete = true;
|
2017-04-12 21:20:56 +00:00
|
|
|
if (view) {
|
|
|
|
view.onEmpty();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onProgress: function(count) {
|
|
|
|
var view = this.inboxView;
|
|
|
|
if (view) {
|
|
|
|
view.onProgress(count);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
openConversation: function(conversation) {
|
|
|
|
if (conversation) {
|
|
|
|
this.openInbox().then(function() {
|
2017-04-21 17:14:03 +00:00
|
|
|
this.inboxView.openConversation(null, conversation);
|
2017-04-12 21:20:56 +00:00
|
|
|
}.bind(this));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
})();
|