Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(android): improve initialization scripts implementation #670

Merged
merged 1 commit into from
Aug 24, 2022

Conversation

lucasfernog
Copy link
Member

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Docs
  • New Binding issue #___
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change?

  • Yes, and the changes were approved in issue #___
  • No

Checklist

  • When resolving issues, they are referenced in the PR's title (e.g fix: remove a typo, closes #___, #___)
  • A change file is added if any packages will require a version bump due to this PR per the instructions in the readme.
  • I have added a convincing reason for adding this feature, if necessary

Other information

Deleted RustWebChromeClient references, it's no longer needed.
The new RustWebViewClient.kt:

package com.tauri.api

import android.graphics.Bitmap
import android.webkit.*

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
    }

    override fun shouldInterceptRequest(
        view: WebView,
        request: WebResourceRequest
    ): WebResourceResponse? {
        return handleRequest(request)
    }

    companion object {
        init {
            System.loadLibrary("api")
        }
    }

    private external fun handleRequest(request: WebResourceRequest): WebResourceResponse?
}

@lucasfernog lucasfernog requested a review from a team as a code owner August 23, 2022 19:57
@wusyong wusyong merged commit 1b26d60 into dev Aug 24, 2022
@wusyong wusyong deleted the feat/improve-init-scripts-android branch August 24, 2022 06:04
@github-actions github-actions bot mentioned this pull request Aug 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants