How to inject code in all windows?
WesleiRamos opened this issue · 9 comments
I'm making an application where the user can create windows using their own html files, but it would require the windows to have a default behavior, so I developed a simple code that could be manually added by the user, but if there was a way to inject that code would make it a lot easier, I searched and found RuntimeOptions::InitScript, I tried calling a native function and nothing happened.
There's an answer here: https://sciter.com/forums/topic/how-to-inject-code-in-all-windows/
I tried calling a native function and nothing happened.
Could you show the code? It's not clear yet.
Could you show the code? It's not clear yet.
This is what i tried (still doesn't work)
#[macro_use]
extern crate sciter;
struct Handler;
impl Handler {
fn calc_sum(&self, a: i32, b: i32) {
print!("{} + {} = {}", a, b, a + b);
}
}
impl sciter::EventHandler for Handler {
dispatch_script_call! {
fn calc_sum(i32, i32);
}
}
fn main() {
sciter::set_options(sciter::RuntimeOptions::DebugMode(true)).unwrap();
sciter::set_options(sciter::RuntimeOptions::InitScript("
Window.this.xcall('calc_sum', 1, 2);
")).unwrap();
let mut frame = sciter::Window::new();
frame.event_handler(Handler);
frame.load_html(b"<p>Hello</p><script>Window.this.xcall('calc_sum', 1, 5);</script>", None);
frame.run_app();
}
I believe, it's too early to call. I wonder if timers work in this case.
I believe, it's too early to call. I wonder if timers work in this case.
I tried several possible ways and nothing works, my app doesn't need to call native functions too early, I just need to create some functions to manipulate the window.
extern crate sciter;
fn main() {
sciter::set_options(sciter::RuntimeOptions::DebugMode(true)).unwrap();
sciter::set_options(sciter::RuntimeOptions::InitScript("setTimeout(() => console.log('Hello World1'), 5000)")).unwrap();
let mut frame = sciter::Window::new();
frame.load_html(b"<p>:)</p><script>setTimeout(() => console.log('Hello World2'), 5000)</script>", None);
frame.run_app();
}
@WesleiRamos Try to ask on http://sciter.com/forums/ - I think, it's a Sciter related issue.
InitScript should work in 4.4.8.23, and see: https://sciter.com/forums/topic/how-to-inject-code-in-all-windows/
It's working now, thanks guys