pub struct BrowserWindowThreaded(/* private fields */);
Expand description
Note: Only available with feature threadsafe
enabled.
A thread-safe handle to a browser window.
It allows you to dispatch code to the GUI thread and thereby manipulate the
browser window from any thread. To do this, you will need to use the
functions dispatch
, dispatch_async
, delegate
and delegate_async
.
§Example
This example fetches a value from within JavaScript:
use browser_window::{application::*, browser::*};
async fn get_cookies(app: &ApplicationHandleThreaded) -> String {
let mut builder =
BrowserWindowBuilder::new(Source::Url("https://www.duckduckgo.com/".into()));
builder.title("test");
let bw: BrowserWindowThreaded = builder.build_threaded(app).await.unwrap();
// Waits for `eval_js` to give back its result from the GUI thread
let result = bw
.delegate_async(|handle| async move {
// Execute `eval_js` on the GUI thread
handle.eval_js("document.cookies").await
})
.await
.unwrap();
result.unwrap().to_string()
}
Implementations§
Source§impl BrowserWindowThreaded
impl BrowserWindowThreaded
Sourcepub fn app(&self) -> ApplicationHandleThreaded
pub fn app(&self) -> ApplicationHandleThreaded
The thread-safe application handle associated with this browser window.
Sourcepub fn delegate<'a, F, R>(&self, func: F) -> BrowserDelegateFuture<'a, R>
pub fn delegate<'a, F, R>(&self, func: F) -> BrowserDelegateFuture<'a, R>
Executes the given closure within the GUI thread, and return the value
that the closure returned. Also see ApplicationThreaded::delegate
.
The function signature is practically the same as:
pub async fn delegate<'a,F,R>( &self, func: F ) -> Result<R, DelegateError> where
F: FnOnce( BrowserWindowHandle ) -> R + Send + 'a,
R: Send { /*...*/ }
Sourcepub fn delegate_async<'a, C, F, R>(
&self,
func: C,
) -> DelegateFutureFuture<'a, R> ⓘ
pub fn delegate_async<'a, C, F, R>( &self, func: C, ) -> DelegateFutureFuture<'a, R> ⓘ
Executes the given async closure func
on the GUI thread, and gives
back the result when done.
Also see ApplicationThreaded::delegate_async
.
Sourcepub fn delegate_future<'a, F, R>(&self, fut: F) -> DelegateFutureFuture<'a, R> ⓘ
pub fn delegate_future<'a, F, R>(&self, fut: F) -> DelegateFutureFuture<'a, R> ⓘ
Executes the given future on the GUI thread, and gives back the result
when done. Also see ApplicationThreaded::delegate_future
.
Sourcepub fn dispatch<'a, F>(&self, func: F) -> bool
pub fn dispatch<'a, F>(&self, func: F) -> bool
Executes the given close on the GUI thread.
See also Application::dispatch
.
Sourcepub fn dispatch_async<'a, C, F>(&self, func: C) -> bool
pub fn dispatch_async<'a, C, F>(&self, func: C) -> bool
Executes the given closure on the GUI thread.
See also Application::dispatch
.
Trait Implementations§
Source§impl Clone for BrowserWindowThreaded
impl Clone for BrowserWindowThreaded
Source§fn clone(&self) -> BrowserWindowThreaded
fn clone(&self) -> BrowserWindowThreaded
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more