aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlessio Vanni <vannilla@firemail.cc>2019-06-21 22:09:37 +0200
committerAlessio Vanni <vannilla@firemail.cc>2019-06-21 22:09:37 +0200
commitfa59204140f82c9516e9c4cb7afc2718abf5baaa (patch)
tree44d82355a0a89295449d7ab823854862c3800780
parentbdc82e65c4d30f541b5e0efcd3c0723103435c4e (diff)
downloadematrix-fa59204140f82c9516e9c4cb7afc2718abf5baaa.tar.lz
ematrix-fa59204140f82c9516e9c4cb7afc2718abf5baaa.tar.xz
ematrix-fa59204140f82c9516e9c4cb7afc2718abf5baaa.zip
Make some private entities public
Since things have been split, some of these have to be exposed to the rest of the world.
-rw-r--r--js/vapi-background.js50
-rw-r--r--js/vapi-tabs.js26
2 files changed, 39 insertions, 37 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 {
diff --git a/js/vapi-tabs.js b/js/vapi-tabs.js
index 4c9caf5..97d0f69 100644
--- a/js/vapi-tabs.js
+++ b/js/vapi-tabs.js
@@ -99,7 +99,7 @@
callback({
id: tabId,
- windowId: winWatcher.idFromWindow(win),
+ windowId: vAPI.window.idFromWindow(win),
active: tabBrowser !== null
&& browser === tabBrowser.selectedBrowser,
url: browser.currentURI.asciiSpec,
@@ -111,7 +111,7 @@
let win;
let tabs = [];
- for (let win of winWatcher.getWindows()) {
+ for (let win of vAPI.window.getWindows()) {
if (window && window !== win) {
continue;
}
@@ -229,7 +229,7 @@
return;
}
- let win = winWatcher.getCurrentWindow();
+ let win = vAPI.window.getCurrentWindow();
let tabBrowser = getTabBrowser(win);
if (tabBrowser === null) {
@@ -440,7 +440,7 @@
};
let currentBrowser = function () {
- let win = winWatcher.getCurrentWindow();
+ let win = vAPI.window.getCurrentWindow();
// https://github.com/gorhill/uBlock/issues/399
// getTabBrowser() can return null at browser launch time.
@@ -614,12 +614,12 @@
return false;
}
- return winWatcher.toBrowserWindow(window) !== null;
+ return vAPI.window.toBrowserWindow(window) !== null;
};
let onWindowLoad = function (win) {
- deferUntil(canAttachToTabBrowser.bind(null, win),
- attachToTabBrowser.bind(null, win));
+ vAPI.deferUntil(canAttachToTabBrowser.bind(null, win),
+ attachToTabBrowser.bind(null, win));
};
let onWindowUnload = function (win) {
@@ -679,7 +679,7 @@
let tabBrowser;
let tabs;
- for (let win of winWatcher.getWindows()) {
+ for (let win of vAPI.window.getWindows()) {
onWindowLoad(win);
tabBrowser = getTabBrowser(win);
@@ -694,8 +694,8 @@
}
}
- winWatcher.onOpenWindow = onWindowLoad;
- winWatcher.onCloseWindow = onWindowUnload;
+ vAPI.window.onOpenWindow = onWindowLoad;
+ vAPI.window.onCloseWindow = onWindowUnload;
vAPI.messaging.globalMessageManager
.addMessageListener(locationChangedMessageName,
@@ -703,14 +703,14 @@
};
let stop = function () {
- winWatcher.onOpenWindow = null;
- winWatcher.onCloseWindow = null;
+ vAPI.window.onOpenWindow = null;
+ vAPI.window.onCloseWindow = null;
vAPI.messaging.globalMessageManager
.removeMessageListener(locationChangedMessageName,
onLocationChanged);
- for (let win of winWatcher.getWindows()) {
+ for (let win of vAPI.window.getWindows()) {
onWindowUnload(win);
}