Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
MoAlyousef committed Feb 5, 2024
1 parent 3018597 commit cecb362
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 40 deletions.
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fltk-webview"
version = "0.4.1"
version = "0.4.2"
authors = ["MoAlyousef <mohammed.alyousef@neurosrg.com>", "Adia Robbie <adyaro37@gmail.com>"]
edition = "2021"
description = "Webview for embedded fltk windows"
Expand All @@ -12,9 +12,8 @@ readme = "README.md"
license = "MIT"

[dependencies]
# fltk = { version = "1.4", features = ["fltk-bundled"] }
fltk = "1.4"
fltk-webview-sys = { version = "0.3.2", path = "fltk-webview-sys" }
fltk-webview-sys = { version = "0.3.3", path = "fltk-webview-sys" }

# for the examples
[dev-dependencies]
Expand Down
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# fltk-webview

This provides webview functionality for embedded fltk windows.
The webview bindings are based on the [webview-official-sys crate](https://crates.io/crates/webview-official-sys), which was modified for use with FLTK and to use the static WebView2Loader library on Windows along with a newer version of webview.

## Usage
Add fltk-webview to your fltk application's Cargo.toml file:
Expand Down Expand Up @@ -44,11 +43,7 @@ fn main() {
- RHEL-based distros: `sudo dnf install webkit2gtk3-devel`.

## Known Issues
- On windows, building using the gnu toolchain will still require deploying the dlls (webview.dll and WebView2Loader.dlls), which can be found in the `target/<profile>` directory.
- On X11/wayland platforms:
- Need help with Gnome's mutter window manager fighting for ownership of the webview window, causing flickering in text fields!
- If running on Wayland, you need to pass the GDK_BACKEND=x11 environment variable for webkit2gtk to work properly.

The situation on linux is quite bad. It depends on whether you're running X11 or wayland. On wayland, this will use xwayland. On X11, I can't get embedding to work on Gnome's mutter window manager, which keeps fighting for ownership of the webview window, causing flickering or a blank screen!D=x11 environment variable for webkit2gtk to work properly.

![alt_test](screenshots/ex.jpg)

Expand Down
22 changes: 10 additions & 12 deletions examples/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@ use fltk::{app, prelude::*, window};
use fltk_webview::*;
use tinyjson::JsonValue;

const HTML: &str = r#"data:text/html,
const HTML: &str = r#"
<html>
<body>hello</body>
<body>
<p>hello</p>
<script>
window.onload = function() {
add(1, 2).then(function(res) {
document.body.innerText = `added, ${res}`;
});
say_hello('Mo').then(function(res) {
console.log(res);
});
window.onload = async () => {
document.body.innerText = `added, ${await add(1, 2)}`;
console.log(await say_hello('Mo'));
};
</script>
</body>
</html>"#;

fn main() {
Expand All @@ -33,7 +31,7 @@ fn main() {
win.show();

let wv = Webview::create(true, &mut wv_win);

wv.set_html(HTML);
wv.bind("add", |seq, content| {
println!("{}, {}", seq, content);
let parsed: JsonValue = content.parse().unwrap();
Expand All @@ -49,9 +47,9 @@ fn main() {
println!("{}, {}", seq, content);
let parsed: JsonValue = content.parse().unwrap();
let val: &String = parsed[0].get().unwrap();
wv.return_(seq, 0, &format!("Hello {}", val));
wv.return_(seq, 0, &format!("\"Hello {}\"", val));
});

wv.navigate(HTML);

app.run().unwrap();
}
33 changes: 18 additions & 15 deletions examples/dispatch.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use core::time;
use fltk::{app, prelude::*, window};
use fltk_webview::*;

// Work only on webkit, Egde doesn't.

const HTML: &str = r#"
<html>
<body>
Expand All @@ -26,26 +23,32 @@ fn main() {
win.make_resizable(true);
win.show();

let wv = Webview::create(true, &mut wv_win);
wv.set_html(HTML);
let mut wv = Webview::create(true, &mut wv_win);
wv.init(
r#"
var counter = function(s) {
var counter = (s) => {
let result = document.getElementById("result");
result.innerText = s;
};
"#,
);
wv.set_html(HTML);

// wv.dispatch(|wv| {
std::thread::spawn(move || {
let mut count = 0;
loop {
std::thread::sleep(time::Duration::from_millis(400));
let (s, r) = app::channel::<i32>();
wv.dispatch(move |_wv| {
std::thread::spawn(move || {
let mut count = 0;
loop {
std::thread::sleep(std::time::Duration::from_millis(400));
s.send(count);
count += 1;
}
});
});

while app.wait() {
if let Some(count) = r.recv() {
wv.eval(&format!("counter({})", count));
count += 1;
}
});
// });
app.run().unwrap();
}
}
2 changes: 1 addition & 1 deletion examples/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn main() {
let wv = Webview::create(true, &mut wv_win);
wv.init(
r#"
window.change = function() {
window.change = () => {
let result = document.getElementById("result");
result.innerText = "works";
};
Expand Down
5 changes: 3 additions & 2 deletions fltk-webview-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fltk-webview-sys"
version = "0.3.2"
version = "0.3.3"
authors = ["MoAlyousef <mohammed.alyousef@neurosrg.com>", "Adia Robbie <adyaro37@gmail.com>"]
edition = "2018"
description = "Webview for embedded fltk windows"
Expand All @@ -12,7 +12,8 @@ readme = "../README.md"
license = "MIT"

[dependencies]
wv-sys = "0.1.2"
wv = "0.1.0"
wv-sys = "0.1.3"

[build-dependencies]
pkg-config = "0.3"
Expand Down
3 changes: 2 additions & 1 deletion fltk-webview-sys/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub use wv_sys::*;
pub use wv_sys::*;
pub use wv::*;

0 comments on commit cecb362

Please sign in to comment.