1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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;
|