make extension open in popout window for edge 18

This commit is contained in:
Kyle Spearrin 2018-10-01 13:22:05 -04:00
parent 4fd0be7d07
commit 78a1e6036f
1 changed files with 18 additions and 31 deletions

View File

@ -12,37 +12,24 @@ if (process.env.ENV === 'production') {
enableProdMode(); enableProdMode();
} }
function bootstrapModule() { function init() {
if (BrowserApi.isEdge18) {
const inPopup = window.location.search === '' || window.location.search.indexOf('uilocation=') === -1 ||
window.location.search.indexOf('uilocation=popup') > -1;
if (inPopup) {
const bodyRect = document.querySelector('body').getBoundingClientRect();
chrome.windows.create({
url: 'popup/index.html?uilocation=popout',
type: 'popup',
width: bodyRect.width + 60,
height: bodyRect.height,
});
BrowserApi.closePopup(window);
return;
}
}
platformBrowserDynamic().bootstrapModule(AppModule, { preserveWhitespaces: true }); platformBrowserDynamic().bootstrapModule(AppModule, { preserveWhitespaces: true });
} }
// Bug in Edge 18 has null getBackgroundPage() result initially. Can be removed in future. init();
if (BrowserApi.getBackgroundPage() == null && BrowserApi.isEdge18) {
const sleep = (time: number) => new Promise((resolve) => window.setTimeout(resolve, time));
const bootstrapForEdge18 = async () => {
let bgAttempts = 1;
while (BrowserApi.getBackgroundPage() == null) {
if (bgAttempts > 30) {
break;
}
// tslint:disable-next-line
console.log('Waiting for background page to not be null. Attempt #' + bgAttempts);
await sleep(200);
bgAttempts++;
}
if (BrowserApi.getBackgroundPage() == null) {
// tslint:disable-next-line
console.log('Reload page.');
window.location.reload();
} else {
bootstrapModule();
}
};
bootstrapForEdge18();
} else {
if (BrowserApi.isEdge18) {
// tslint:disable-next-line
console.log('Normal bootstrap.');
}
bootstrapModule();
}