2015-01-18 15:43:25 -10:00
|
|
|
/*global $, Whisper, Backbone, textsecure, extension*/
|
2015-09-07 14:53:43 -07:00
|
|
|
/*
|
|
|
|
* vim: ts=4:sw=4:expandtab
|
2015-01-18 15:43:25 -10:00
|
|
|
*/
|
|
|
|
|
2015-01-21 18:27:42 -10:00
|
|
|
// This script should only be included in background.html
|
2015-01-18 15:43:25 -10:00
|
|
|
(function () {
|
2015-02-11 02:47:50 -08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
window.Whisper = window.Whisper || {};
|
|
|
|
|
2015-11-07 14:34:32 -08:00
|
|
|
|
2015-11-07 14:11:13 -08:00
|
|
|
window.isFocused = function() {
|
|
|
|
return inboxFocused;
|
|
|
|
};
|
|
|
|
window.isOpen = function() {
|
|
|
|
return inboxOpened;
|
|
|
|
};
|
2015-09-15 18:49:41 -07:00
|
|
|
|
2015-11-07 14:11:13 -08:00
|
|
|
window.drawAttention = function() {
|
|
|
|
if (inboxOpened && !inboxFocused) {
|
|
|
|
extension.windows.drawAttention(inboxWindowId);
|
2015-03-17 15:06:21 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-02-11 02:47:50 -08:00
|
|
|
/* Inbox window controller */
|
2015-11-01 23:44:15 -08:00
|
|
|
var inboxFocused = false;
|
2015-02-11 02:47:50 -08:00
|
|
|
var inboxOpened = false;
|
2015-05-22 17:10:01 -07:00
|
|
|
var inboxWindowId = 'inbox';
|
2015-09-15 18:49:41 -07:00
|
|
|
var appWindow = null;
|
2015-05-12 14:01:45 -07:00
|
|
|
window.openInbox = function() {
|
2016-02-27 15:30:02 -08:00
|
|
|
console.log('open inbox');
|
2015-02-11 02:47:50 -08:00
|
|
|
if (inboxOpened === false) {
|
|
|
|
inboxOpened = true;
|
|
|
|
extension.windows.open({
|
2015-05-12 14:01:45 -07:00
|
|
|
id: 'inbox',
|
2015-02-11 02:47:50 -08:00
|
|
|
url: 'index.html',
|
|
|
|
focused: true,
|
2015-08-25 16:47:15 -07:00
|
|
|
width: 580,
|
2015-07-29 11:23:56 -07:00
|
|
|
height: 440,
|
2015-09-18 13:12:10 -07:00
|
|
|
minWidth: 600,
|
|
|
|
minHeight: 360
|
2015-02-11 02:47:50 -08:00
|
|
|
}, function (windowInfo) {
|
2015-09-15 18:49:41 -07:00
|
|
|
appWindow = windowInfo;
|
2015-11-07 14:34:32 -08:00
|
|
|
inboxWindowId = appWindow.id;
|
2015-03-12 11:23:41 -07:00
|
|
|
|
2015-11-10 22:25:52 +02:00
|
|
|
appWindow.contentWindow.addEventListener('load', function() {
|
|
|
|
setUnreadCount(storage.get("unreadCount", 0));
|
|
|
|
});
|
|
|
|
|
2015-11-07 14:34:32 -08:00
|
|
|
appWindow.onClosed.addListener(function () {
|
2015-08-27 15:21:25 -07:00
|
|
|
inboxOpened = false;
|
2015-09-15 18:49:41 -07:00
|
|
|
appWindow = null;
|
2015-07-01 22:28:06 +02:00
|
|
|
});
|
2015-11-01 23:44:15 -08:00
|
|
|
|
|
|
|
appWindow.contentWindow.addEventListener('blur', function() {
|
|
|
|
inboxFocused = false;
|
|
|
|
});
|
|
|
|
appWindow.contentWindow.addEventListener('focus', function() {
|
|
|
|
inboxFocused = true;
|
2015-12-03 17:13:38 -08:00
|
|
|
extension.windows.clearAttention(inboxWindowId);
|
2015-11-01 23:44:15 -08:00
|
|
|
});
|
2015-07-01 22:28:06 +02:00
|
|
|
|
2015-11-08 10:40:37 -08:00
|
|
|
// close the inbox if background.html is refreshed
|
|
|
|
extension.windows.onSuspend(function() {
|
2015-03-12 11:23:41 -07:00
|
|
|
// TODO: reattach after reload instead of closing.
|
2015-07-01 22:28:06 +02:00
|
|
|
extension.windows.remove(inboxWindowId);
|
2015-03-12 11:23:41 -07:00
|
|
|
});
|
2015-02-11 02:47:50 -08:00
|
|
|
});
|
|
|
|
} else if (inboxOpened === true) {
|
2015-05-12 14:01:45 -07:00
|
|
|
extension.windows.focus(inboxWindowId, function (error) {
|
|
|
|
if (error) {
|
|
|
|
inboxOpened = false;
|
|
|
|
openInbox();
|
|
|
|
}
|
|
|
|
});
|
2015-01-21 18:27:42 -10:00
|
|
|
}
|
2015-05-12 14:01:45 -07:00
|
|
|
};
|
2015-05-15 13:54:29 -07:00
|
|
|
|
2015-11-10 21:19:57 +02:00
|
|
|
window.setUnreadCount = function(count) {
|
|
|
|
if (count > 0) {
|
|
|
|
extension.navigator.setBadgeText(count);
|
2016-02-19 17:19:04 -08:00
|
|
|
if (inboxOpened === true && appWindow) {
|
2015-11-10 21:19:57 +02:00
|
|
|
appWindow.contentWindow.document.title = "Signal (" + count + ")";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
extension.navigator.setBadgeText("");
|
2016-02-19 17:19:04 -08:00
|
|
|
if (inboxOpened === true && appWindow) {
|
2015-11-10 21:19:57 +02:00
|
|
|
appWindow.contentWindow.document.title = "Signal";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-09-04 18:33:14 -07:00
|
|
|
var open;
|
2015-09-13 20:25:04 -07:00
|
|
|
window.openConversation = function(conversation) {
|
2015-09-04 18:33:14 -07:00
|
|
|
if (inboxOpened === true) {
|
|
|
|
appWindow.contentWindow.openConversation(conversation);
|
|
|
|
} else {
|
|
|
|
open = conversation;
|
|
|
|
}
|
2015-09-15 20:41:48 -07:00
|
|
|
openInbox();
|
2015-09-13 20:25:04 -07:00
|
|
|
};
|
2015-09-04 18:33:14 -07:00
|
|
|
window.getOpenConversation = function() {
|
|
|
|
var o = open;
|
|
|
|
open = null;
|
|
|
|
return o;
|
|
|
|
};
|
2015-01-21 18:27:42 -10:00
|
|
|
})();
|