sciter-sdk / rust-sciter

Rust bindings for Sciter
https://sciter.com
MIT License
804 stars 75 forks source link

Can't call JavaScript #100

Closed GirkovArpa closed 2 years ago

GirkovArpa commented 3 years ago

JavaScript cannot be called when using the Sciter.JS library. Nothing happens, except it returns Ok(undefined).

fn document_complete(&mut self, root: HELEMENT, _target: HELEMENT) {
  let value = &Element::from(root).call_function("foo", &make_args!("bar"));
  println!("{:?}", value); // Ok(undefined)
}
pravic commented 3 years ago

http://sciter.com/forums - better to ask there. Sciter.Js have some surprising decisions, so no idea what is working on that version and what isn't.

GirkovArpa commented 3 years ago

Very well then.

GirkovArpa commented 3 years ago

The workaround I'm using is, since JS can call Rust but not vice-versa, is have JS simply keep asking Rust if it needs to do anything, and act based on the response.

pravic commented 3 years ago

Not an efficient decision. What was the answer on sciter forums?

GirkovArpa commented 3 years ago

I have not asked yet 😛

Nikola526 commented 2 years ago

I got it to work with:

let root = Element::from_window(frame.get_hwnd()).unwrap();
root.eval_script("Window.this.Test()").unwrap();
GirkovArpa commented 2 years ago

Got it working with this:

impl sciter::EventHandler for EventHandler {
    fn get_subscription(&mut self) -> Option<sciter::dom::event::EVENT_GROUPS> {
        Some(
            sciter::dom::event::default_events()
                | sciter::dom::event::EVENT_GROUPS::HANDLE_METHOD_CALL,
        )
    }
}
pravic commented 2 years ago

@GirkovArpa Wait, the title says "cannot call JS" and you are talking about "cannot be called from JS". Also, default_events() does include HANDLE_METHOD_CALL by default: https://github.com/sciter-sdk/rust-sciter/blob/f59030af0a00052a2759ca28667bed24a6448c2d/src/dom.rs#L1487-L1489