Struct
AppHandle
pub struct AppHandle { /* private fields */ }Shared lifecycle handle for a running Kurogane application.
Obtain one with AppInstance::handle; clones share the application.
Threads
Usable from any thread. Queries copy what is open under a short lock. A broadcast sends to its subscribers on the calling thread, which CEF allows for frames in the browser process. Closing and ending run on CEF’s UI thread. They run at once when called there and are posted there otherwise.
Once AppInstance::shutdown has begun, calls that would reach CEF do
nothing, since CEF takes no call after it has shut down.
Methods
#pub fn shutdown(&self)
Ends the application by closing all browsers.
The application ends after the last browser closes. Calling this from
another thread posts the close to the UI thread. The call does not wait
for the browsers to close. Does nothing once AppInstance::shutdown
has begun.
This end cannot be cancelled and no browser may open after it begins.
Popups are refused, AppInstance::create_window and
AppInstance::create_child_browser return RuntimeError::ShuttingDown
and any browser CEF is already creating is closed as it appears. No
context menu opens either, not even the one whose
App::on_context_menu hook began the end.
#pub fn should_shutdown(&self) -> bool
Returns whether the application has ended.
Becomes true once the last browser has closed, whatever closed it (its
window, AppHandle::shutdown, Ctrl+C or macOS asking the
application to quit). Any of those three that finds nothing open ends
it at once. Also true once AppInstance::shutdown has begun. An
application that pumps CEF itself keeps pumping until then.
#pub fn broadcast(&self, event: &str, data: &[u8])
Broadcast bytes to all renderers subscribed to event.
A page’s kurogane.on callback receives them as an ArrayBuffer. The
event is delivered asynchronously to every active subscription for the
given event name. This method is thread-safe and returns immediately after
queuing the event for delivery. Does nothing once
AppInstance::shutdown has begun.
#pub fn broadcast_json<T: Serialize>(&self, event: &str, value: &T)
Broadcast a JSON-serializable event to all renderers subscribed to event.
The value is serialized to JSON. A page’s kurogane.on callback receives
the JSON text as a string. This is the preferred way to emit structured
events.
#pub fn browser_count(&self) -> usize
Number of currently live browser instances.
#pub fn window_count(&self) -> usize
Number of currently open windows.
#pub fn close_all_windows(&self)
Closes all open windows.
Safe to call from any thread. CEF’s windows close only on the UI
thread; a call from elsewhere is posted there. Does nothing once
AppInstance::shutdown has begun.
#pub fn close_all_browsers(&self, force: bool)
Closes all live browser instances.
The call does not wait. A browser counts in AppHandle::browser_count
until CEF has finished closing it. An application that pumps CEF keeps
pumping until the count is 0. A browser embedded in the
application’s own window closes without asking that window to close.
A call from another thread is posted to the UI thread. Does nothing
once AppInstance::shutdown has begun.
With force no page can cancel the close. A call that finds a browser
open then ends the application as AppHandle::shutdown does and
nothing opens after it. Without it a page’s beforeunload may keep its
browser and the application running.
#pub fn find_window_by_browser(&self, browser_id: BrowserId) -> Option<WindowId>
Looks up the window that hosts a given browser.
None once the browser has closed, even while CEF is still closing its window.
#pub fn find_window_by_name(&self, name: &str) -> Option<WindowId>
Looks up the open window named name
(WindowOptions::name).
None once its close has been reported
(App::on_window_closing), even
while CEF is still closing it. The name is then free for a new window.
#pub fn browsers(&self) -> Vec<(BrowserId, BrowserMetadata)>
Metadata for all live browsers.
#pub fn windows(&self) -> Vec<(WindowId, WindowMetadata)>
Metadata for all open windows.
#pub fn children_of(&self, id: BrowserId) -> Vec<BrowserId>
All children of the given parent browser.
#pub fn browser_for_window(&self, id: WindowId) -> Option<BrowserId>
Browser hosted in the given window.
None until the window’s browser has been created and once it has closed.
#pub fn forget_permissions(&self, origin: &Origin)
Forgets the permission answers Chromium remembers for origin. The
site’s next request then reaches
App::on_permission again. Use it after
the application’s policy changed or the user took a permission back.
Chromium remembers its answers to web sites (http, https), granted
or denied, in the profile. It forgets them nowhere else. Forgetting
also takes back a grant the site holds now; its notifications stop.
Applies to the profile of every open browser, an embedded browser’s
own profile included. A call from another thread is posted to the UI
thread. Does nothing for the opaque origin, or once
AppInstance::shutdown has begun.
#pub fn get_browser_handle(&self, id: BrowserId) -> Option<BrowserHandle>
Creates a BrowserHandle for a registered browser, if it exists.
Returns None if no browser with the given BrowserId is registered, or
once AppInstance::shutdown has begun.