diff options
Diffstat (limited to 'plugins/uk.co.whiteoctober.cordova.appversion/www/AppVersionPlugin.js')
| -rw-r--r-- | plugins/uk.co.whiteoctober.cordova.appversion/www/AppVersionPlugin.js | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/plugins/uk.co.whiteoctober.cordova.appversion/www/AppVersionPlugin.js b/plugins/uk.co.whiteoctober.cordova.appversion/www/AppVersionPlugin.js new file mode 100644 index 00000000..3e395260 --- /dev/null +++ b/plugins/uk.co.whiteoctober.cordova.appversion/www/AppVersionPlugin.js @@ -0,0 +1,48 @@ +/*jslint indent: 2 */ +/*global window, jQuery, angular, cordova */ +"use strict"; + +// Returns a jQuery or AngularJS deferred object, or pass a success and fail callbacks if you don't want to use jQuery or AngularJS +var getPromisedCordovaExec = function (command, success, fail) { + var toReturn, deferred, injector, $q; + if (success === undefined) { + if (window.jQuery) { + deferred = jQuery.Deferred(); + toReturn = deferred; + } else if (window.angular) { + injector = angular.injector(["ng"]); + $q = injector.get("$q"); + deferred = $q.defer(); + toReturn = deferred.promise; + } else { + return console.error('AppVersion either needs a success callback, or jQuery/AngularJS defined for using promises'); + } + success = deferred.resolve; + fail = deferred.reject; + } + // 5th param is NOT optional. must be at least empty array + cordova.exec(success, fail, "AppVersion", command, []); + return toReturn; +}; + +var getAppVersion = function (success, fail) { + return getPromisedCordovaExec('getVersionNumber', success, fail); +}; + +getAppVersion.getAppName = function (success, fail) { + return getPromisedCordovaExec('getAppName', success, fail); +}; + +getAppVersion.getPackageName = function (success, fail) { + return getPromisedCordovaExec('getPackageName', success, fail); +}; + +getAppVersion.getVersionNumber = function (success, fail) { + return getPromisedCordovaExec('getVersionNumber', success, fail); +}; + +getAppVersion.getVersionCode = function (success, fail) { + return getPromisedCordovaExec('getVersionCode', success, fail); +}; + +module.exports = getAppVersion; |
