document.addEventListener('plusready', function() {
var first = null;
document.addEventListener("netchange",onNetChange,false);
function onNetChange(){
//Get the current network type
var nt = plus.networkinfo.getCurrentType();
switch(nt){
case plus.networkinfo.CONNECTION_ETHERNET:
case plus.networkinfo.CONNECTION_WIFI:
mui.toast("The network is connected");
break;
default:
mui.toast("The network has been disconnected");
break;
}
}
var webview = plus.webview.currentWebview();
plus.key.addEventListener('backbutton', function() {
document.addEventListener("netchange",onNetChange,false);
webview.canBack(function(e) {
if (e.canBack) {
webview.back();
} else {
if (!first) {
first = new Date().getTime();
mui.toast('Click again to exit the application');
setTimeout(function() {
first = null;
}, 1000);
} else {
if (new Date().getTime() - first < 1000) {
plus.runtime.quit();
}
}
}
})
});
//plus object upgrade
if(plus) {
var btn = ["Confirm upgrade", "Cancel"];
plus.runtime.getProperty(plus.runtime.appid, function(inf) {
ver = inf.version;
console.log(ver)
ajaxurl = "http://xxxxxxxx";//Backend address
$.ajax({
url: ajaxurl+'/common/version',
success: function(data) {
console.log(data)
console.log(data.result.version)
if (data.result.version != ver) {
var _msg = "Current version: V" + ver+", latest version number: V" + data.result.version;
// var _msg = "Current version: V" + data.result.version;
mui.confirm(_msg, 'Upgrade confirmation', btn, function(e) {
if (e.index == 0) { //Perform upgrade operation
plus.nativeUI.showWaiting( "The environment is being prepared, please wait patiently!" );
var dtask = plus.downloader.createDownload(data.result.downloadURL, {
}, function(d, status) {
if (status == 200) {
var path = d.filename; //Download apk
plus.runtime.install(path); // Automatically install apk files
plus.nativeUI.closeWaiting(); //After downloading, showwait disappears
} else {
plus.nativeUI.alert('Version update failed:' + status);
}
});
dtask.start();
}
});
} else {
mui.toast('The current version number is the latest');
return;
}
},
error: function(xhr, type, errerThrown) {
mui.toast('Network abnormality, please try again later');
}
});
});
}
});