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 log(m){document.getElementById('log').innerText+=m+'\n'}
|
||||||
function checkUpdate(){
|
function checkUpdate(){
|
||||||
var manFile='/h5/manifest-'+channel+'.json';
|
log('manifest via Bridge ...');
|
||||||
log('checking '+manFile+' ...');
|
var resp=Android.fetchManifest(channel);
|
||||||
fetch(BASE+manFile+'?t='+Date.now(),{cache:'no-store'})
|
try{
|
||||||
.then(function(r){if(!r.ok)throw Error('HTTP '+r.status);return r.json()})
|
var j=JSON.parse(resp);
|
||||||
.then(function(j){log('latest: '+j.latest+' min: '+j.min_version);
|
if(j.error){log('ERR: '+j.error);return}
|
||||||
|
log('latest: '+j.latest+' min: '+j.min_version);
|
||||||
if(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,'');
|
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}
|
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;
|
var myVer=document.getElementById('ver').textContent;
|
||||||
if(j.latest!==myVer&&j.latest!=='v'+myVer&&'v'+j.latest!==myVer){dlVer=j.latest;
|
if(j.latest!==myVer&&j.latest!=='v'+myVer&&'v'+j.latest!==myVer){dlVer=j.latest;
|
||||||
log('*** NEW VERSION ***');document.getElementById('btnApply').disabled=false}
|
log('*** NEW VERSION ***');document.getElementById('btnApply').disabled=false}
|
||||||
else log('up to date')})
|
else log('up to date')
|
||||||
.catch(function(e){log('ERR: '+e.message)})
|
}catch(e){log('ERR: '+e.message)}
|
||||||
}
|
}
|
||||||
function applyUpdate(){
|
function applyUpdate(){
|
||||||
fetch(dlUrl+'?t='+Date.now(),{cache:'no-store'})
|
var t=Android.fetchText(('h5/index-'+dlVer).replace('0.1.0-dav-android-','v')+'.html');
|
||||||
.then(function(r){if(!r.ok)throw Error('HTTP '+r.status);return r.text()})
|
if(typeof t!=='string'||t.startsWith('ERROR:')){log('ERR: '+t);return}
|
||||||
.then(function(t){
|
if(!dlSha||dlSha.startsWith('TBD')){log('ERR: SHA256 required');return}
|
||||||
if(!dlSha){log('ERR: SHA256 required');return}
|
|
||||||
var h=Android.sha256(t);
|
var h=Android.sha256(t);
|
||||||
if(h!==dlSha){log('SHA256 MISMATCH!');return}
|
if(h!==dlSha){log('SHA256 MISMATCH!');return}
|
||||||
Android.saveCache(t);log('OK! restart app to apply')
|
Android.saveCache(t);log('OK! restart app to apply')
|
||||||
})
|
|
||||||
.catch(function(e){log('ERR: '+e.message)})
|
|
||||||
}
|
}
|
||||||
</script></body></html>
|
</script></body></html>
|
||||||
|
|||||||
Binary file not shown.
@@ -24,16 +24,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
settings.domStorageEnabled = true
|
settings.domStorageEnabled = true
|
||||||
settings.allowFileAccess = true
|
settings.allowFileAccess = true
|
||||||
addJavascriptInterface(Bridge(this@MainActivity), "Android")
|
addJavascriptInterface(Bridge(this@MainActivity), "Android")
|
||||||
webViewClient = object : WebViewClient() {
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cacheFile.exists()) {
|
if (cacheFile.exists()) {
|
||||||
val html = cacheFile.readText()
|
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