Skip to content

Commit

Permalink
Merge pull request #84 from marcel-ernst/master
Browse files Browse the repository at this point in the history
add browser platform
  • Loading branch information
sampart authored Sep 3, 2019
2 parents 5d6430f + 9cb7910 commit a5ae663
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
13 changes: 13 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,17 @@

<source-file src="src/wp8/AppVersion.cs" />
</platform>

<!-- browser -->
<platform name="browser">
<config-file target="config.xml" parent="/*">
<feature name="AppVersion">
<param name="browser-package" value="AppVersion" />
</feature>
</config-file>

<js-module src="src/browser/AppVersionProxy.js" name="AppVersionProxy">
<runs />
</js-module>
</platform>
</plugin>
75 changes: 75 additions & 0 deletions src/browser/AppVersionProxy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
"use strict";

var cache = null;

function readConfig(success, fail) {
if(cache === null) {
var xhr = new XMLHttpRequest();
xhr.addEventListener("load", function () {
try {
var parser = new DOMParser();
var doc = parser.parseFromString(xhr.responseText, "application/xml");
var widget = doc.getElementsByTagName("widget").item(0);

cache = {
appVersion: widget.getAttribute('version'),
appName: widget.getElementsByTagName("name").item(0).textContent,
packageName: widget.getAttribute('id'),
versionCode: widget.getAttribute('browser-versionCode')
};
success(cache);
}
catch(e) {
fail(e);
}
});

xhr.addEventListener("error", function () {
fail(e);
});
xhr.open("get", "../config.xml", true);
xhr.send();
}
else {
setTimeout(function() {
success(cache);
},0);
}
}


var getAppVersion = function (success, fail) {
readConfig(function(data) {
success(data.appVersion);
}, fail);
};

getAppVersion.getAppName = function (success, fail) {
readConfig(function(data) {
success(data.appName);
}, fail);
};

getAppVersion.getPackageName = function (success, fail) {
readConfig(function(data) {
success(data.packageName);
}, fail);
};

getAppVersion.getVersionNumber = function (success, fail) {
readConfig(function(data) {
success(data.appVersion);
}, fail);
};

getAppVersion.getVersionCode = function (success, fail) {
readConfig(function(data) {
success(data.versionCode);
}, fail);
};

module.exports = getAppVersion;


require("cordova/exec/proxy").add("AppVersion", module.exports);

0 comments on commit a5ae663

Please sign in to comment.