Skip to content

Commit

Permalink
Convert to async xhr (#839)
Browse files Browse the repository at this point in the history
* Convert to async xhr

Resolves #820

* Move load outside forEach
  • Loading branch information
RobbieTheWagner authored Jul 27, 2018
1 parent c6be063 commit c207685
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions app/adapters/web-extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ export default BasicAdapter.extend({
},

_injectDebugger() {
chrome.devtools.inspectedWindow.eval(loadEmberDebug());
this.onResourceAdded();
loadEmberDebug().then((emberDebug) => {
chrome.devtools.inspectedWindow.eval(emberDebug);
this.onResourceAdded();
});
},

_setThemeColors() {
Expand All @@ -68,7 +70,7 @@ export default BasicAdapter.extend({
document.body.classList.add(theme);
},

onResourceAdded(/*callback*/) {},
onResourceAdded(/*callback*/) { },

willReload() {
this._injectDebugger();
Expand Down Expand Up @@ -99,28 +101,42 @@ export default BasicAdapter.extend({
scripts as soon as possible into the new page.
*/
reloadTab() {
chrome.devtools.inspectedWindow.reload({
injectedScript: loadEmberDebug()
loadEmberDebug().then((emberDebug) => {
chrome.devtools.inspectedWindow.reload({ injectedScript: emberDebug });
});

},

canOpenResource: false,

sendIframes(urls) {
urls.forEach(url => {
chrome.devtools.inspectedWindow.eval(loadEmberDebug(), { frameURL: url });
loadEmberDebug().then((emberDebug) => {
urls.forEach(url => {
chrome.devtools.inspectedWindow.eval(emberDebug, { frameURL: url });
});
});
}
});

function loadEmberDebug() {
let minimumVersion = config.emberVersionsSupported[0].replace(/\./g, '-');
let xhr;
if (!emberDebug) {
xhr = new XMLHttpRequest();
xhr.open("GET", chrome.runtime.getURL(`/panes-${minimumVersion}/ember_debug.js`), false);
xhr.send();
emberDebug = xhr.responseText;
}
return emberDebug;
return new Promise((resolve) => {
if (!emberDebug) {
xhr = new XMLHttpRequest();
xhr.open("GET", chrome.runtime.getURL(`/panes-${minimumVersion}/ember_debug.js`));
xhr.onload = function() {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
emberDebug = xhr.responseText;
resolve(emberDebug);
}
}
};

xhr.send();
} else {
resolve(emberDebug);
}
});
}

0 comments on commit c207685

Please sign in to comment.