From 11249207f3367aab8c0f04fa430dd8c1f2b2fbf3 Mon Sep 17 00:00:00 2001
From: Pawel Andruszkiewicz
Date: Wed, 4 Nov 2015 10:01:26 +0100
Subject: [PATCH] Reworked mechanism of loading tizen-specific code of cordova
plugins.
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
---
src/cordova/cordova_api.js | 47 ++++++++++++++++++++++
src/device/cordova_device_api.js | 9 ++---
src/dialog/cordova_dialog_api.js | 9 ++---
src/file/js/File.js | 9 ++---
src/filetransfer/cordova_filetransfer_api.js | 11 ++---
src/globalization/cordova_globalization_api.js | 11 ++---
src/lib/cordova-5.1.1.js | 7 +---
src/media/cordova_media_api.js | 8 ++--
.../cordova_networkinformation_api.js | 11 ++---
9 files changed, 72 insertions(+), 50 deletions(-)
diff --git a/src/cordova/cordova_api.js b/src/cordova/cordova_api.js
index e3c42e3..0dd918a 100755
--- a/src/cordova/cordova_api.js
+++ b/src/cordova/cordova_api.js
@@ -15,3 +15,50 @@
*/
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);
+ }
+ }
+ }
+};
diff --git a/src/device/cordova_device_api.js b/src/device/cordova_device_api.js
index 0fdd748..b154467 100755
--- a/src/device/cordova_device_api.js
+++ b/src/device/cordova_device_api.js
@@ -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
diff --git a/src/dialog/cordova_dialog_api.js b/src/dialog/cordova_dialog_api.js
index a1f5aa6..0de4429 100755
--- a/src/dialog/cordova_dialog_api.js
+++ b/src/dialog/cordova_dialog_api.js
@@ -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
diff --git a/src/file/js/File.js b/src/file/js/File.js
index b342f45..51b67d0 100644
--- a/src/file/js/File.js
+++ b/src/file/js/File.js
@@ -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
diff --git a/src/filetransfer/cordova_filetransfer_api.js b/src/filetransfer/cordova_filetransfer_api.js
index 39858ee..39122d4 100755
--- a/src/filetransfer/cordova_filetransfer_api.js
+++ b/src/filetransfer/cordova_filetransfer_api.js
@@ -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
diff --git a/src/globalization/cordova_globalization_api.js b/src/globalization/cordova_globalization_api.js
index f6fc476..2594778 100755
--- a/src/globalization/cordova_globalization_api.js
+++ b/src/globalization/cordova_globalization_api.js
@@ -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
diff --git a/src/lib/cordova-5.1.1.js b/src/lib/cordova-5.1.1.js
index a63ff4e..135bba3 100644
--- a/src/lib/cordova-5.1.1.js
+++ b/src/lib/cordova-5.1.1.js
@@ -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();
diff --git a/src/media/cordova_media_api.js b/src/media/cordova_media_api.js
index c9fa2f9..8ae5bc1 100755
--- a/src/media/cordova_media_api.js
+++ b/src/media/cordova_media_api.js
@@ -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
diff --git a/src/networkinformation/cordova_networkinformation_api.js b/src/networkinformation/cordova_networkinformation_api.js
index 41cb857..1d5d582 100644
--- a/src/networkinformation/cordova_networkinformation_api.js
+++ b/src/networkinformation/cordova_networkinformation_api.js
@@ -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
--
2.7.4