From a8ee7dc79bcd8da2b093ca6d58616f02fbcde52f Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 22 Apr 2023 16:35:02 +0100 Subject: [PATCH] main: refactor for new client functions --- src/main.cxx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main.cxx b/src/main.cxx index 3d78366..d553623 100644 --- a/src/main.cxx +++ b/src/main.cxx @@ -1,5 +1,7 @@ #include +#include + #include "browser.hxx" #include "browser/app.hxx" #include "browser/client.hxx" @@ -46,7 +48,7 @@ int main(int argc, char* argv[]) { // CefClient struct - central object for main thread, and implements lots of handlers for browser process Browser::Client client_(cef_app); CefRefPtr client = &client_; - client->SetupNative(); + std::thread native_thread(&Browser::Client::Run, client); #if defined(CEF_X11) // X11 error handlers @@ -65,7 +67,6 @@ int main(int argc, char* argv[]) { // CEF settings - only set the ones we're interested in CefSettings settings = CefSettings(); settings.log_severity = LOGSEVERITY_WARNING; // Print warnings and errors only - //settings.external_message_pump = true; // Allows us to integrate CEF's event loop into our own settings.command_line_args_disabled = true; // We don't want our command-line to configure CEF's windows settings.uncaught_exception_stack_size = 8; // Number of call stack frames given in unhandled exception events @@ -73,16 +74,18 @@ int main(int argc, char* argv[]) { exit_code = CefInitialize(main_args, settings, cef_app, nullptr); if (exit_code == 0) { fmt::print("Exiting with error: cef_initialize exit_code {}\n", exit_code); + client->CloseNative(); + native_thread.join(); return exit_code; } - // Run the CEF message loop - // TODO: later this will be replaced with an OS-specific event loop capable of calling - // cef_do_message_loop_work() in response to CEF's "message pump" + // Block on the CEF message loop until CefQuitMessageLoop() is called CefRunMessageLoop(); // Shutdown and return + // TODO: CloseNative could technically be called before the native thread has finished the relevant setup... CefShutdown(); client->CloseNative(); + native_thread.join(); return 0; }