1- use std:: path:: PathBuf ;
1+ use std:: path:: { Path , PathBuf } ;
22
33use cef:: args:: Args ;
44use cef:: sys:: { CEF_API_VERSION_LAST , cef_resultcode_t} ;
@@ -25,12 +25,23 @@ unsafe impl<H: CefEventHandler> Send for CefContextBuilder<H> {}
2525
2626impl < H : CefEventHandler > CefContextBuilder < H > {
2727 pub ( crate ) fn new ( ) -> Self {
28+ Self :: new_inner ( false )
29+ }
30+
31+ pub ( crate ) fn new_helper ( ) -> Self {
32+ Self :: new_inner ( true )
33+ }
34+
35+ fn new_inner ( helper : bool ) -> Self {
2836 #[ cfg( target_os = "macos" ) ]
2937 let _loader = {
30- let loader = library_loader:: LibraryLoader :: new ( & std:: env:: current_exe ( ) . unwrap ( ) , false ) ;
38+ let loader = cef :: library_loader:: LibraryLoader :: new ( & std:: env:: current_exe ( ) . unwrap ( ) , helper ) ;
3139 assert ! ( loader. load( ) ) ;
3240 loader
3341 } ;
42+ #[ cfg( not( target_os = "macos" ) ) ]
43+ let _ = helper;
44+
3445 let _ = api_hash ( CEF_API_VERSION_LAST , 0 ) ;
3546
3647 let args = Args :: new ( ) ;
@@ -62,17 +73,29 @@ impl<H: CefEventHandler> CefContextBuilder<H> {
6273 }
6374 }
6475
76+ fn common_settings ( instance_dir : & Path ) -> Settings {
77+ Settings {
78+ windowless_rendering_enabled : 1 ,
79+ root_cache_path : instance_dir. to_str ( ) . map ( CefString :: from) . unwrap ( ) ,
80+ cache_path : CefString :: from ( "" ) ,
81+ disable_signal_handlers : 1 ,
82+ ..Default :: default ( )
83+ }
84+ }
85+
6586 #[ cfg( target_os = "macos" ) ]
6687 pub ( crate ) fn initialize ( self , event_handler : H , disable_gpu_acceleration : bool ) -> Result < impl CefContext , InitError > {
6788 let instance_dir = create_instance_dir ( ) ;
6889
90+ let exe = std:: env:: current_exe ( ) . expect ( "cannot get current exe path" ) ;
91+ let app_root = exe. parent ( ) . and_then ( |p| p. parent ( ) ) . expect ( "bad path structure" ) . parent ( ) . expect ( "bad path structure" ) ;
92+
6993 let settings = Settings {
70- windowless_rendering_enabled : 1 ,
94+ main_bundle_path : CefString :: from ( app_root . to_str ( ) . unwrap ( ) ) ,
7195 multi_threaded_message_loop : 0 ,
7296 external_message_pump : 1 ,
73- root_cache_path : instance_dir. to_str ( ) . map ( CefString :: from) . unwrap ( ) ,
74- cache_path : CefString :: from ( "" ) ,
75- ..Default :: default ( )
97+ no_sandbox : 1 , // GPU helper crashes when running with sandbox
98+ ..Self :: common_settings ( & instance_dir)
7699 } ;
77100
78101 self . initialize_inner ( & event_handler, settings) ?;
@@ -85,11 +108,8 @@ impl<H: CefEventHandler> CefContextBuilder<H> {
85108 let instance_dir = create_instance_dir ( ) ;
86109
87110 let settings = Settings {
88- windowless_rendering_enabled : 1 ,
89111 multi_threaded_message_loop : 1 ,
90- root_cache_path : instance_dir. to_str ( ) . map ( CefString :: from) . unwrap ( ) ,
91- cache_path : CefString :: from ( "" ) ,
92- ..Default :: default ( )
112+ ..Self :: common_settings ( & instance_dir)
93113 } ;
94114
95115 self . initialize_inner ( & event_handler, settings) ?;
0 commit comments