2015-01-19 01:43:25 +00:00
|
|
|
/*global $, Whisper, Backbone, textsecure, extension*/
|
|
|
|
/* 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/>.
|
|
|
|
*/
|
|
|
|
|
2015-01-22 04:27:42 +00:00
|
|
|
// This script should only be included in background.html
|
|
|
|
// Whisper.windowMap is defined in background.js
|
2015-01-19 01:43:25 +00:00
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
window.Whisper = window.Whisper || {};
|
|
|
|
|
2015-01-22 04:27:42 +00:00
|
|
|
var windowMap = Whisper.windowMap;
|
2015-01-19 01:43:25 +00:00
|
|
|
|
|
|
|
window.openConversation = function openConversation (modelId) {
|
2015-01-22 04:27:42 +00:00
|
|
|
|
|
|
|
var windowId = windowMap.windowIdFrom(modelId);
|
2015-01-19 01:43:25 +00:00
|
|
|
|
|
|
|
// prevent multiple copies of the same conversation from being opened
|
|
|
|
if (!windowId) {
|
2015-01-22 04:27:42 +00:00
|
|
|
// open the panel
|
2015-01-22 08:21:37 +00:00
|
|
|
extension.windows.open({
|
2015-01-19 01:43:25 +00:00
|
|
|
url: 'conversation.html',
|
|
|
|
type: 'panel',
|
|
|
|
focused: true,
|
|
|
|
width: 280,
|
|
|
|
height: 420
|
|
|
|
}, function (windowInfo) {
|
|
|
|
var idPairs = JSON.parse(localStorage.getItem('idPairs'));
|
|
|
|
var newWindowId = windowInfo.id;
|
|
|
|
|
2015-01-22 04:27:42 +00:00
|
|
|
windowMap.add({
|
|
|
|
windowId: windowInfo.id,
|
|
|
|
modelId: modelId
|
|
|
|
});
|
2015-01-19 01:43:25 +00:00
|
|
|
});
|
|
|
|
} else {
|
2015-01-22 04:27:42 +00:00
|
|
|
// focus the panel
|
2015-01-22 08:21:37 +00:00
|
|
|
extension.windows.focus(windowId, function () {
|
2015-01-22 04:27:42 +00:00
|
|
|
if (chrome.runtime.lastError) {
|
|
|
|
// panel isn't actually open...
|
|
|
|
window.closeConversation(windowId);
|
|
|
|
|
|
|
|
// ...and so we try again.
|
|
|
|
openConversation(modelId);
|
|
|
|
}
|
|
|
|
});
|
2015-01-19 01:43:25 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
window.closeConversation = function closeConversation (windowId) {
|
2015-01-22 04:27:42 +00:00
|
|
|
windowMap.remove('windowId', windowId);
|
2015-01-19 01:43:25 +00:00
|
|
|
};
|
2015-01-22 04:27:42 +00:00
|
|
|
})();
|