-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathappinfo.js
73 lines (60 loc) · 1.92 KB
/
appinfo.js
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
var exec = require('cordova/exec');
var channel = require('cordova/channel');
channel.createSticky('onAppInfoReady');
channel.waitForInitialization('onAppInfoReady');
function appInfo() {
this.version = null;
this.identifier = null;
this.build = null;
var me = this;
channel.onCordovaReady.subscribe(function() {
me.getAppInfo(function(info) {
me.version = info.version;
me.identifier = info.identifier;
me.build = info.build || 'unknown';
channel.onAppInfoReady.fire();
},function(e) {
console.log("[ERROR] Error initializing Cordova: " + e);
});
});
}
/**
* Get an object with the keys 'version', 'build' and 'identifier'.
*
* @param {Function} success Callback method called on success.
* @param {Function} fail Callback method called on failure.
*/
appInfo.prototype.getAppInfo = function(success, fail){
exec(success, fail, 'AppInfo', 'getAppInfo', []);
};
/**
* Get the version name.
*
* @param {Function} success Callback method called on success.
* @param {Function} fail Callback method called on failure.
*/
appInfo.prototype.getVersion = function(success, fail) {
exec(success, fail, 'AppInfo', 'getVersion', []);
}
/**
* Get the app identifier.
*
* @param {Function} success Callback method called on success.
* @param {Function} fail Callback method called on failure.
*/
appInfo.prototype.getIdentifier = function(success, fail){
exec(success, fail, 'AppInfo', 'getIdentifier', []);
}
// Override for browser platform
if (cordova.platformId==='browser') {
appInfo.prototype.getAppInfo = function (success, fail) {
success({identifier: '', version: ''})
}
appInfo.prototype.getVersion = function (success, fail) {
success('')
}
appInfo.prototype.getIdentifier = function(success, fail){
success('')
}
}
module.exports = new appInfo();