update check plugin: start of work on mobile case

This commit is contained in:
Jon Atkins 2013-11-09 20:33:41 +00:00
parent 56782f9440
commit e6f4c6d2c9

View File

@ -22,10 +22,22 @@
// use own namespace for plugin // use own namespace for plugin
window.plugin.updateCheck = function() {}; window.plugin.updateCheck = function() {};
window.plugin.updateCheck.url = 'http://iitc.jonatkins.com/versioncheck.php?build=@@BUILDNAME@@';
window.plugin.updateCheck.versionDataLoading = false; window.plugin.updateCheck.versionDataLoading = false;
window.plugin.updateCheck.getUrl = function(callback) {
var url = 'http://iitc.jonatkins.com/versioncheck.php'
+ '?build=@@BUILDNAME@@'
+ '&mobile='+((typeof android !== 'undefined' && android)?'1':'0');
if (callback) {
url = url + '&callback='+callback
}
return url;
}
window.plugin.updateCheck.versionCompare = function(a,b) { window.plugin.updateCheck.versionCompare = function(a,b) {
a = a.split('.'); a = a.split('.');
b = b.split('.'); b = b.split('.');
@ -51,9 +63,14 @@ window.plugin.updateCheck.loadVersionData = function() {
if (!window.plugin.updateCheck.versionDataLoading) { if (!window.plugin.updateCheck.versionDataLoading) {
window.plugin.updateCheck.versionDataLoading = true; window.plugin.updateCheck.versionDataLoading = true;
//TODO: IITC Mobile-specific parameter, to retrieve the mobile app version rather than the script versions
//also
// JSInterface public void updateIitc(String fileUrl)
//call on the android object to be able to download+install the android app.
var s = document.createElement('script'); var s = document.createElement('script');
s.setAttribute('type','text/javascript'); s.setAttribute('type','text/javascript');
s.setAttribute('src', window.plugin.updateCheck.url+'&callback=window.plugin.updateCheck.versionDataCallback'); s.setAttribute('src', window.plugin.updateCheck.getUrl('window.plugin.updateCheck.versionDataCallback'));
s.setAttribute('id','update-check-script-tag'); s.setAttribute('id','update-check-script-tag');
document.getElementsByTagName("head")[0].appendChild(s); document.getElementsByTagName("head")[0].appendChild(s);
@ -143,6 +160,33 @@ window.plugin.updateCheck.showReport = function(data) {
result += '<div>IITC update check: '+data.name+'</div>'; result += '<div>IITC update check: '+data.name+'</div>';
} }
if (typeof android !== 'undefined' && android) {
// mobile app version check
var ourVerCode = android.getVersionCode && android.getVersionCode() || 0;
var ourVerName = android.getVersionName && android.getVersionName() || '(unknown)';
if (data.mobile) {
var latestVerCode = parseInt(data.mobile.versioncode);
var latestVerName = data.mobile.versionstr;
if (ourVerCode == latestVerCode) {
// up to date
result += '<div>IITC Mobile is up to date - version <span="ver code "'+ourVerCode+'">'+ourVerName+'</span></div>';
} else if (ourVerCode < latestVerCode) {
// out of date
result += '<div>IITC Mobile is out of date. Current version <span="ver code "'+ourVerCode+'">'+ourVerName+'</span>, '
+ 'Available version <span="ver code "'+latestVerCode+'">'+latestVerName+'</span>.</div>';
} else {
// local version newer?!
result += '<div>IITC Mobile version newer than latest on server?! Current version <span="ver code "'+ourVerCode+'">'+ourVerName+'</span>, '
+ 'Available version <span="ver code "'+latestVerCode+'">'+latestVerName+'</span>.</div>';
}
} else {
result += '<div>Warning: no version data for mobile app found in response</div>';
}
} else {
// desktop userscript version check
if (data.iitc && window.script_info) { if (data.iitc && window.script_info) {
var compare = window.plugin.updateCheck.compareDetails(data.iitc, window.script_info); var compare = window.plugin.updateCheck.compareDetails(data.iitc, window.script_info);
result += '<div>IITC Main script: '+compare.html+'</div>'; result += '<div>IITC Main script: '+compare.html+'</div>';
@ -155,6 +199,7 @@ window.plugin.updateCheck.showReport = function(data) {
result += '<div>Warning: your IITC script does not contain version data</div>'; result += '<div>Warning: your IITC script does not contain version data</div>';
} }
} }
}
if (data.plugins && window.bootPlugins) { if (data.plugins && window.bootPlugins) {
@ -190,17 +235,22 @@ window.plugin.updateCheck.showReport = function(data) {
result += '<div>Plugins:<table>'; result += '<div>Plugins:<table>';
var formatRow = function(p) { var formatRow = function(p,weblink,downloadlink) {
var status = p.status; var status = p.status;
var name = p.name; var name = p.name;
var statustext = p.compare && p.compare.html || '-'; var statustext = p.compare && p.compare.html || '-';
var links = [];
if (weblink && p.compare && p.compare.webUrl) links.push('<a href="'+p.compare.webUrl+'" target="_blank">web</a>');
if (downloadlink && p.compare && p.compare.downloadUrl) links.push('<a href="'+p.compare.downloadUrl+'" target="_blank">download</a>');
//now convert to text
links = links && links.join(' ') || '-';
return '<tr class="'+status+'"><td>'+name+'</td><td>'+statustext+'</td></tr>'; return '<tr class="'+status+'"><td>'+name+'</td><td>'+statustext+'</td><td>'+links+'</td></tr>';
} }
result += '<tr><th colspan="3">Out of date</th></tr>'; result += '<tr><th colspan="3">Out of date</th></tr>';
for (var i in plugins.outOfDate) { for (var i in plugins.outOfDate) {
result += formatRow (plugins.outOfDate[i]); result += formatRow (plugins.outOfDate[i],true,true);
} }
if (plugins.outOfDate.length==0) { if (plugins.outOfDate.length==0) {
result += '<tr><td colspan="3">no plugins</td></tr>'; result += '<tr><td colspan="3">no plugins</td></tr>';
@ -208,7 +258,7 @@ window.plugin.updateCheck.showReport = function(data) {
result += '<tr><th colspan="3">Up To Date</th></tr>'; result += '<tr><th colspan="3">Up To Date</th></tr>';
for (var i in plugins.upToDate) { for (var i in plugins.upToDate) {
result += formatRow (plugins.upToDate[i]); result += formatRow (plugins.upToDate[i],true,false);
} }
if (plugins.upToDate.length==0) { if (plugins.upToDate.length==0) {
result += '<tr><td colspan="3">no plugins</td></tr>'; result += '<tr><td colspan="3">no plugins</td></tr>';
@ -216,7 +266,7 @@ window.plugin.updateCheck.showReport = function(data) {
result += '<tr><th colspan="3">Other</th></tr>'; result += '<tr><th colspan="3">Other</th></tr>';
for (var i in plugins.other) { for (var i in plugins.other) {
result += formatRow (plugins.other[i]); result += formatRow (plugins.other[i],true,false);
} }
if (plugins.other.length==0) { if (plugins.other.length==0) {
result += '<tr><td colspan="3">no plugins</td></tr>'; result += '<tr><td colspan="3">no plugins</td></tr>';