diff options
Diffstat (limited to 'js/vapi-background.js')
-rw-r--r-- | js/vapi-background.js | 50 |
1 files changed, 26 insertions, 24 deletions
diff --git a/js/vapi-background.js b/js/vapi-background.js index d939186..10f7b2b 100644 --- a/js/vapi-background.js +++ b/js/vapi-background.js @@ -41,28 +41,6 @@ Services.appinfo.ID === '{ec8030f7-c20a-464f-9b0e-13a3a9e97384}' && Services.vc.compare(Services.appinfo.version, '44') > 0; - let deferUntil = function (testFn, mainFn, details) { - let dtls = (typeof details !== 'object') ? {} : details; - let now = 0; - let next = dtls.next || 200; - let until = dtls.until || 2000; - - let check = function () { - if (testFn() === true || now >= until) { - mainFn(); - return; - } - now += next; - vAPI.setTimeout(check, next); - }; - - if ('sync' in dtls && dtls.sync === true) { - check(); - } else { - vAPI.setTimeout(check, 1); - } - }; - vAPI.app = { name: 'eMatrix', version: location.hash.slice(1), @@ -98,6 +76,28 @@ cleanupTasks.push(task); } + vAPI.deferUntil = function (testFn, mainFn, details) { + let dtls = (typeof details !== 'object') ? {} : details; + let now = 0; + let next = dtls.next || 200; + let until = dtls.until || 2000; + + let check = function () { + if (testFn() === true || now >= until) { + mainFn(); + return; + } + now += next; + vAPI.setTimeout(check, next); + }; + + if ('sync' in dtls && dtls.sync === true) { + check(); + } else { + vAPI.setTimeout(check, 1); + } + }; + window.addEventListener('unload', function () { // if (typeof vAPI.app.onShutdown === 'function') { // vAPI.app.onShutdown(); @@ -762,6 +762,8 @@ return api; })(); + vAPI.window = winWatcher; + let getTabBrowser = function (win) { return win && win.gBrowser || null; }; @@ -1961,7 +1963,7 @@ }; tbb.attachToNewWindow = function (win) { - deferUntil(canAddLegacyToolbarButton.bind(null, win), + vAPI.deferUntil(canAddLegacyToolbarButton.bind(null, win), addLegacyToolbarButton.bind(null, win)); }; @@ -2577,7 +2579,7 @@ 'addon-options-displayed', false); cleanupTasks.push(unregister); - deferUntil(canInit, init, { next: 463 }); + vAPI.deferUntil(canInit, init, { next: 463 }); }; return { |