Expand description
This module contains runtime and application related handles.
Browser Window needs to be initialized, and also run its own runtime.
Once that is set up and running, all windows can be constructed and be used.
To do this, use Application::initialize
.
Then you will have an Application
instance, from which you can derive a
Runtime
instance. Running the Runtime
will grant you access to an
ApplicationHandle
which you use to manipulate your application with.
§Example #1
Here is an example to show how you can construct your application:
use std::process;
use browser_window::application::*;
fn main() {
let application = Application::initialize(&ApplicationSettings::default()).unwrap();
let runtime = application.start();
let exit_code = runtime.run_async(|handle| async move {
// Do something ...
// Not normally needed:
handle.exit(0);
});
process::exit(exit_code);
}
§Example #2
If you want to run another kind of runtime, like tokio for example, its still possible to use Browser Window in conjunction with that.
However, you will need to enable feature threadsafe
, as it will enable all threadsafe handles.
Here is an example:
use std::process;
use browser_window::application::*;
use tokio;
async fn async_main( app: ApplicationHandleThreaded ) {
// Do something ...
app.exit(0);
}
fn main() {
let application = Application::initialize( &ApplicationSettings::default() ).unwrap();
let bw_runtime = application.start();
let tokio_runtime = tokio::runtime::Runtime::new().unwrap();
// First run our own runtime on the main thread
let exit_code = bw_runtime.run(|_app| {
let app = _app.into_threaded();
// Spawn the main logic into the tokio runtime
tokio_runtime.spawn( async_main( app ) );
});
process::exit(exit_code);
}
Structs§
- Application
- Use this to initialize and start your application with.
- Application
Handle - A thread-unsafe application handle. Often provided by for Browser Window.
- Application
Handle Threaded - Note: Only available with feature
threadsafe
enabled. - Application
Settings - Runtime
- The runtime to run the application with.
Traits§
Type Aliases§
- Application
Delegate Future - The future that dispatches a closure onto the GUI thread