@@ -596,6 +596,11 @@ impl<R: Runtime> App<R> {
596596/// ```
597597#[ allow( clippy:: type_complexity) ]
598598pub struct Builder < R : Runtime > {
599+ /// A flag indicating that the runtime must be started on an environment that supports the event loop not on the main thread.
600+ #[ cfg( any( windows, target_os = "linux" ) ) ]
601+ #[ cfg_attr( doc_cfg, doc( any( windows, target_os = "linux" ) ) ) ]
602+ runtime_any_thread : bool ,
603+
599604 /// The JS message handler.
600605 invoke_handler : Box < InvokeHandler < R > > ,
601606
@@ -645,6 +650,8 @@ impl<R: Runtime> Builder<R> {
645650 /// Creates a new App builder.
646651 pub fn new ( ) -> Self {
647652 Self {
653+ #[ cfg( any( windows, target_os = "linux" ) ) ]
654+ runtime_any_thread : false ,
648655 setup : Box :: new ( |_| Ok ( ( ) ) ) ,
649656 invoke_handler : Box :: new ( |_| ( ) ) ,
650657 invoke_responder : Arc :: new ( window_invoke_responder) ,
@@ -665,6 +672,18 @@ impl<R: Runtime> Builder<R> {
665672 }
666673 }
667674
675+ /// Builds a new Tauri application running on any thread, bypassing the main thread requirement.
676+ ///
677+ /// ## Platform-specific
678+ ///
679+ /// - **macOS**: on macOS the application *must* be executed on the main thread, so this function is not exposed.
680+ #[ cfg( any( windows, target_os = "linux" ) ) ]
681+ #[ cfg_attr( doc_cfg, doc( any( windows, target_os = "linux" ) ) ) ]
682+ pub fn any_thread ( mut self ) -> Self {
683+ self . runtime_any_thread = true ;
684+ self
685+ }
686+
668687 /// Defines the JS message handler callback.
669688 ///
670689 /// # Example
@@ -1098,7 +1117,15 @@ impl<R: Runtime> Builder<R> {
10981117 ) ) ;
10991118 }
11001119
1120+ #[ cfg( any( windows, target_os = "linux" ) ) ]
1121+ let runtime = if self . runtime_any_thread {
1122+ R :: new_any_thread ( ) ?
1123+ } else {
1124+ R :: new ( ) ?
1125+ } ;
1126+ #[ cfg( not( any( windows, target_os = "linux" ) ) ) ]
11011127 let runtime = R :: new ( ) ?;
1128+
11021129 let runtime_handle = runtime. handle ( ) ;
11031130 let global_shortcut_manager = runtime. global_shortcut_manager ( ) ;
11041131 let clipboard_manager = runtime. clipboard_manager ( ) ;
0 commit comments