diff --git a/repertory/repertory/src/ui/ui_main.cpp b/repertory/repertory/src/ui/ui_main.cpp index 8a3c88c3..92301fd2 100644 --- a/repertory/repertory/src/ui/ui_main.cpp +++ b/repertory/repertory/src/ui/ui_main.cpp @@ -49,10 +49,12 @@ namespace repertory::ui { return static_cast(exit_code::ui_failed); } - const auto run_ui = [](auto *server) { + const auto run_ui = [&]() -> int { REPERTORY_USES_FUNCTION_NAME(); - static std::atomic active_server{server}; + ui_server server(&config); + + static std::atomic active_server{&server}; static const auto quit_handler = [](int /* sig */) { REPERTORY_USES_FUNCTION_NAME(); @@ -66,6 +68,8 @@ namespace repertory::ui { } catch (const std::exception &ex) { utils::error::raise_error(function_name, ex, "failed to stop ui"); } + + repertory::project_cleanup(); }; std::signal(SIGINT, quit_handler); @@ -75,24 +79,17 @@ namespace repertory::ui { std::signal(SIGTERM, quit_handler); try { - server->start(); + server.start(); } catch (const std::exception &ex) { utils::error::raise_error(function_name, ex, "failed to start ui"); } - try { - server->stop(); - } catch (const std::exception &ex) { - utils::error::raise_error(function_name, ex, "failed to stop ui"); - } - - repertory::project_cleanup(); + quit_handler(SIGTERM); + return 0; }; #if defined(_WIN32) - ui_server server(&config); - run_ui(&server); - return 0; + return run_ui(); #else // !defined(_WIN32) repertory::project_cleanup(); @@ -106,9 +103,7 @@ namespace repertory::ui { return -1; } - ui_server server(&config); - run_ui(&server); - return 0; + return run_ui(); }); #endif // defined(_WIN32) }