]> git.r.bdr.sh - rbdr/junction/commitdiff
Add chrome compatibility
authorRuben Beltran del Rio <redacted>
Sun, 27 Sep 2020 16:14:53 +0000 (18:14 +0200)
committerRuben Beltran del Rio <redacted>
Sun, 27 Sep 2020 16:14:53 +0000 (18:14 +0200)
CHANGELOG.md
README.md
extension/junction.js

index 0d49813c5c47575c80ba9a9ff0102cd2ce360cd0..f8a499d9377dbcf73bf063d1f1eb1bac9b24f567 100644 (file)
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 ### Added
 - This changelog
 - Firefox extension configuration
+- Chrome extension configuration
 - Rudimentary state control in the extension
 
 [Unreleased]: https://gitlab.com/rbdr/junction/compare/v1.0.0...HEAD
index 9e420d34a0c58b5aead57236bd383063dbac894d..036203a4b55f1df927312fb0255d1a7882ddf4f1 100644 (file)
--- a/README.md
+++ b/README.md
@@ -11,3 +11,9 @@ on the `This Firefox` option. Then click on `Load Temporary Add-On` and
 point the browser to the `extension/manifest.json` file.
 
 This will enable the extension and will allow you to use the inspector to debug.
+
+### Testing on Chrome
+
+In order to test on chrome, first go to `chrome://extensions/`. Make sure
+`Developer mode` is enabled. Then click `Load Unpacked` and point the browser
+to the `extension` directory.
index 7de7c28012e5f8781f5fca622402745c48a7f17a..575a716b20d83c825898befe01cb225e68578c48 100644 (file)
@@ -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);