fix: v6页checkUpdate+applyUpdate全用Bridge(移除fetch+CSP误伤)
This commit is contained in:
@@ -45,11 +45,12 @@ function selectCh(el,ch){
|
||||
}
|
||||
function log(m){document.getElementById('log').innerText+=m+'\n'}
|
||||
function checkUpdate(){
|
||||
var manFile='/h5/manifest-'+channel+'.json';
|
||||
log('checking '+manFile+' ...');
|
||||
fetch(BASE+manFile+'?t='+Date.now(),{cache:'no-store'})
|
||||
.then(function(r){if(!r.ok)throw Error('HTTP '+r.status);return r.json()})
|
||||
.then(function(j){log('latest: '+j.latest+' min: '+j.min_version);
|
||||
log('manifest via Bridge ...');
|
||||
var resp=Android.fetchManifest(channel);
|
||||
try{
|
||||
var j=JSON.parse(resp);
|
||||
if(j.error){log('ERR: '+j.error);return}
|
||||
log('latest: '+j.latest+' min: '+j.min_version);
|
||||
if(j.min_version){
|
||||
var v=j.min_version.replace(/[^0-9]/g,''),my=document.getElementById('ver').textContent.replace(/[^0-9]/g,'');
|
||||
if(parseInt(my)<parseInt(v)){log('ERR: too old, need APK update');return}
|
||||
@@ -60,18 +61,15 @@ function checkUpdate(){
|
||||
var myVer=document.getElementById('ver').textContent;
|
||||
if(j.latest!==myVer&&j.latest!=='v'+myVer&&'v'+j.latest!==myVer){dlVer=j.latest;
|
||||
log('*** NEW VERSION ***');document.getElementById('btnApply').disabled=false}
|
||||
else log('up to date')})
|
||||
.catch(function(e){log('ERR: '+e.message)})
|
||||
else log('up to date')
|
||||
}catch(e){log('ERR: '+e.message)}
|
||||
}
|
||||
function applyUpdate(){
|
||||
fetch(dlUrl+'?t='+Date.now(),{cache:'no-store'})
|
||||
.then(function(r){if(!r.ok)throw Error('HTTP '+r.status);return r.text()})
|
||||
.then(function(t){
|
||||
if(!dlSha){log('ERR: SHA256 required');return}
|
||||
var h=Android.sha256(t);
|
||||
if(h!==dlSha){log('SHA256 MISMATCH!');return}
|
||||
Android.saveCache(t);log('OK! restart app to apply')
|
||||
})
|
||||
.catch(function(e){log('ERR: '+e.message)})
|
||||
var t=Android.fetchText(('h5/index-'+dlVer).replace('0.1.0-dav-android-','v')+'.html');
|
||||
if(typeof t!=='string'||t.startsWith('ERROR:')){log('ERR: '+t);return}
|
||||
if(!dlSha||dlSha.startsWith('TBD')){log('ERR: SHA256 required');return}
|
||||
var h=Android.sha256(t);
|
||||
if(h!==dlSha){log('SHA256 MISMATCH!');return}
|
||||
Android.saveCache(t);log('OK! restart app to apply')
|
||||
}
|
||||
</script></body></html>
|
||||
|
||||
Binary file not shown.
@@ -24,16 +24,7 @@ class MainActivity : AppCompatActivity() {
|
||||
settings.domStorageEnabled = true
|
||||
settings.allowFileAccess = true
|
||||
addJavascriptInterface(Bridge(this@MainActivity), "Android")
|
||||
webViewClient = object : WebViewClient() {
|
||||
override fun onPageFinished(view: WebView, url: String) {
|
||||
view.evaluateJavascript("""
|
||||
var meta = document.createElement('meta');
|
||||
meta.httpEquiv = 'Content-Security-Policy';
|
||||
meta.content = "default-src 'none'; script-src 'unsafe-inline'; connect-src 'none'";
|
||||
document.head.appendChild(meta);
|
||||
""".trimIndent(), null)
|
||||
}
|
||||
}
|
||||
webViewClient = object : WebViewClient() {}
|
||||
|
||||
if (cacheFile.exists()) {
|
||||
val html = cacheFile.readText()
|
||||
|
||||
1
window_dump.xml
Normal file
1
window_dump.xml
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user