/**
 * THIS FILE WILL BE OVERWRITTEN.
 * DO NOT EDIT.
 **/

/* global chrome */

import Bridge from '../bridge'
import { uid } from 'quasar'

export default function connect () {
  window.QBexInit({
    connect (cb) {
      const
        // If we don't get an id, generate one so we have a unique connection to whatever it is.
        // this could be the popup window or the options window (As they don't have tab ids)
        tabId = chrome.devtools ? chrome.devtools.inspectedWindow.tabId : uid(),
        port = chrome.runtime.connect({
          name: tabId ? 'app:' + tabId : 'app'
        })

      let disconnected = false
      port.onDisconnect.addListener(() => {
        disconnected = true
      })

      let bridge = new Bridge({
        listen (fn) {
          port.onMessage.addListener(fn)
        },
        send (data) {
          if (!disconnected) {
            port.postMessage(data)
          }
        }
      })

      cb(bridge)
    },
    onReload (reloadFn) {
      window.addEventListener('beforeunload', reloadFn)
    }
  })
}

@@ -178,335 +178,55 @@
 %7B%0A  
-window.QBexInit(%7B%0A    connect (cb) %7B%0A      const%0A        // If we don't get an id, generate one so we have a unique connection to whatever it is.%0A        // this could be the popup window or the options window (As they don't have tab ids)%0A        tabId = chrome.devtools ? chrome.devtools.inspectedWindow.tabId : uid(),%0A       
+const buildConnection = (id, cb) =%3E %7B%0A    const
  por
@@ -264,25 +264,13 @@
     
-    
 name:
- tabId ?
  'ap
@@ -279,34 +279,19 @@
 ' + 
-tabId : 'app'%0A    
+id%0A
     %7D)%0A%0A
     
@@ -278,34 +278,32 @@
 :' + id%0A    %7D)%0A%0A
-  
     let disconne
@@ -315,18 +315,16 @@
 = false%0A
-  
     port
@@ -363,18 +363,16 @@
 %7B%0A      
-  
 disconne
@@ -387,26 +387,24 @@
 rue%0A    
-  
 %7D)%0A%0A    
   let br
@@ -395,18 +395,16 @@
 %7D)%0A%0A    
-  
 let brid
@@ -427,18 +427,16 @@
 %7B%0A      
-  
 listen (
@@ -445,26 +445,24 @@
 ) %7B%0A        
-  
 port.onMessa
@@ -486,18 +486,16 @@
 )%0A      
-  
 %7D,%0A     
@@ -495,18 +495,16 @@
 ,%0A      
-  
 send (da
@@ -505,26 +505,24 @@
 nd (data) %7B%0A
-  
         if (
@@ -544,26 +544,24 @@
 %7B%0A          
-  
 port.postMes
@@ -571,24 +571,30 @@
 e(data)%0A    
+    %7D%0A
       %7D%0A    
@@ -597,40 +597,729 @@
     
-    %7D%0A      %7D)%0A%0A      cb(bridge)
+%7D)%0A%0A    cb(bridge)%0A  %7D%0A%0A  window.QBexInit(%7B%0A    connect (cb) %7B%0A      if (chrome.tabs && !chrome.devtools) %7B%0A        // If we're on a web browser tab, use the current tab id to connect to the app.%0A        chrome.tabs.getCurrent(tab =%3E %7B%0A          buildConnection(tab.id, cb)%0A        %7D)%0A      %7D else %7B%0A        // If we're not in a proper web browser tab, generate an id so we have a unique connection to whatever it is.%0A        // this could be the popup window or the options window (As they don't have tab ids)%0A        // If dev tools is available, it means we're on it. Use that for the id.%0A        const tabId = chrome.devtools ? chrome.devtools.inspectedWindow.tabId : uid()%0A        buildConnection(tabId, cb)%0A      %7D%0A
 %0A   

Fix regression in content script communication #76 (#5570)