Menu

Struct

AppInstance

kurogane::AppInstanceSource
pub struct AppInstance { /* private fields */ }

The running application, owned by the thread that started it.

Not Send; CEF shuts down on the thread that initialized it and dropping an AppInstance shuts CEF down. Use AppInstance::handle from other threads.

Methods

#pub fn handle(&self) -> &AppHandle

Returns the shared handle, usable from any thread.

#pub fn pump(&self)

Advances Chromium by one iteration of its internal message loop.

When using external event-loop ownership via App::start, this must be called repeatedly on the thread that initialized CEF.

Kurogane assumes pump calls are non-reentrant and originate from a single UI thread.

#pub fn should_shutdown(&self) -> bool

Returns true once the application has ended; see AppHandle::should_shutdown.

#pub fn create_window( &self, url: &str, options: WindowOptions, ) -> Result<WindowId, RuntimeError>

Opens url in a new window of the application’s, as options say (see WindowOptions).

Errors

RuntimeError::InvalidWindowOptions for options no window can have; RuntimeError::WindowNameTaken when an open window has the name the options give; RuntimeError::ShuttingDown once AppHandle::shutdown has begun; RuntimeError::BrowserCreationFailed or RuntimeError::WindowCreationFailed when CEF creates neither.

#pub fn run(self) -> Result<(), RuntimeError>

Takes ownership and blocks on the CEF message loop.

The loop runs until the application’s last browser has closed, after AppHandle::shutdown (from any thread), its last window closing or Ctrl+C. tanso::shutdown() then runs on the current (UI) thread.

Not for an application given an App::scheduler. The scheduler turns on CEF’s external message pump, under which this loop returns at once and tanso::shutdown() would run under a window still opening. Such an application calls AppInstance::pump from its own loop until AppInstance::should_shutdown, then AppInstance::shutdown.

#pub fn shutdown(&self)

Perform orderly CEF shutdown.

Calls tanso::shutdown() on the UI thread; AppHandle::should_shutdown is true from here on. Safe to call multiple times. Subsequent calls are no-ops.

Unlike AppHandle::shutdown, this shuts down the CEF runtime itself. All browsers must already be closed; AppHandle::should_shutdown is true at that point.

From here on, AppHandle and BrowserHandle calls that would reach CEF do nothing. Finish using them on other threads first. A call made there at this moment can still reach CEF.

#pub fn create_child_browser( &self, parent: &impl HasWindowHandle, bounds: BrowserBounds, url: &str, ) -> Result<BrowserHandle, RuntimeError>

Creates a Chromium browser hosted inside an existing native window.

The browser is a native child window of parent, placed at bounds in the parent’s coordinates (see BrowserBounds). BrowserHandle::set_bounds moves it later.

parent is the host’s window as it is, anything that hands out a raw_window_handle window handle (a winit Window for one). It must outlive the browser, which the host closes first (docs/winit.md).

The runtime must have been started with App::start_embedded, and AppInstance::pump must continue to be called regularly for Chromium to process events.

Errors

RuntimeError::UnsupportedParentWindow when parent is not a Win32 window, an AppKit view or an X11 window (a Wayland surface, for one); RuntimeError::ShuttingDown once AppHandle::shutdown has begun; RuntimeError::BrowserCreationFailed when CEF creates no browser.

#pub fn create_child_browser_with_request_context( &self, parent: &impl HasWindowHandle, bounds: BrowserBounds, url: &str, rc_settings: &RequestContextSettings, ) -> Result<BrowserHandle, RuntimeError>

Creates a child browser with a custom request context (separate cookie/cache partition).

Same as create_child_browser but accepts RequestContextSettings to control the cache partition, cookie persistence and accept language for this browser.

The runtime must have been started with App::start_embedded.

Errors

As create_child_browser; also RuntimeError::BrowserCreationFailed when CEF creates no request context from rc_settings.

Trait implementations