95f8e3921c
As a chrome packaged app, we have to keep at least one window open in order to maintain our websocket connection in the background page. This change replaces the system window frame with custom buttons in the inbox header, such that the 'close' button merely hides the window rather than unloading it. Fixes #237 FREEBIE
107 lines
4 KiB
JavaScript
107 lines
4 KiB
JavaScript
/* vim: ts=4:sw=4:expandtab
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
(function () {
|
|
'use strict';
|
|
|
|
window.Whisper = window.Whisper || {};
|
|
|
|
extension.windows.getBackground(function(bg) {
|
|
var SocketView = Whisper.View.extend({
|
|
className: 'status',
|
|
initialize: function() {
|
|
setInterval(function() {
|
|
var className, message = '';
|
|
switch(bg.getSocketStatus && bg.getSocketStatus()) {
|
|
case WebSocket.CONNECTING:
|
|
className = 'connecting';
|
|
break;
|
|
case WebSocket.OPEN:
|
|
className = 'open';
|
|
break;
|
|
case WebSocket.CLOSING:
|
|
className = 'closing';
|
|
break;
|
|
case WebSocket.CLOSED:
|
|
className = 'closed';
|
|
message = 'Websocket closed';
|
|
break;
|
|
}
|
|
if (!this.$el.hasClass(className)) {
|
|
this.$el.attr('class', className);
|
|
this.$el.text(message);
|
|
}
|
|
}.bind(this), 1000);
|
|
},
|
|
events: {
|
|
'click': 'reloadBackgroundPage'
|
|
},
|
|
reloadBackgroundPage: function() {
|
|
bg.location.reload();
|
|
}
|
|
});
|
|
|
|
Whisper.InboxView = Whisper.View.extend({
|
|
template: $('#inbox').html(),
|
|
className: 'inbox',
|
|
initialize: function (options) {
|
|
this.render();
|
|
|
|
this.newConversationView = new Whisper.NewConversationView();
|
|
this.newConversationView.$el.hide();
|
|
this.listenTo(this.newConversationView, 'open',
|
|
this.openConversation.bind(this, null));
|
|
|
|
this.inbox = new Whisper.ConversationListView({
|
|
el : this.$('.conversations'),
|
|
collection : bg.inbox
|
|
}).render();
|
|
|
|
this.inbox.listenTo(bg.inbox, 'sort', this.inbox.render);
|
|
|
|
new SocketView().render().$el.appendTo(this.$('.socket-status'));
|
|
|
|
extension.windows.beforeUnload(function() {
|
|
this.inbox.stopListening();
|
|
}.bind(this));
|
|
|
|
new Whisper.WindowControlsView({
|
|
appWindow: options.appWindow
|
|
}).$el.appendTo(this.$('#header'));
|
|
},
|
|
events: {
|
|
'click .fab': 'showCompose',
|
|
'select .contact': 'openConversation',
|
|
},
|
|
openConversation: function(e, data) {
|
|
bg.openConversation(data.modelId);
|
|
this.hideCompose();
|
|
},
|
|
showCompose: function() {
|
|
this.newConversationView.reset();
|
|
this.$el.hide();
|
|
this.newConversationView.$el.insertAfter(this.$el);
|
|
this.newConversationView.$el.show();
|
|
this.newConversationView.$input.focus();
|
|
this.listenToOnce(this.newConversationView, 'back', this.hideCompose);
|
|
},
|
|
hideCompose: function() {
|
|
this.newConversationView.$el.hide();
|
|
this.$el.show();
|
|
}
|
|
});
|
|
});
|
|
|
|
})();
|