From 69ba6581b0ea66d4ab8f4d56a820842886f1e716 Mon Sep 17 00:00:00 2001 From: Marco Date: Tue, 27 May 2014 23:12:14 +0200 Subject: [PATCH] moved some chromium-specific code into chromium.js (using extension.navigator namespace) --- js/background.js | 4 ++-- js/chromium.js | 18 ++++++++++++++++++ js/popup.js | 4 ++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/js/background.js b/js/background.js index de17e4a1..deb59463 100644 --- a/js/background.js +++ b/js/background.js @@ -17,7 +17,7 @@ textsecure.registerOnLoadFunction(function() { if (!localStorage.getItem('first_install_ran')) { localStorage.setItem('first_install_ran', 1); - chrome.tabs.create({url: "options.html"}); + extension.navigator.tabs.create("options.html"); } else { if (isRegistrationDone()) { textsecure.subscribeToPush(function(message) { @@ -26,7 +26,7 @@ textsecure.registerOnLoadFunction(function() { ': "' + getString(message.message.body) + '"'); var newUnreadCount = textsecure.storage.getUnencrypted("unreadCount", 0) + 1; textsecure.storage.putUnencrypted("unreadCount", newUnreadCount); - chrome.browserAction.setBadgeText({text: newUnreadCount + ""}); + extension.navigator.setBadgeText(newUnreadCount); }); } } diff --git a/js/chromium.js b/js/chromium.js index 8036f4e2..cbd9c087 100644 --- a/js/chromium.js +++ b/js/chromium.js @@ -14,6 +14,24 @@ * along with this program. If not, see . */ +window.extension = window.extension || {}; + +window.extension.navigator = function() { + var self = {}; + + var tabs = {}; + tabs.create = function(url){ + chrome.tabs.create({url: url}); + }; + self.tabs = tabs; + + self.setBadgeText = function(text){ + chrome.browserAction.setBadgeText({text: text + ""}); + }; + + return self; +}(); + // Random shared utilities that are used only by chromium things function registrationDone() { diff --git a/js/popup.js b/js/popup.js index 87ec8fc2..9e7ba264 100644 --- a/js/popup.js +++ b/js/popup.js @@ -17,11 +17,11 @@ textsecure.registerOnLoadFunction(function() { if (textsecure.storage.getUnencrypted("number_id") === undefined) { - chrome.tabs.create({url: "options.html"}); + extension.navigator.tabs.create("options.html"); } else { $('.my-number').text(textsecure.storage.getUnencrypted("number_id").split(".")[0]); textsecure.storage.putUnencrypted("unreadCount", 0); - chrome.browserAction.setBadgeText({text: ""}); + extension.navigator.setBadgeText(""); $("#me").click(function() { $('#popup_send_numbers').val($('.my-number').text()); });