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: support callback function in eval #778

Merged
merged 12 commits into from Mar 23, 2023
Merged

Conversation

pewsheen
Copy link
Contributor

@pewsheen pewsheen commented Nov 29, 2022

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

This a draft for resolving issue #474. The API should expose to external after most of major platforms are implemented.

  • Callback closure in evaluate_script should be like | val: String | { ... }.
  • We will serialize the evaluated result into JSON string and pass it to the callback.
  • Error from the execution result will not pass to the callback closure due to varying formats returned by each platform. I think this is a minor issue, we can deal with this later.
  • TODO:
    • macOS
    • Unix
    • Windows
    • Android

Issues

@pewsheen pewsheen marked this pull request as ready for review March 21, 2023 08:07
@pewsheen pewsheen requested a review from a team as a code owner March 21, 2023 08:07
Cargo.toml Outdated Show resolved Hide resolved
src/webview/webkitgtk/mod.rs Outdated Show resolved Hide resolved
src/webview/webview2/mod.rs Outdated Show resolved Hide resolved
@wusyong
Copy link
Member

wusyong commented Mar 21, 2023

I think we can expose another method called evaluate_script_with_callback or something.
We can leave Android unimplemented and open an issue for it later.

@pewsheen
Copy link
Contributor Author

I was expected to pass Result<> to the callback if an exception was thrown during the execution. However, it seems that Windows does not return an error but instead responds with the string "null" in the execution result.

It'd be best to wrap a try...catch... clause at the top level of the script if you anticipate that exceptions could occur and you want to handle it.

src/webview/mod.rs Outdated Show resolved Hide resolved
Co-authored-by: Ngo Iok Ui (Wu Yu Wei) <yuweiwu@pm.me>
wusyong
wusyong previously approved these changes Mar 23, 2023
@wusyong wusyong merged commit 2647731 into tauri-apps:dev Mar 23, 2023
7 checks passed
@github-actions github-actions bot mentioned this pull request Mar 23, 2023
@pewsheen pewsheen deleted the eval-js branch March 23, 2023 06:00
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.

None yet

2 participants