Reworked mechanism of loading tizen-specific code of cordova plugins.
authorPawel Andruszkiewicz <p.andruszkie@samsung.com>
Wed, 4 Nov 2015 09:01:26 +0000 (10:01 +0100)
committerPawel Andruszkiewicz <p.andruszkie@samsung.com>
Thu, 5 Nov 2015 06:42:44 +0000 (07:42 +0100)
Tizen-specific code is now loaded after all the other plugins and only if it's required.

Change-Id: Ia69ada6161411b7622e136a16590905abf45f2d3
Signed-off-by: Pawel Andruszkiewicz <p.andruszkie@samsung.com>
src/cordova/cordova_api.js
src/device/cordova_device_api.js
src/dialog/cordova_dialog_api.js
src/file/js/File.js
src/filetransfer/cordova_filetransfer_api.js
src/globalization/cordova_globalization_api.js
src/lib/cordova-5.1.1.js
src/media/cordova_media_api.js
src/networkinformation/cordova_networkinformation_api.js

index e3c42e3..0dd918a 100755 (executable)
  */
 
 console.log('Loaded cordova API');
+
+exports = {
+  load: function(require) {
+    // delete this method
+    delete exports.load;
+
+    var plugins = [];
+
+    // mechanism to add Tizen-specific plugins to cordova
+    cordova.define('cordova-tizen', function(require, exports, module) {
+      module.exports = {
+        addPlugin: function(dependency, name, algorithm, symbol) {
+          plugins.push({
+            dependency: dependency,
+            name: name,
+            algorithm: algorithm,
+            symbol: symbol
+          });
+        }
+      };
+    });
+
+    var channel = require('cordova/channel');
+
+    // executed when all cordova plugins have been loaded
+    channel.onPluginsReady.subscribe(function() {
+      var mm = require('cordova/modulemapper');
+
+      // add plugins to module mapper, but only if they are required
+      // (their dependencies have been defined/loaded)
+      for (var i = 0; i < plugins.length; ++i) {
+        var p = plugins[i];
+        if (cordova.define.moduleMap[p.dependency]) {
+          mm[p.algorithm](p.name, p.symbol);
+        }
+      }
+    });
+
+    // load all native plugins
+    for (var prop in tizen.cordova) {
+      if (tizen.cordova.hasOwnProperty(prop)) {
+        console.log('Trying to load: tizen.cordova.' + prop);
+        tizen.cordova[prop](require);
+      }
+    }
+  }
+};
index 0fdd748..b154467 100755 (executable)
@@ -55,13 +55,10 @@ require("cordova/exec/proxy").add("Device", exports);
 
 console.log('Loaded cordova.device API');
 
-//TODO: remove when added to public cordova repository -> begin
+// TODO: remove when added to public cordova repository -> begin
 });
 
 exports = function(require) {
-  // this plugin is not loaded via cordova_plugins.js, we need to manually add
-  // it to module mapper
-  var mm = require('cordova/modulemapper');
-  mm.runs(plugin_name);
+  require('cordova-tizen').addPlugin('cordova-plugin-device.device', plugin_name, 'runs');
 };
-//TODO: remove -> end
+// TODO: remove -> end
index a1f5aa6..0de4429 100755 (executable)
@@ -322,13 +322,10 @@ require("cordova/exec/proxy").add("Notification", exports);
 
 console.log('Loaded cordova.dialog API');
 
-//TODO: remove when added to public cordova repository -> begin
+// TODO: remove when added to public cordova repository -> begin
 });
 
 exports = function(require) {
-  // this plugin is not loaded via cordova_plugins.js, we need to manually add
-  // it to module mapper
-  var mm = require('cordova/modulemapper');
-  mm.runs(plugin_name);
+  require('cordova-tizen').addPlugin('cordova-plugin-dialogs.notification', plugin_name, 'runs');
 };
-//TODO: remove -> end
+// TODO: remove -> end
index b342f45..51b67d0 100644 (file)
@@ -46,13 +46,10 @@ require("cordova/exec/proxy").add("File", exports);
 
 console.log('Loaded cordova.file API');
 
-//TODO: remove when added to public cordova repository -> begin
+// TODO: remove when added to public cordova repository -> begin
 });
 
 exports = function(require) {
-  // this plugin is not loaded via cordova_plugins.js, we need to manually add
-  // it to module mapper
-  var mm = require('cordova/modulemapper');
-  mm.runs(plugin_name);
+  require('cordova-tizen').addPlugin('cordova-plugin-file.File', plugin_name, 'runs');
 };
-//TODO: remove -> end
+// TODO: remove -> end
index 39858ee..39122d4 100755 (executable)
@@ -15,7 +15,7 @@
  */
 
 // TODO: remove when added to public cordova repository -> begin
-var plugin_name = 'cordova-plugin-file.tizen.FileTransfer';
+var plugin_name = 'cordova-plugin-file-transfer.tizen.FileTransfer';
 
 cordova.define(plugin_name, function(require, exports, module) {
 // TODO: remove -> end
@@ -210,13 +210,10 @@ require("cordova/exec/proxy").add("FileTransfer", exports);
 
 console.log('Loaded cordova.file-transfer API');
 
-//TODO: remove when added to public cordova repository -> begin
+// TODO: remove when added to public cordova repository -> begin
 });
 
 exports = function(require) {
-  // this plugin is not loaded via cordova_plugins.js, we need to manually add
-  // it to module mapper
-  var mm = require('cordova/modulemapper');
-  mm.runs(plugin_name);
+  require('cordova-tizen').addPlugin('cordova-plugin-file-transfer.FileTransfer', plugin_name, 'runs');
 };
-//TODO: remove -> end
+// TODO: remove -> end
index f6fc476..2594778 100755 (executable)
@@ -296,7 +296,7 @@ function Globalization_getCurrencyPattern(currencyCode, successCb, errorCb) {
 
 
 //TODO: remove when added to public cordova repository -> begin
-var plugin_name = 'cordova-plugin-device.tizen.Globalization';
+var plugin_name = 'cordova-plugin-globalization.tizen.Globalization';
 cordova.define(plugin_name, function(require, exports, module) {
 //TODO: remove -> end
   exports = {
@@ -339,12 +339,9 @@ cordova.define(plugin_name, function(require, exports, module) {
   };
   require("cordova/exec/proxy").add("Globalization", exports);
   console.log('Loaded cordova.globalization API');
-//TODO: remove when added to public cordova repository -> begin
+// TODO: remove when added to public cordova repository -> begin
 });
 exports = function(require) {
-//this plugin is not loaded via cordova_plugins.js, we need to manually add
-//it to module mapper
-  var mm = require('cordova/modulemapper');
-  mm.runs(plugin_name);
+  require('cordova-tizen').addPlugin('cordova-plugin-globalization.globalization', plugin_name, 'runs');
 };
-//TODO: remove -> end
+// TODO: remove -> end
index a63ff4e..135bba3 100644 (file)
@@ -1334,12 +1334,7 @@ module.exports = {
 
      modulemapper.clobbers('cordova/exec/proxy', 'cordova.commandProxy');
 
-     // load all Tizen plugins
-     for (var plugin in tizen.cordova) {
-       if (tizen.cordova.hasOwnProperty(plugin)) {
-         tizen.cordova[plugin](require);
-       }
-     }
+     tizen.cordova.load(require);
 
      channel.onNativeReady.fire();
 
index c9fa2f9..8ae5bc1 100755 (executable)
@@ -40,12 +40,10 @@ require("cordova/exec/proxy").add("Media", exports);
 
 console.log('Loaded cordova.media API');
 
-//TODO: remove when added to public cordova repository -> begin
+// TODO: remove when added to public cordova repository -> begin
 });
 
 exports = function(require) {
-  // this plugin is not loaded via cordova_plugins.js, we need to manually add
-  // it to module mapper
-  var mm = require('cordova/modulemapper');
-  mm.runs(plugin_name);
+  require('cordova-tizen').addPlugin('cordova-plugin-media.Media', plugin_name, 'runs');
 };
+// TODO: remove -> end
index 41cb857..1d5d582 100644 (file)
@@ -15,7 +15,7 @@
  */
 
 // TODO: remove when added to public cordova repository -> begin
-var plugin_name = 'cordova-plugin-file.tizen.NetworkStatus';
+var plugin_name = 'cordova-plugin-network-information.tizen.NetworkStatus';
 
 cordova.define(plugin_name, function(require, exports, module) {
 // TODO: remove -> end
@@ -82,13 +82,10 @@ require('cordova/exec/proxy').add('NetworkStatus', exports);
 
 console.log('Loaded cordova.networkinformation API');
 
-//TODO: remove when added to public cordova repository -> begin
+// TODO: remove when added to public cordova repository -> begin
 });
 
 exports = function(require) {
-  // this plugin is not loaded via cordova_plugins.js, we need to manually add
-  // it to module mapper
-  var mm = require('cordova/modulemapper');
-  mm.runs(plugin_name);
+  require('cordova-tizen').addPlugin('cordova-plugin-network-information.network', plugin_name, 'runs');
 };
-//TODO: remove -> end
+// TODO: remove -> end