From bd7f4febaa871ce4427492549ede81870f04a0e5 Mon Sep 17 00:00:00 2001 From: lilia Date: Wed, 3 May 2017 22:15:35 -0700 Subject: [PATCH] Remove dead code These are all unused, obsolete, or no-op functions at this point. // FREEBIE --- background.html | 1 - js/background.js | 2 - js/chromium.js | 246 ++-------------------------------- js/conversation_controller.js | 3 - js/conversation_panel.js | 28 ---- js/index.js | 30 ----- js/models/conversations.js | 2 +- js/notifications.js | 2 - js/panel_controller.js | 28 ---- 9 files changed, 9 insertions(+), 333 deletions(-) delete mode 100644 js/conversation_panel.js delete mode 100644 js/index.js delete mode 100644 js/panel_controller.js diff --git a/background.html b/background.html index 509cd600edce..cc5713c5d39e 100644 --- a/background.html +++ b/background.html @@ -784,7 +784,6 @@ - diff --git a/js/background.js b/js/background.js index 331a3f1404f0..dfc078b823c8 100644 --- a/js/background.js +++ b/js/background.js @@ -10,7 +10,6 @@ console.log('background page reloaded'); console.log('environment:', window.config.environment); - extension.notification.init(); var initialLoadComplete = false; @@ -61,7 +60,6 @@ console.log("listening for registration events"); Whisper.events.on('registration_done', function() { console.log("handling registration event"); - extension.keepAwake(); init(true); }); diff --git a/js/chromium.js b/js/chromium.js index dcf212750bbf..4826917b797a 100644 --- a/js/chromium.js +++ b/js/chromium.js @@ -6,253 +6,23 @@ // Browser specific functions for Chrom* window.extension = window.extension || {}; - window.extension.navigator = (function () { - var self = {}, - tabs = {}; - tabs.create = function (url) { - if (chrome.tabs) { - chrome.tabs.create({url: url}); - } else { - extension.windows.open({url: url}); - } - }; - self.tabs = tabs; - - self.setBadgeText = function (text) { - if (window.chrome && chrome.browserAction && chrome.browserAction.setBadgeText) { - chrome.browserAction.setBadgeText({text: String(text)}); - } - }; - - return self; - }()); - extension.windows = { - open: function(options, callback) { - if (chrome.windows) { - chrome.windows.create(options, callback); - } else if (chrome.app.window) { - var url = options.url; - delete options.url; - chrome.app.window.create(url, options, callback); - } - }, - - focus: function(id, callback) { - if (window.chrome && chrome.windows) { - chrome.windows.update(id, { focused: true }, function() { - callback(chrome.runtime.lastError); - }); - } else if (window.chrome && chrome.app.window) { - var appWindow = chrome.app.window.get(id); - if (appWindow) { - appWindow.show(); - appWindow.focus(); - callback(); - } else { - callback('No window found for id ' + id); - } - } - }, - - getCurrent: function(callback) { - if (chrome.windows) { - chrome.windows.getCurrent(callback); - } else if (chrome.app.window) { - callback(chrome.app.window.current()); - } - }, - - remove: function(windowId) { - if (chrome.windows) { - chrome.windows.remove(windowId); - } else if (chrome.app.window) { - chrome.app.window.get(windowId).close(); - } - }, - - getBackground: function(callback) { - var getBackground; - if (window.chrome && chrome.extension) { - var bg = chrome.extension.getBackgroundPage(); - bg.storage.onready(function() { - callback(bg); - resolve(); - }); - } else if (window.chrome && chrome.runtime) { - chrome.runtime.getBackgroundPage(function(bg) { - bg.storage.onready(function() { - callback(bg); - }); - }); - } - }, - - getAll: function() { - if (window.chrome) { - return chrome.app.window.getAll(); - } else { - return []; - } - }, - - getViews: function() { - if (chrome.extension) { - return chrome.extension.getViews(); - } else if (chrome.app.window) { - return chrome.app.window.getAll().map(function(appWindow) { - return appWindow.contentWindow; - }); - } - }, - - onSuspend: function(callback) { - if (chrome.runtime) { - chrome.runtime.onSuspend.addListener(callback); - } else { - window.addEventListener('beforeunload', callback); - } - }, onClosed: function(callback) { - // assumes only one front end window - if (window.chrome && chrome.app && chrome.app.window) { - return chrome.app.window.getAll()[0].onClosed.addListener(callback); - } else { - window.addEventListener('beforeunload', callback); - } - }, - - drawAttention: function(window_id) { - if (window.chrome && chrome.app.window) { - var w = chrome.app.window.get(window_id); - if (w) { - w.clearAttention(); - w.drawAttention(); - } - } - }, - - clearAttention: function(window_id) { - if (window.chrome && chrome.app.window) { - var w = chrome.app.window.get(window_id); - if (w) { - w.clearAttention(); - } - } - } - - }; - - extension.onLaunched = function(callback) { - if (window.chrome && chrome.browserAction && chrome.browserAction.onClicked) { - chrome.browserAction.onClicked.addListener(callback); - } - if (window.chrome && chrome.app && chrome.app.runtime) { - chrome.app.runtime.onLaunched.addListener(callback); + window.addEventListener('beforeunload', callback); } }; - // Translate - - if (window.chrome && window.chrome.i18n) { - window.i18n = function(message, substitutions) { - return chrome.i18n.getMessage(message, substitutions); - }; - - i18n.getLocale = function() { - if (window.chrome && chrome.i18n) { - return chrome.i18n.getUILanguage(); - } - return 'en'; - }; - } - - var notification_pending = Promise.resolve(); extension.notification = { - init: function() { - // register some chrome listeners - if (window.chrome && chrome.notifications) { - chrome.notifications.onClicked.addListener(function() { - extension.notification.clear(); - Whisper.Notifications.onclick(); - }); - chrome.notifications.onButtonClicked.addListener(function() { - extension.notification.clear(); - Whisper.Notifications.clear(); - getInboxCollection().each(function(model) { - model.markRead(); - }); - }); - chrome.notifications.onClosed.addListener(function(id, byUser) { - if (byUser) { - Whisper.Notifications.clear(); - } - }); - } - }, - clear: function() { - notification_pending = notification_pending.then(function() { - return new Promise(function(resolve) { - if (window.chrome) { - chrome.notifications.clear('signal', resolve); - } - }); - }); - }, update: function(options) { - if (window.chrome) { - var chromeOpts = { - type : options.type, - title : options.title, - message : options.message || '', // required - iconUrl : options.iconUrl, - imageUrl : options.imageUrl, - items : options.items, - buttons : options.buttons - }; - notification_pending = notification_pending.then(function() { - return new Promise(function(resolve) { - chrome.notifications.update('signal', chromeOpts, function(wasUpdated) { - if (!wasUpdated) { - chrome.notifications.create('signal', chromeOpts, resolve); - } else { - resolve(); - } - }); - }); - }); - } else { - var notification = new Notification(options.title, { - body : options.message, - icon : options.iconUrl, - tag : 'signal' - }); - notification.onclick = function() { - Whisper.Notifications.onclick(); - }; - } - } - }; - - extension.keepAwake = function() { - if (window.chrome && chrome && chrome.alarms) { - chrome.alarms.onAlarm.addListener(function() { - // nothing to do. + var notification = new Notification(options.title, { + body : options.message, + icon : options.iconUrl, + tag : 'signal' }); - chrome.alarms.create('awake', {periodInMinutes: 1}); + notification.onclick = function() { + Whisper.Notifications.onclick(); + }; } }; - if (window.chrome && chrome.runtime.onInstalled) { - chrome.runtime.onInstalled.addListener(function(options) { - if (options.reason === 'install') { - console.log('new install'); - extension.install(); - } else if (options.reason === 'update') { - console.log('new update. previous version:', options.previousVersion); - } else { - console.log('onInstalled', options.reason); - } - }); - } }()); diff --git a/js/conversation_controller.js b/js/conversation_controller.js index d1164f74ce0f..bb72755c36a5 100644 --- a/js/conversation_controller.js +++ b/js/conversation_controller.js @@ -69,9 +69,6 @@ window.setBadgeCount(0); window.document.title = "Signal"; } - if (newUnreadCount === 0) { - window.clearAttention(); - } }, startPruning: function() { var halfHour = 30 * 60 * 1000; diff --git a/js/conversation_panel.js b/js/conversation_panel.js deleted file mode 100644 index 385629c3d9a0..000000000000 --- a/js/conversation_panel.js +++ /dev/null @@ -1,28 +0,0 @@ -/*global $, Whisper, Backbone, textsecure, extension*/ -/* - * vim: ts=4:sw=4:expandtab - */ -(function () { - 'use strict'; - - window.Whisper = window.Whisper || {}; - - extension.windows.getCurrent(function (windowInfo) { - extension.windows.getBackground(function(bg) { - window.$ = bg.$; - var body = $('body', document); - var conversation = bg.getConversationForWindow(windowInfo.id); - if (conversation) { - window.document.title = conversation.getTitle(); - var view = new bg.Whisper.ConversationView({ - model: conversation, - appWindow: windowInfo - }); - view.$el.prependTo(body); - view.$('input.send-message').focus(); - } else { - $('
').text('Error').prependTo(body); - } - }); - }); -}()); diff --git a/js/index.js b/js/index.js deleted file mode 100644 index 64c4c706d31c..000000000000 --- a/js/index.js +++ /dev/null @@ -1,30 +0,0 @@ -/*global $, Whisper, Backbone, textsecure, extension*/ -/* - * vim: ts=4:sw=4:expandtab - */ -(function () { - 'use strict'; - - function logError(error) { - extension.windows.getBackground(function(bg) { - bg.console.log('index.html: ', error); - }); - } - - window.onerror = function(message, script, line, col, error) { - logError(error); - }; - - function render() { - extension.windows.getBackground(function(bg) { - bg.owsDesktopApp.getAppView(window).then(function(appView) { - var bodyEl = document.getElementById('signal-container'); - bodyEl.innerHTML = ""; - bodyEl.appendChild(appView.el); - }); - }); - } - - window.addEventListener('onreload', render); - render(); -}()); diff --git a/js/models/conversations.js b/js/models/conversations.js index f55f708e263e..cb235a9e7ef4 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -949,7 +949,7 @@ if (!message.isIncoming()) { return Promise.resolve(); } - if (window.isOpen() && window.isFocused()) { + if (window.isFocused()) { return Promise.resolve(); } diff --git a/js/notifications.js b/js/notifications.js index 80152e5fc5b1..0ea28b8b4530 100644 --- a/js/notifications.js +++ b/js/notifications.js @@ -30,7 +30,6 @@ }, update: function() { console.log('updating notifications', this.length); - extension.notification.clear(); if (this.length === 0) { return; } @@ -89,7 +88,6 @@ onRemove: function() { console.log('remove notification'); if (this.length === 0) { - extension.notification.clear(); return; } }, diff --git a/js/panel_controller.js b/js/panel_controller.js deleted file mode 100644 index cfec29c2384b..000000000000 --- a/js/panel_controller.js +++ /dev/null @@ -1,28 +0,0 @@ -/*global $, Whisper, Backbone, extension*/ -/* - * vim: ts=4:sw=4:expandtab - */ - -// This script should only be included in background.html -(function () { - 'use strict'; - - window.Whisper = window.Whisper || {}; - - window.isOpen = function() { - return true; - }; - - window.clearAttention = function() { - console.log('clear attention'); - if (window.keepClear) { - clearInterval(window.keepClear); - delete window.keepClear; - } - window.keepClear = setInterval(function() { - extension.windows.clearAttention(inboxWindowId); - }, 2000); - }; - var inboxWindowId = 'inbox'; - -})();