X-Git-Url: https://git.r.bdr.sh/rbdr/junction/blobdiff_plain/1ed219c8314a0ca1b95ef8593bb608b7659c87a3..27a1c981529492981f08bb1c0ece4cb5d615c19b:/extension/junction.js?ds=inline diff --git a/extension/junction.js b/extension/junction.js index 7de7c28..575a716 100644 --- a/extension/junction.js +++ b/extension/junction.js @@ -1,5 +1,6 @@ const internals = { + promisesSupported: !!(window.browser), isInCallState: false, icons: { @@ -26,12 +27,11 @@ const internals = { internals.isInCallState = true; internals.setIcon('hangUp'); - const tabs = await browser.tabs.query({ - currentWindow: true, - active: true - }); + console.log('setting tabs'); + const activeTabs = await internals.getActiveTabs(); - internals.createAudioElement(browser.runtime.getURL('sounds/tada.wav')); + console.log(activeTabs[0].url); // placeholder while we connect backend. + internals.createAudioElement(internals.getRoot().runtime.getURL('sounds/tada.wav')); }, hangUp() { @@ -41,11 +41,12 @@ const internals = { internals.isInCallState = false; }, - createAudioElement(source) { + createAudioElement(source, type = 'audio/wav') { const audioElement = document.createElement('audio'); audioElement.src = source; audioElement.autoplay = 'autoplay'; + audioElement.type = type; document.querySelector('body').appendChild(audioElement); }, @@ -55,10 +56,37 @@ const internals = { setIcon(iconSet) { - browser.browserAction.setIcon({ + internals.getRoot().browserAction.setIcon({ path: internals.icons[iconSet] }); - } + }, + + getRoot() { + + return window.browser || window.chrome; + }, + + // Chrome doesn't yet implement the promise based tabs.query :'( + + getActiveTabs() { + + const query = { + currentWindow: true, + active: true + }; + + if (internals.promisesSupported) { + return internals.getRoot().tabs.query(query); + } + + return new Promise((resolve, reject) => { + + internals.getRoot().tabs.query(query, (tabs) => { + + return resolve(tabs); + }); + }); + }, }; -browser.browserAction.onClicked.addListener(internals.onClick); +internals.getRoot().browserAction.onClicked.addListener(internals.onClick);