tuffite/
lib.rs

1//! Public Rust API for applications built with Tuffite.
2//!
3//! Applications declare a logical main with explicit Browser and Utility types.
4//! Browser state is created only in the main process. The main factory assembles
5//! definitions in each process, while `before_startup` runs for each native process role.
6//!
7//! ```no_run
8//! # mod example {
9//! use tuffite::{Browser, BrowserContext, ApplicationResult};
10//! struct MyBrowser;
11//! #[tuffite::browser]
12//! impl Browser for MyBrowser {
13//!     fn new(_: BrowserContext) -> ApplicationResult<Self> { Ok(Self) }
14//! }
15//! #[tuffite::main(browser = MyBrowser)]
16//! fn main() -> tuffite::app::Builder<MyBrowser> {
17//!     tuffite::app::Builder::new()
18//!         .before_startup(|launch| {
19//!             launch.argv_mut().retain(|arg| arg != "--business-debug");
20//!             Ok(())
21//!         })
22//! }
23//! # }
24//! ```
25
26// Native packaging FFI has a narrowly scoped exception in package::icons.
27#![deny(unsafe_code)]
28
29extern crate self as tuffite;
30
31/// Generated Framework Shell API models and typed native requests.
32// Schema shapes and generated handler signatures intentionally mirror other languages.
33#[allow(
34    clippy::struct_excessive_bools,
35    clippy::cmp_owned,
36    clippy::let_unit_value,
37    clippy::type_complexity
38)]
39pub mod shell_api {
40    include!("shell_api_generated.rs");
41}
42
43#[cfg(feature = "build")]
44pub mod build;
45#[cfg(feature = "cli")]
46pub mod cli;
47
48pub use tuffite_macros::{browser, command, main, utility};
49pub use tuffite_runtime::{
50    ApplicationError, ApplicationResult, Browser, BrowserContext, Bytes, ChromiumExecutor, Command,
51    CommandDescriptor, CommandError, CommandResult, DEFAULT_UTILITY_SESSION_CREDITS, EventEmitter,
52    ExecutorError, HandleKind, JavaScriptExtensionError, JavaScriptExtensionHost,
53    JavaScriptExtensionPackage, JavaScriptExtensionSessionHandle, MAX_UTILITY_SESSION_CREDITS,
54    MAX_UTILITY_SESSION_EVENT_BYTES, RawHandle, Runtime, RuntimeError, RuntimeState, ShellApiError,
55    ShellApiHost, ShellApiRequest, TaskContext, TaskHandle, TaskPriority, Timestamp, Utility,
56    UtilityContext, UtilityFuture, UtilityRequest, UtilityServiceRegistration, UtilitySession,
57    UtilitySessionClosed, UtilitySessionCommand, UtilitySessionEmitter, UtilitySessionEvent,
58    UtilitySessionFlowControl, UtilitySessionFlowError, UtilitySessionFuture, UtilitySessionHandle,
59    UtilitySessionHost, UtilitySessionHostError, UtilitySessionOptions, UtilitySessionRequest,
60    V8Context,
61};
62#[cfg(feature = "async")]
63pub use tuffite_runtime::{ChromiumTask, ChromiumTaskError};
64pub use tuffite_runtime::{app, browser, utility};
65
66/// Implementation details used by code generated by Tuffite macros.
67///
68/// This module is public for macro expansion only and has no compatibility
69/// guarantee for application code.
70#[doc(hidden)]
71pub mod __private {
72    pub use tuffite_abi::Application;
73    pub use tuffite_runtime::browser::BrowserDefinition;
74    pub use tuffite_runtime::utility::{UtilityDefinition, validate_utility_names};
75    pub use tuffite_runtime::{CommandHandler, CommandRegistry};
76    pub use tuffite_runtime::{codec, serde};
77}
78
79/// Builds a statically checked command registry from explicitly annotated
80/// handlers. Each handler must use `#[tuffite::command(endpoint::Type)]`.
81#[macro_export]
82macro_rules! generate_handler {
83    () => {
84        compile_error!("tuffite::generate_handler! requires at least one command handler")
85    };
86    ($first:path $(, $handler:path)* $(,)?) => {{
87        type __TuffiteBrowser =
88            <$first as $crate::__private::CommandHandler>::Browser;
89
90        fn __tuffite_dispatch(
91            browser: &mut __TuffiteBrowser,
92            command: $crate::Command<'_>,
93        ) -> $crate::CommandResult {
94            if command.id()
95                == <$first as $crate::__private::CommandHandler>::COMMAND.id()
96            {
97                return <$first as $crate::__private::CommandHandler>::dispatch(
98                    browser,
99                    command,
100                );
101            }
102            $(
103                if command.id()
104                    == <$handler as $crate::__private::CommandHandler>::COMMAND.id()
105                {
106                    return <$handler as $crate::__private::CommandHandler>::dispatch(
107                        browser,
108                        command,
109                    );
110                }
111            )*
112            Err($crate::CommandError::UnknownCommand)
113        }
114
115        $crate::__private::CommandRegistry::<__TuffiteBrowser>::new(
116            __tuffite_dispatch,
117            &[
118                <$first as $crate::__private::CommandHandler>::COMMAND,
119                $(<$handler as $crate::__private::CommandHandler>::COMMAND,)*
120            ],
121        )
122    }};
123}
124
125/// Asynchronous native desktop remoting client.
126#[cfg(feature = "remoting")]
127pub mod remoting;