sciter-sdk / rust-sciter

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

data_ready not working? #55

Closed DevJac closed 5 years ago

DevJac commented 5 years ago

I have the following code:

use rusqlite::Connection;
use sciter::w2s;

struct HostHandler {
    app_archive: sciter::host::Archive,
}

impl sciter::host::HostHandler for HostHandler {
    fn on_data_load(
        &mut self,
        data: &mut sciter::host::SCN_LOAD_DATA,
    ) -> Option<sciter::host::LOAD_RESULT> {
        let requested_uri = w2s!(data.uri);
        eprintln!("Loading: {:?}", &requested_uri[7..]);
        if requested_uri.starts_with("file://") {
            let desired_app_archive_file = &requested_uri[7..];
            if let Some(bytes) = self.app_archive.get(desired_app_archive_file) {
                eprintln!("Loading: {:?}", self.app_archive.get(&requested_uri[7..]));
                eprintln!(
                    "{}",
                    String::from_utf8_lossy(self.app_archive.get(&requested_uri[7..]).unwrap())
                );
                self.data_ready(data.hwnd, &requested_uri, bytes, None);
            }
        }
        Some(sciter::host::LOAD_RESULT::LOAD_MYSELF)
    }
}

pub fn app_main(_db_conn: &Connection) {
    setup_sciter();
    let app_archive = sciter::host::Archive::open(APP_ARCHIVE).unwrap();
    let mut main_window = sciter::Window::new();
    main_window.sciter_handler(HostHandler { app_archive });
    main_window.load_file("main.htm");
    main_window.run_app();
}

fn setup_sciter() {
    sciter::set_options(sciter::RuntimeOptions::DebugMode(true)).unwrap();
    sciter::set_options(sciter::RuntimeOptions::ScriptFeatures(
        sciter::SCRIPT_RUNTIME_FEATURES::ALLOW_SOCKET_IO as u8,
    ))
    .unwrap();
}

const APP_ARCHIVE: &[u8] = include_bytes!(env!("APP_ARCHIVE"));

The output when I run this code is:

Loading: "main.htm"
Loading: Some([60, 104, 116, 109, 108, 62, 10, 32, 32, 32, 32, 60, 104, 101, 97, 100, 62, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 116, 105, 116, 108, 101, 62, 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33, 60, 47, 116, 105, 116, 108, 101, 62, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 115, 99, 114, 105, 112, 116, 32, 116, 121, 112, 101, 61, 34, 116, 101, 120, 116, 47, 116, 105, 115, 99, 114, 105, 112, 116, 34, 32, 115, 114, 99, 61, 34, 120, 121, 122, 34, 32, 47, 62, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 115, 99, 114, 105, 112, 116, 32, 116, 121, 112, 101, 61, 34, 116, 101, 120, 116, 47, 116, 105, 115, 99, 114, 105, 112, 116, 34, 32, 115, 114, 99, 61, 34, 115, 114, 99, 47, 115, 99, 105, 116, 101, 114, 47, 109, 46, 116, 105, 115, 34, 32, 47, 62, 10, 32, 32, 32, 32, 60, 47, 104, 101, 97, 100, 62, 10, 32, 32, 32, 32, 60, 98, 111, 100, 121, 62, 10, 32, 32, 32, 32, 32, 32, 32, 32, 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33, 10, 32, 32, 32, 32, 60, 47, 98, 111, 100, 121, 62, 10, 60, 47, 104, 116, 109, 108, 62, 10])
<html>
    <head>
        <title>Hello World!</title>
        <script type="text/tiscript" src="xyz" />
        <script type="text/tiscript" src="src/sciter/m.tis" />
    </head>
    <body>
        Hello World!
    </body>
</html>

The archive is clearly working, but when I run this code it just shows a blank Sciter window, as though the file load never did anything.

I believe my code here is self contained, you just have to change app_main to main (and I guess get rid of the database connection parameter that's never used).

DevJac commented 5 years ago

Nevermind. I just have to return None and it works.

What does returning None from on_data_load do? Just the default I guess?

pravic commented 5 years ago

Yes, but on_data_ready should work. I'll check.

pravic commented 5 years ago

Here we go: https://docs.rs/sciter-rs/0.5.45/sciter/host/enum.LOAD_RESULT.html

LOAD_MYSELF indicates that you will use HREQUEST. Use none or default in case of data_ready.

pravic commented 5 years ago

The docs are not clear, I agree.