pub struct Window { /* private fields */ }Expand description
The WebUI window type.
Implementations§
Source§impl Window
impl Window
Sourcepub fn show(&self, content: &str) -> Result<(), WebUIError>
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()
Sourcepub fn show_browser(
&self,
content: &str,
browser: Browser,
) -> Result<(), WebUIError>
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.
Sourcepub fn show_webview(&self, content: &str) -> Result<(), WebUIError>
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).
Sourcepub fn start_server(&self, content: &str) -> String
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.
Sourcepub fn close(&self)
pub fn close(&self)
Close the window. The window object will still exist and can be shown again later.
Sourcepub fn set_minimum_size(&self, width: u32, height: u32)
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.
Sourcepub fn set_position(&self, x: u32, y: u32)
pub fn set_position(&self, x: u32, y: u32)
Set the window position.
Sourcepub fn set_center(&self)
pub fn set_center(&self)
Center the window on the screen.
§Remarks
Call this before show() for best results. Works better with WebView.
Sourcepub fn set_hide(&self, hide: bool)
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().
Sourcepub fn set_frameless(&self, frameless: bool)
pub fn set_frameless(&self, frameless: bool)
Remove the window frame and title bar (borderless/frameless mode).
§Remarks
Works with WebView windows only.
Sourcepub fn set_transparent(&self, transparent: bool)
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.
Sourcepub fn set_resizable(&self, resizable: bool)
pub fn set_resizable(&self, resizable: bool)
Sourcepub fn set_icon(&self, icon: &str, icon_type: &str)
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.
Sourcepub fn set_high_contrast(&self, high_contrast: bool)
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.
Sourcepub fn is_high_contrast(&self) -> bool
pub fn is_high_contrast(&self) -> bool
Check if the operating system is currently using a high-contrast theme.
Sourcepub fn set_custom_parameters(&self, params: &str)
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.
Sourcepub fn set_close_handler_webview<F>(&self, callback: F)where
F: CloseHandler,
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.
Navigate all connected clients of a window to a specific URL.
Sourcepub fn get_url(&self) -> String
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.
Sourcepub fn set_public(&self, status: bool)
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.
Sourcepub fn bind<F>(&self, function: &str, callback: F)where
F: EventHandler,
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.
Sourcepub fn set_event_blocking(&self, event_blocking: bool)
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.
Sourcepub fn set_timeout(&self, second: usize)
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.
Sourcepub fn script(
&self,
script: &str,
timeout: usize,
capacity: usize,
) -> Result<String, WebUIError>
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.
Sourcepub fn set_runtime(&self, runtime: Runtime)
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.
Sourcepub fn send_raw<T>(&self, function: &str, data: T)
pub fn send_raw<T>(&self, function: &str, data: T)
Send raw binary data to a JavaScript function in the UI. Sends to all connected clients.
Sourcepub fn set_file_handler<F>(&self, callback: F)where
F: FileHandlerWindow,
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.
Sourcepub fn set_root_folder(&self, path: &str) -> Result<(), WebUIError>
pub fn set_root_folder(&self, path: &str) -> Result<(), WebUIError>
Set the web-server root folder path for a specific window.
Sourcepub fn get_best_browser(&self) -> Browser
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.
Sourcepub fn set_profile(&self, name: &str, path: &str)
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.
Sourcepub fn delete_profile(&self)
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.
Sourcepub fn get_port(&self) -> usize
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.
Sourcepub fn set_port(&self, port: usize) -> Result<(), WebUIError>
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.
Sourcepub fn get_parent_process_id(&self) -> usize
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.
Sourcepub fn get_child_process_id(&self) -> usize
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.
Sourcepub fn get_window_handler(&self) -> *mut c_void
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).