browser_window/core/
application.rs

1#[cfg(not(feature = "gtk"))]
2pub mod c;
3#[cfg(feature = "gtk")]
4pub mod gtk;
5
6use std::{
7	os::raw::{c_char, c_int},
8	time::Duration,
9};
10
11#[cfg(not(feature = "gtk"))]
12pub use c::ApplicationImpl;
13#[cfg(feature = "gtk")]
14pub use gtk::ApplicationImpl;
15
16use crate::{application::ApplicationSettings, error::Result};
17
18pub trait ApplicationExt: Clone {
19	/// Asserts if not on the GUI thread
20	fn assert_correct_thread(&self);
21	/// Dispatches work to be executed on the GUI thread.
22	fn dispatch(&self, work: fn(ApplicationImpl, *mut ()), data: *mut ()) -> bool;
23	/// Dispatches work to be executed on the GUI thread, but delayed by the
24	/// specified number of milliseconds.
25	fn dispatch_delayed(
26		&self, work: fn(ApplicationImpl, *mut ()), data: *mut (), delay: Duration,
27	) -> bool;
28	/// Causes the main loop to exit and lets it return the given code.
29	fn exit(&self, exit_code: i32);
30	/// Same as `exit`, but is thread-safe.
31	fn exit_threadsafe(self: &Self, exit_code: i32);
32	/// Shuts down all application processes and performs necessary clean-up
33	/// code.
34	fn free(&self) {}
35	fn initialize(
36		argc: c_int, argv: *mut *mut c_char, settings: &ApplicationSettings,
37	) -> Result<ApplicationImpl>;
38	/// When this is called, the runtime will exit as soon as there are no more
39	/// windows left.
40	fn mark_as_done(&self);
41	/// Runs the main loop.
42	/// This blocks until the application is exitting.
43	fn run(&self, on_ready: fn(ApplicationImpl, *mut ()), data: *mut ()) -> i32;
44}