2015-01-19 01:43:25 +00:00
|
|
|
/*global $, Whisper, Backbone, textsecure, extension*/
|
2015-09-07 21:53:43 +00:00
|
|
|
/*
|
|
|
|
* vim: ts=4:sw=4:expandtab
|
2015-01-19 01:43:25 +00:00
|
|
|
*/
|
|
|
|
|
2015-01-22 04:27:42 +00:00
|
|
|
// This script should only be included in background.html
|
2015-01-19 01:43:25 +00:00
|
|
|
(function () {
|
2015-02-11 10:47:50 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
window.Whisper = window.Whisper || {};
|
|
|
|
|
2015-11-07 22:34:32 +00:00
|
|
|
|
2015-11-07 22:11:13 +00:00
|
|
|
window.isFocused = function() {
|
|
|
|
return inboxFocused;
|
|
|
|
};
|
|
|
|
window.isOpen = function() {
|
|
|
|
return inboxOpened;
|
|
|
|
};
|
2015-09-16 01:49:41 +00:00
|
|
|
|
2015-11-07 22:11:13 +00:00
|
|
|
window.drawAttention = function() {
|
|
|
|
if (inboxOpened && !inboxFocused) {
|
2017-08-24 23:22:01 +00:00
|
|
|
if (window.keepClear) {
|
|
|
|
clearInterval(window.keepClear);
|
|
|
|
delete window.keepClear;
|
|
|
|
}
|
2017-08-28 19:59:08 +00:00
|
|
|
console.log('draw attention');
|
2015-11-07 22:11:13 +00:00
|
|
|
extension.windows.drawAttention(inboxWindowId);
|
2015-03-17 22:06:21 +00:00
|
|
|
}
|
|
|
|
};
|
2016-04-11 22:27:39 +00:00
|
|
|
window.clearAttention = function() {
|
2017-08-28 19:59:08 +00:00
|
|
|
console.log('clear attention');
|
2017-08-24 23:22:01 +00:00
|
|
|
if (window.keepClear) {
|
|
|
|
clearInterval(window.keepClear);
|
|
|
|
delete window.keepClear;
|
|
|
|
}
|
2017-08-25 21:28:05 +00:00
|
|
|
window.keepClear = setInterval(function() {
|
|
|
|
extension.windows.clearAttention(inboxWindowId);
|
2017-08-24 23:22:01 +00:00
|
|
|
}, 2000);
|
2016-04-11 22:27:39 +00:00
|
|
|
};
|
2015-03-17 22:06:21 +00:00
|
|
|
|
2015-02-11 10:47:50 +00:00
|
|
|
/* Inbox window controller */
|
2015-11-02 07:44:15 +00:00
|
|
|
var inboxFocused = false;
|
2015-02-11 10:47:50 +00:00
|
|
|
var inboxOpened = false;
|
2015-05-23 00:10:01 +00:00
|
|
|
var inboxWindowId = 'inbox';
|
2015-09-16 01:49:41 +00:00
|
|
|
var appWindow = null;
|
2015-05-12 21:01:45 +00:00
|
|
|
window.openInbox = function() {
|
2016-02-27 23:30:02 +00:00
|
|
|
console.log('open inbox');
|
2015-02-11 10:47:50 +00:00
|
|
|
if (inboxOpened === false) {
|
|
|
|
inboxOpened = true;
|
2017-03-09 18:40:47 +00:00
|
|
|
owsDesktopApp.getAppView(window).then(function(appView) {
|
|
|
|
var bodyEl = $('body');
|
|
|
|
bodyEl.innerHTML = "";
|
|
|
|
bodyEl.append(appView.el);
|
2015-02-11 10:47:50 +00:00
|
|
|
});
|
2017-03-09 18:40:47 +00:00
|
|
|
owsDesktopApp.openConversation(getOpenConversation());
|
2015-02-11 10:47:50 +00:00
|
|
|
} else if (inboxOpened === true) {
|
2015-05-12 21:01:45 +00:00
|
|
|
extension.windows.focus(inboxWindowId, function (error) {
|
|
|
|
if (error) {
|
|
|
|
inboxOpened = false;
|
|
|
|
openInbox();
|
|
|
|
}
|
|
|
|
});
|
2015-01-22 04:27:42 +00:00
|
|
|
}
|
2015-05-12 21:01:45 +00:00
|
|
|
};
|
2015-05-15 20:54:29 +00:00
|
|
|
|
2015-11-10 19:19:57 +00:00
|
|
|
window.setUnreadCount = function(count) {
|
|
|
|
if (count > 0) {
|
|
|
|
extension.navigator.setBadgeText(count);
|
2016-02-20 01:19:04 +00:00
|
|
|
if (inboxOpened === true && appWindow) {
|
2015-11-10 19:19:57 +00:00
|
|
|
appWindow.contentWindow.document.title = "Signal (" + count + ")";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
extension.navigator.setBadgeText("");
|
2016-02-20 01:19:04 +00:00
|
|
|
if (inboxOpened === true && appWindow) {
|
2015-11-10 19:19:57 +00:00
|
|
|
appWindow.contentWindow.document.title = "Signal";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-09-05 01:33:14 +00:00
|
|
|
var open;
|
2015-09-14 03:25:04 +00:00
|
|
|
window.openConversation = function(conversation) {
|
2015-09-05 01:33:14 +00:00
|
|
|
if (inboxOpened === true) {
|
2017-04-10 19:45:58 +00:00
|
|
|
owsDesktopApp.openConversation(conversation);
|
2015-09-05 01:33:14 +00:00
|
|
|
} else {
|
|
|
|
open = conversation;
|
|
|
|
}
|
2015-09-16 03:41:48 +00:00
|
|
|
openInbox();
|
2015-09-14 03:25:04 +00:00
|
|
|
};
|
2015-09-05 01:33:14 +00:00
|
|
|
window.getOpenConversation = function() {
|
|
|
|
var o = open;
|
|
|
|
open = null;
|
|
|
|
return o;
|
|
|
|
};
|
2015-01-22 04:27:42 +00:00
|
|
|
})();
|