70
src/main.cpp
70
src/main.cpp
@@ -17,43 +17,12 @@
|
||||
|
||||
#include "App.hpp"
|
||||
|
||||
namespace Waylight {
|
||||
|
||||
bool signal_running();
|
||||
|
||||
std::optional<App> g_app {};
|
||||
|
||||
auto main() -> int
|
||||
{
|
||||
if (signal_running()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::signal(SIGINT, [](int) {
|
||||
if (g_app)
|
||||
g_app->stop();
|
||||
});
|
||||
|
||||
CPPTRACE_TRY
|
||||
{
|
||||
g_app.emplace();
|
||||
g_app->run();
|
||||
}
|
||||
CPPTRACE_CATCH(std::exception const &e)
|
||||
{
|
||||
std::string what { e.what() };
|
||||
std::ranges::replace(what, '"', '.');
|
||||
std::ranges::replace(what, '\'', '.');
|
||||
std::ranges::replace(what, '`', '.');
|
||||
if (what.empty()) {
|
||||
std::println(std::cerr, "Unexpected exception!");
|
||||
} else {
|
||||
std::println(std::cerr, "Unexpected exception! Error: {}", what);
|
||||
}
|
||||
cpptrace::from_current_exception().print();
|
||||
tinyfd_messageBox(
|
||||
"Unexpected exception", what.c_str(), "ok", "error", 1);
|
||||
}
|
||||
}
|
||||
|
||||
bool signal_running()
|
||||
{
|
||||
char const *lock_path = "/tmp/waylight.lock";
|
||||
@@ -82,3 +51,38 @@ bool signal_running()
|
||||
dprintf(fd, "%d\n", getpid());
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace Waylight
|
||||
|
||||
auto main() -> int
|
||||
{
|
||||
if (Waylight::signal_running()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::signal(SIGINT, [](int) {
|
||||
if (Waylight::g_app)
|
||||
Waylight::g_app->stop();
|
||||
});
|
||||
|
||||
CPPTRACE_TRY
|
||||
{
|
||||
Waylight::g_app.emplace();
|
||||
Waylight::g_app->run();
|
||||
}
|
||||
CPPTRACE_CATCH(std::exception const &e)
|
||||
{
|
||||
std::string what { e.what() };
|
||||
std::ranges::replace(what, '"', '.');
|
||||
std::ranges::replace(what, '\'', '.');
|
||||
std::ranges::replace(what, '`', '.');
|
||||
if (what.empty()) {
|
||||
std::println(std::cerr, "Unexpected exception!");
|
||||
} else {
|
||||
std::println(std::cerr, "Unexpected exception! Error: {}", what);
|
||||
}
|
||||
cpptrace::from_current_exception().print();
|
||||
tinyfd_messageBox(
|
||||
"Unexpected exception", what.c_str(), "ok", "error", 1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user