From d934853b017e51a85f259df8159c8ca877a76dac Mon Sep 17 00:00:00 2001
From: Max Lynch <max@drifty.com>
Date: Tue, 24 Nov 2015 16:55:09 -0600
Subject: [PATCH] Shit

---
 README.md            |  2 +-
 gulpfile.js          |  4 ++--
 package.json         | 10 ++++++----
 src/cordova.js       |  3 +++
 src/index.js         | 16 +++++++++++-----
 src/plugin-config.js | 24 +++++++++++++++++++++++-
 test/app/app.js      | 44 +++++++++++++++++++++++++++++++++-----------
 test/app/index.html  |  2 +-
 8 files changed, 80 insertions(+), 25 deletions(-)

diff --git a/README.md b/README.md
index 9cf3598b..f6aab432 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,2 @@
-# ionic-native
+# Cordova Wrap
 Native plugins to replace ngCordova
diff --git a/gulpfile.js b/gulpfile.js
index 969bb5ae..8fb79870 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -13,14 +13,14 @@ function compile(watch) {
   var bundler = watchify(browserify()
   .require('./src/index.js', {
     entry: true,
-    expose: 'ionic-native'
+    expose: 'cordova-wrap'
   })
   .transform(babel, {presets: ['es2015']}));
 
   function rebundle() {
     bundler.bundle()
       .on('error', function(err) { console.error(err); this.emit('end'); })
-      .pipe(source('ionic-native.js'))
+      .pipe(source('cordova-wrap.js'))
       .pipe(buffer())
       .pipe(sourcemaps.init({ loadMaps: true }))
       .pipe(sourcemaps.write('./'))
diff --git a/package.json b/package.json
index ad54698c..ce51def7 100644
--- a/package.json
+++ b/package.json
@@ -2,23 +2,25 @@
   "name": "ionic-native",
   "version": "1.0.0",
   "description": "Native plugins to replace ngCordova",
-  "main": "gulpfile.js",
+  "main": "dist/cordova-wrap.js",
   "directories": {
     "test": "test"
   },
   "dependencies": {
+    "babel-polyfill": "^6.2.0",
     "babel-preset-es2015": "^6.1.18",
     "babelify": "^7.2.0",
     "browserify": "^12.0.1",
+    "es6-promise": "^3.0.2",
     "gulp": "^3.9.0",
+    "gulp-babel": "^6.1.0",
     "gulp-concat": "^2.6.0",
     "gulp-connect": "^2.2.0",
+    "gulp-serve": "^1.2.0",
     "gulp-sourcemaps": "^1.6.0",
     "vinyl-buffer": "^1.0.0",
     "vinyl-source-stream": "^1.1.0",
-    "watchify": "^3.6.1",
-    "gulp-babel": "^6.1.0",
-    "gulp-serve": "^1.2.0"
+    "watchify": "^3.6.1"
   },
   "devDependencies": {
     "babel-preset-stage-0": "^6.1.18"
diff --git a/src/cordova.js b/src/cordova.js
index 1f9d3f0c..a7d8a9b3 100644
--- a/src/cordova.js
+++ b/src/cordova.js
@@ -1,3 +1,6 @@
+import {Promise} from 'es6-promise';
+
+
 const promisifyCordova = (pluginObj, pluginName, methodName) => {
   return (...args) => {
     return new Promise((resolve, reject) => {
diff --git a/src/index.js b/src/index.js
index af48f957..c2e361fa 100644
--- a/src/index.js
+++ b/src/index.js
@@ -10,25 +10,31 @@ let promised;
 function newPluginClass(config) {
   let obj = {
     installed: () => {
-      return config.pluginRef && get(window, config.pluginRef);
+      return !!obj.plugin();
     },
 
-    plugin: config.plugin
+    // Get the plugin by checking the plugin ref path on window
+    plugin: () => {
+      return get(window, config.pluginRef)
+    },
+
+    pluginName: config.plugin
   };
 
   return obj;
 }
 
 // Go through each registered plugin
-for(let plugin of PluginConfig) {
-  console.log('Plugin', plugin.className, plugin);
+for(let i = 0; i < PluginConfig.length; i++) {
+  let plugin = PluginConfig[i];
 
   // Create the wrapped class
   let cls = newPluginClass(plugin);
 
   promised = plugin.promise || [];
 
-  for(let method of promised) {
+  for(let j = 0; j < promised.length; j++) {
+    let method = promised[j];
     let p = promisifyCordova(cls, plugin.id, method)
     cls[method] = p;
   }
diff --git a/src/plugin-config.js b/src/plugin-config.js
index 8ad90400..43128640 100644
--- a/src/plugin-config.js
+++ b/src/plugin-config.js
@@ -12,10 +12,32 @@ export var PluginConfig = [
     promise: ['takePicture'],
     pluginRef: 'navigator.camera'
   },
+  {
+    id: 'statusbar',
+    className: 'StatusBar',
+    plugin: 'cordova-plugin-statusbar',
+    pluginRef: 'StatusBar',
+    promise: ['show', 'hide', 'styleDefault', 'styleLightContent', 'styleBlackTranslucent', 'styleBlackOpaque']
+  },
   {
     id: 'applinks',
     className: 'AppLinks',
     plugin: 'com.lampa.startapp',
-    pluginRef: 'navigator.startApp'
+    pluginRef: 'navigator.startApp',
+    promise: ['start', 'check']
+  },
+  {
+    id: 'barcode',
+    className: 'Barcode',
+    plugin: 'phonegap-plugin-barcodescanner',
+    pluginRef: 'cordova.plugins.barcodeScanner',
+    promise: ['scan', 'encode']
+  },
+  {
+    id: 'camera-roll',
+    className: 'CameraRoll',
+    plugin: 'cordova-plugin-camera-roll',
+    pluginRef: 'CameraRoll',
+    promise: ['saveToCameraRoll', 'getPhotos']
   },
 ]
diff --git a/test/app/app.js b/test/app/app.js
index 80f9199b..d0b82bee 100644
--- a/test/app/app.js
+++ b/test/app/app.js
@@ -1,13 +1,35 @@
-console.log(window.Native);
 
+document.addEventListener('deviceready', function() {
 
-if(Native.Camera.installed()) {
-  console.log('Camera installed');
-} else {
-  console.log('Camera not installed');
-}
-Native.Camera.takePicture().then(function(resp) {
-  console.log('Got picture');
-}, function(err) {
-  console.log('ERROR');
-});
+  console.log(window.Native);
+
+  alert('in here!');
+
+  if(Native.Camera.installed()) {
+    alert('here!');
+    console.log('Camera installed');
+  } else {
+    alert('No cam');
+    console.log('Camera not installed');
+  }
+  Native.Camera.takePicture().then(function(resp) {
+    console.log('Got picture');
+  }, function(err) {
+    console.log('ERROR');
+  });
+
+  if(Native.AppLinks.installed()) {
+    console.log('AppLinks installed');
+  } else {
+    console.log('AppLinks not installed');
+  }
+
+  if(Native.StatusBar.installed()) {
+    console.log('StatusBar installed');
+    Native.StatusBar.styleBlackTranslucent();
+  } else {
+    alert('No statusbar');
+    console.log('StatusBar not installed');
+  }
+
+})
diff --git a/test/app/index.html b/test/app/index.html
index 0d4439e1..81687f13 100644
--- a/test/app/index.html
+++ b/test/app/index.html
@@ -1,7 +1,7 @@
 <!doctype html>
 <html>
   <head>
-    <script src="../../dist/ionic-native.js"></script>
+    <script src="../../dist/cordova-wrap.js"></script>
     <script src="app.js"></script>
   </head>
   <body>