From 0a3c03025b374fe6a7664307d196102f3e2e93c0 Mon Sep 17 00:00:00 2001 From: lilia Date: Thu, 6 Nov 2014 17:01:56 -0800 Subject: [PATCH] Abstract nativeclient callback logic The nativeclient.js module overrides window.textsecure.registerOnLoadFunction with its own version. Otherwise helpers will define a trivial placeholder for same. The flag textsecure.NATIVE_CLIENT can be set anywhere ahead of nativeclient.js, but is only acted on in nativeclient.js, and crypto.js. --- js/helpers.js | 18 +++--------------- js/nativeclient.js | 5 +++++ 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/js/helpers.js b/js/helpers.js index 0cebb359..14542701 100644 --- a/js/helpers.js +++ b/js/helpers.js @@ -205,21 +205,9 @@ window.textsecure.throwHumanError = function(error, type, humanError) { throw e; } -;(function() { - 'use strict'; - window.textsecure = window.textsecure || {}; - window.textsecure.NATIVE_CLIENT = window.textsecure.NATIVE_CLIENT || true; - - if (!textsecure.NATIVE_CLIENT) { - window.textsecure.registerOnLoadFunction = window.textsecure.nativeclient.registerOnLoadFunction; - } else { - window.textsecure.registerOnLoadFunction = function(func) { - return new Promise(function(resolve, reject) { - return resolve(func()); - }); - }; - } -})(); +window.textsecure.registerOnLoadFunction = textsecure.registerOnLoadFunction || function(func) { + return Promise.resolve(func()); +}; window.textsecure.replay = function() { var self = {}; diff --git a/js/nativeclient.js b/js/nativeclient.js index 441f44b4..24f8fcaf 100644 --- a/js/nativeclient.js +++ b/js/nativeclient.js @@ -16,6 +16,11 @@ ;(function() { 'use strict'; window.textsecure = window.textsecure || {}; + window.textsecure.NATIVE_CLIENT = window.textsecure.NATIVE_CLIENT || true; + + if (!textsecure.NATIVE_CLIENT) { + window.textsecure.registerOnLoadFunction = window.textsecure.nativeclient.registerOnLoadFunction; + } var naclMessageNextId = 0; var naclMessageIdCallbackMap = {};