Skip to main content

Window

Struct Window 

Source
pub struct Window { /* private fields */ }
Expand description

The WebUI window type.

Implementations§

Source§

impl Window

Source

pub fn new() -> Self

Create a new window object.

Examples found in repository?
examples/bind.rs (line 4)
3fn main() -> Result<(), WebUIError> {
4    let window = Window::new();
5    window.bind("say_hello", |_| println!("Hello, world!"));
6    window.show(r#"<html><head><title>Hello, world!</title><script src="webui.js"></script></head><body><button onclick="say_hello()">Hello</button></body></html>"#)?;
7    wait();
8    Ok(())
9}
Source

pub fn show(&self, content: &str) -> Result<(), WebUIError>

Show a window using embedded HTML, a URL, a local file, or a local folder. If the window is already open, it will be refreshed. This refreshes all clients in multi-client mode.

§Remarks

To use only a specific browser please use show_browser() To use only WebView please use show_webview()

Examples found in repository?
examples/bind.rs (line 6)
3fn main() -> Result<(), WebUIError> {
4    let window = Window::new();
5    window.bind("say_hello", |_| println!("Hello, world!"));
6    window.show(r#"<html><head><title>Hello, world!</title><script src="webui.js"></script></head><body><button onclick="say_hello()">Hello</button></body></html>"#)?;
7    wait();
8    Ok(())
9}
Source

pub fn show_browser( &self, content: &str, browser: Browser, ) -> Result<(), WebUIError>

Show a window using a specific web browser.

§Remarks

It’s recommended to use ChromiumBased browser. On macOS, the browser’s icon may still appear in the Dock after exit. We recommend using show_webview on macOS to avoid this.

Source

pub fn show_webview(&self, content: &str) -> Result<(), WebUIError>

Show a WebView window using embedded HTML, a URL, or a local file. If the window is already open, it will be refreshed.

§Remarks

WebUI’s primary focus is using web browsers as GUI, but if you need to use WebView instead of a web browser, then you can use this API, which was added to WebUI starting from v2.5.

  • Windows Dependencies: WebView2, and WebView2Loader.dll.
  • Linux Dependencies: WebKit GTK v3.
  • macOS Dependencies: WebKit (WKWebView).
Source

pub fn start_server(&self, content: &str) -> String

Start only the local web server without opening a browser window, and return the URL. Useful for headless web app scenarios.

Source

pub fn close(&self)

Close the window. The window object will still exist and can be shown again later.

Source

pub fn is_shown(&self) -> bool

Check if the window is still running.

Source

pub fn focus(&self)

Bring the window to the front and give it keyboard focus.

Source

pub fn minimize(&self)

Minimize the WebView window.

Source

pub fn maximize(&self)

Maximize a WebView window.

Source

pub fn set_kiosk(&self, status: bool)

Set the window in Kiosk mode (Full screen).

Source

pub fn set_size(&self, width: u32, height: u32)

Set the window size.

Source

pub fn set_minimum_size(&self, width: u32, height: u32)

Set the minimum allowed window size. The user will not be able to resize the window smaller than this.

§Remarks

Currently works on Windows only.

Source

pub fn set_position(&self, x: u32, y: u32)

Set the window position.

Source

pub fn set_center(&self)

Center the window on the screen.

§Remarks

Call this before show() for best results. Works better with WebView.

Source

pub fn set_hide(&self, hide: bool)

Start the window in hidden mode. The window will be running but not visible.

§Remarks

Should be called before show().

Source

pub fn set_frameless(&self, frameless: bool)

Remove the window frame and title bar (borderless/frameless mode).

§Remarks

Works with WebView windows only.

Source

pub fn set_transparent(&self, transparent: bool)

Enable or disable window background transparency.

§Remarks

Works with WebView windows only. The web content must also use a transparent/semi-transparent background for this to be visible.

Source

pub fn set_resizable(&self, resizable: bool)

Control whether the user can resize the window.

§Remarks

Works with WebView windows only.

Source

pub fn set_icon(&self, icon: &str, icon_type: &str)

Set the default embedded HTML favicon. The icon is served automatically by WebUI’s built-in server.

Source

pub fn set_high_contrast(&self, high_contrast: bool)

Mark the window as supporting high-contrast mode. Use this together with CSS to build a better high-contrast theme.

Source

pub fn is_high_contrast(&self) -> bool

Check if the operating system is currently using a high-contrast theme.

Source

pub fn set_custom_parameters(&self, params: &str)

Add custom command-line parameters to the browser launch command. This can be used, for example, to enable remote debugging.

Source

pub fn set_close_handler_webview<F>(&self, callback: F)
where F: CloseHandler,

Set a callback to intercept the close event of a WebView window. Return false from the handler to prevent the window from closing; return true to allow it.

Source

pub fn navigate(&self, url: &str)

Navigate all connected clients of a window to a specific URL.

Source

pub fn get_url(&self) -> String

Get the current URL of a running window’s web server.

§Remarks

By default, WebUI only allows access to this URL from localhost.

Source

pub fn set_public(&self, status: bool)

Allow the window’s web server URL to be accessible from external devices on the network. By default, WebUI only allows access from localhost.

Source

pub fn bind<F>(&self, function: &str, callback: F)
where F: EventHandler,

Bind an HTML element click event or a JavaScript function call to a C callback. Use an empty element name to catch all events from the window.

Examples found in repository?
examples/bind.rs (line 5)
3fn main() -> Result<(), WebUIError> {
4    let window = Window::new();
5    window.bind("say_hello", |_| println!("Hello, world!"));
6    window.show(r#"<html><head><title>Hello, world!</title><script src="webui.js"></script></head><body><button onclick="say_hello()">Hello</button></body></html>"#)?;
7    wait();
8    Ok(())
9}
Source

pub fn set_event_blocking(&self, event_blocking: bool)

Control whether UI events from this window are processed one at a time in a single blocking thread (true), or each in a new non-blocking thread (false). Applies to this window only. Use set_config(ui_event_blocking, …) to apply to all windows.

§Remarks

When set to true, the script() API will not return a response until the current event callback has finished.

Source

pub fn set_timeout(&self, second: usize)

Set the maximum time in seconds to wait for the browser window to connect after calling show(). A value of 0 means wait forever.

Source

pub fn script( &self, script: &str, timeout: usize, capacity: usize, ) -> Result<String, WebUIError>

Run JavaScript and get the response back. Works in single client mode. Make sure your buffer is large enough to hold the response.

Source

pub fn set_runtime(&self, runtime: Runtime)

Choose between Deno, Bun, and Nodejs as the runtime for .js and .ts files served by the web server.

Source

pub fn send_raw<T>(&self, function: &str, data: T)
where T: Into<Vec<u8>>,

Send raw binary data to a JavaScript function in the UI. Sends to all connected clients.

Source

pub fn set_file_handler<F>(&self, callback: F)
where F: FileHandlerWindow,

Set a custom handler to serve files. The handler receives the requested filename and must return a complete HTTP response (headers + body). Replaces any handler set with set_file_handler_window.

Source

pub fn set_root_folder(&self, path: &str) -> Result<(), WebUIError>

Set the web-server root folder path for a specific window.

Source

pub fn get_best_browser(&self) -> Browser

Get the recommended web browser ID to use for this window. If a browser is already in use, returns that browser’s ID.

Source

pub fn set_profile(&self, name: &str, path: &str)

Set the web browser profile to use. An empty name and path uses the default user profile.

Source

pub fn set_proxy(&self, proxy_server: &str)

Set the web browser proxy server.

§Remarks

Must be called before show().

Source

pub fn delete_profile(&self)

Delete a specific window web-browser local folder profile.

§Remarks

Recommended to call after all windows are closed, before clean(). This can break functionality of other windows using the same browser profile.

Source

pub fn get_port(&self) -> usize

Get the network port used by the running window’s web server. Useful for constructing the webui.js URL when integrating with an external server.

Source

pub fn set_port(&self, port: usize) -> Result<(), WebUIError>

Set a specific network port for the window’s web server. Useful when integrating with an external web server like NGINX.

Source

pub fn get_parent_process_id(&self) -> usize

Get the process ID of the backend application (the parent process). The web browser may create additional child processes.

Source

pub fn get_child_process_id(&self) -> usize

Get the process ID of the browser window child process. In WebView mode, returns the parent PID because backend and WebView run in the same process.

Source

pub fn get_window_handler(&self) -> *mut c_void

Get the native window handle. On Windows returns HWND (works with both WebView and web browser). On Linux returns GtkWindow* (WebView only).

Source

pub fn run(&self, script: &str)

Run JavaScript without waiting for the response.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.