Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yamadapc/rust-darwin-webkit
bindings to some of the WebKit's API on MacOS for Rust
https://github.com/yamadapc/rust-darwin-webkit
Last synced: 2 months ago
JSON representation
bindings to some of the WebKit's API on MacOS for Rust
- Host: GitHub
- URL: https://github.com/yamadapc/rust-darwin-webkit
- Owner: yamadapc
- License: mit
- Created: 2019-01-05T06:55:15.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-08-12T20:32:28.000Z (5 months ago)
- Last Synced: 2024-10-11T22:53:46.912Z (3 months ago)
- Language: Rust
- Homepage:
- Size: 13 MB
- Stars: 9
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rust-darwin-webkit
![](https://github.com/yamadapc/rust-darwin-webkit/workflows/Rust/badge.svg)
![](https://github.com/yamadapc/rust-darwin-webkit/workflows/Documentation/badge.svg)
![Crates.io](https://img.shields.io/crates/v/darwin-webkit)* [**Documentation**](https://yamadapc.github.io/rust-darwin-webkit/darwin_webkit/)
* [**Crate on crates.io**](https://crates.io/crates/darwin-webkit)- - -
**darwin_webkit** exposes bindings to some of the WebKit's API on MacOS for
Rust. It uses the `objc` and `cocoa` crates to bind with Objective-C.**This has not been tested properly yet.**
Can be embedded onto audio plug-ins by getting the native webview handle and
adding it to a plug-ins native `NSWindowView` handle.**Closure captures are unsafe as we'll just pass pointers around.**
## Install
```
cargo add darwin-webkit
```## Example
```rust
use darwin_webkit::helpers::dwk_app::DarwinWKApp;fn main() {
unsafe {
let app = DarwinWKApp::new("Simple WebView");
let webview = app.create_webview();
webview.load_url("https://www.google.com.br");
app.set_webview(&webview);
app.run();
}
}
```## Communication example
```rust
use cocoa::base::id;
use darwin_webkit::helpers::dwk_app::DarwinWKApp;
use std::rc::Rc;fn main() {
unsafe {
let app = DarwinWKApp::new("Host an app");
let webview = Rc::new(app.create_webview());let callback = Box::into_raw(Box::new(Box::new(|_: id, _: id| {
println!("JavaScript called rust!");
webview.evaluate_javascript("document.body.innerHTML += ' -> response from rust';");
})));
webview.add_message_handler("hello", callback);
webview.load_html_string(
"
document.body.innerHTML += 'start';
window.webkit.messageHandlers.hello.postMessage('hello');
document.body.innerHTML += ' -> success';
",
"",
);app.set_webview(&webview);
app.run();
}
}
```## Missing
- ~~Callbacks from JavaScript to Rust.~~
- TODOs in raw bindings
* `serverTrust` in `WKWebView`
* In `NSURLRequest`
* Working with a Cache Policy
* Accessing Request Components
* Getting Header Fields
* Controlling Request Behavior
* Accessing the Service Type
* Supporting Secure Coding
- ...## Linting
```bash
cargo clippy
```