Crate browser_window

Source
Expand description

BrowserWindow is a Rust crate that allows you to utilize a browser engine to build graphical interfaces, similar to Electron.js. You create your user interface with HTML, CSS and JavaScript. Then, you can communicate information to JavaScript and back to Rust.

Pick the underlying browser framework by setting feature cef, webkitgtk or edge2. For more info on which on you should choose and how to set them up, check this guide.

§Getting Started

To start building apps with Browser Window, take a look at the application module, or this quick example:

use browser_window::{application::*, browser::*, prelude::*};
 
fn main() {
	let app = Application::initialize(&ApplicationSettings::default()).unwrap();
	let runtime = app.start();
	runtime.run_async(|app| async move {
		let mut bwb = BrowserWindowBuilder::new(Source::File("file:///my-file.html".into()));
		bwb.dev_tools(true);
		bwb.size(800, 600);
		bwb.title("Example");
		let bw = bwb.build_async(&app).await;
        bw.on_message().register_async(|h, e| async move {
            match e.cmd.as_str() {
                "command_one" => {
                    h.eval_js(&format!(
                        "js_function({}, {}, {})",
                        1,
                        "'two'",
                        JsValue::String("𝟛\n".into()) // Gets properly formatted to a JS string
                                                      // literal
                    ));
                }
                "command_two" => {
                    // ... do something else here ...
                }
                _ => {}
            }
        });
 
        bw.show();
	});
	app.finish();
}

For more detailed example code, see this example code.

§Thread safety

To use the threadsafe version of BrowserWindow, enable feature threadsafe. This will use Arc instead of Rc internally, and will enable the BrowserWindowThreaded and ApplicationHandleThreaded handles. It will also require closures to be Send. Docs.rs will show the threadsafe versions of everything. If you need to know how everything is compiled in the non-threadsafe version, you need to invoke cargo doc --open in the git repo yourself.

§Events

To learn how to use events, take a quick look at the event module.

Modules§

application
This module contains runtime and application related handles.
browser
This module contains all browser related handles and stuff.
cookie
Module for dealing with cookies.
error
Error types.
event
This module contains all event related types.
javascript
prelude
Some common traits that need to be often available.
window
This module contains all window related functionality.

Structs§

DelegateFuture
This future executes a closure on the GUI thread and returns the result.
DelegateFutureFuture
This future runs a future on the GUI thread and returns its output.

Enums§

DelegateError
The error that occurs when you’re delegating work to the GUI thread, but it fails to finish and/or return a result.

Traits§

HasHandle