mirror of
https://github.com/tauri-apps/tauri.git
synced 2025-01-03 08:36:07 +03:00
feat(android): improve initialization scripts (#5028)
This commit is contained in:
parent
0500d3b4b1
commit
641d56dcb3
3
examples/api/src-tauri/Cargo.lock
generated
3
examples/api/src-tauri/Cargo.lock
generated
@ -4223,8 +4223,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "wry"
|
||||
version = "0.20.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ea48fb3b68ab76f62837bfcea63baed9a185dbec9c14d4e5d70033e22fefffd2"
|
||||
source = "git+https://github.com/tauri-apps/wry?branch=dev#1b26d605d6e33f5417eb6566a7381d8feb239c8b"
|
||||
dependencies = [
|
||||
"block",
|
||||
"cocoa",
|
||||
|
@ -6,6 +6,9 @@ edition = "2021"
|
||||
rust-version = "1.57"
|
||||
license = "Apache-2.0 OR MIT"
|
||||
|
||||
[patch.crates-io]
|
||||
wry = { git = "https://github.com/tauri-apps/wry", branch = "dev" }
|
||||
|
||||
[lib]
|
||||
crate-type = ["staticlib", "cdylib", "rlib"]
|
||||
|
||||
|
@ -1,26 +0,0 @@
|
||||
package {{reverse-domain app.domain}}.{{snake-case app.name}}
|
||||
|
||||
import android.webkit.*
|
||||
|
||||
class RustWebChromeClient: WebChromeClient() {
|
||||
private var loadedUrl: String? = null
|
||||
|
||||
override fun onProgressChanged(view: WebView, progress: Int) {
|
||||
var url = view.url ?: ""
|
||||
if (url.endsWith("##")) {
|
||||
url = url.dropLast(2)
|
||||
}
|
||||
if (loadedUrl != url && progress >= 20) {
|
||||
loadedUrl = url
|
||||
runInitializationScripts()
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
init {
|
||||
System.loadLibrary("{{snake-case app.name}}")
|
||||
}
|
||||
}
|
||||
|
||||
private external fun runInitializationScripts()
|
||||
}
|
@ -1,8 +1,22 @@
|
||||
package {{reverse-domain app.domain}}.{{snake-case app.name}}
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.webkit.*
|
||||
|
||||
class RustWebViewClient: WebViewClient() {
|
||||
class RustWebViewClient(initScripts: Array<String>): WebViewClient() {
|
||||
private val initializationScripts: Array<String>
|
||||
|
||||
init {
|
||||
initializationScripts = initScripts
|
||||
}
|
||||
|
||||
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
|
||||
for (script in initializationScripts) {
|
||||
view?.evaluateJavascript(script, null)
|
||||
}
|
||||
super.onPageStarted(view, url, favicon)
|
||||
}
|
||||
|
||||
override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
|
||||
return false
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user