 class QRReaderModule
-  notInApp: -> navigator.userAgent.indexOf("AppGyverSteroids") == -1
+  isInApp: ->
+    [navigator.userAgent, window.parent.navigator.userAgent]
+      .reduce ((value, userAgent) -> userAgent.indexOf("AppGyverSteroids") != -1 || value), false
 
   pluginAvailable: -> cordova?.plugins?.barcodeScanner?.scan?
 

    console.log "ERROR: #{errorMsg}"
    alert errorMsg

  openReader: =>
    if @notInApp()
      alert "This plugin is only supported in mobile apps."
    else if @pluginAvailable()
      cordova.plugins.barcodeScanner.scan @onScanResults, @onScanError
    else
      alert "Barcode Scanner Plugin not available!"

  setupButton: =>
    @onTap @btn, @openReader

    true

  #extract the collection name and id of the item
  parseCode: (code) ->
    parts = code.split(":")
    return {
      collection:parts[0]
