diff options
author | Saturn&Eric <[email protected]> | 2022-05-20 19:13:55 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2022-05-20 19:13:55 +0000 |
commit | 306cc5b41af9596875c2999af638eaa35899e404 (patch) | |
tree | 6d8d5b3cdb35e79527d33c63d4e69995f9c3f2df /src/main.cpp | |
parent | Merge pull request #65 from saturneric/develop-2.0.8 (diff) | |
parent | fix(ui): there is possible null pointer dereference (diff) | |
download | GpgFrontend-306cc5b41af9596875c2999af638eaa35899e404.tar.gz GpgFrontend-306cc5b41af9596875c2999af638eaa35899e404.zip |
Merge pull request #66 from saturneric/develop-2.0.8
Develop 2.0.8.2
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 115 |
1 files changed, 41 insertions, 74 deletions
diff --git a/src/main.cpp b/src/main.cpp index fd20a664..b51c44ea 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -32,16 +32,11 @@ #include <csetjmp> #include <csignal> -#include <cstdlib> +#include <cstddef> -#include "GpgFrontendBuildInfo.h" -#include "core/GpgFunctionObject.h" +#include "core/GpgCoreInit.h" +#include "ui/GpgFrontendApplication.h" #include "ui/GpgFrontendUIInit.h" -#include "ui/main_window/MainWindow.h" - -#if !defined(RELEASE) && defined(WINDOWS) -#include "core/function/GlobalSettingStation.h" -#endif /** * \brief initialize the easylogging++ library. @@ -53,20 +48,28 @@ INITIALIZE_EASYLOGGINGPP */ jmp_buf recover_env; +constexpr int CRASH_CODE = ~0; ///< + /** - * @brief + * @brief handle the signal SIGSEGV * * @param sig */ extern void handle_signal(int sig); /** - * @brief + * @brief processes before exit the program. * */ extern void before_exit(); /** + * @brief initialize the logging system. + * + */ +extern void init_logging_system(); + +/** * * @param argc * @param argv @@ -85,38 +88,14 @@ int main(int argc, char* argv[]) { Q_INIT_RESOURCE(gpgfrontend); // create qt application - QApplication app(argc, argv); - -#ifndef MACOS - QApplication::setWindowIcon(QIcon(":gpgfrontend.png")); -#endif + auto* app = + GpgFrontend::UI::GpgFrontendApplication::GetInstance(argc, argv, true); -#ifdef MACOS - // support retina screen - QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); -#endif + // init the logging system + init_logging_system(); - // set the extra information of the build - QApplication::setApplicationVersion(BUILD_VERSION); - QApplication::setApplicationName(PROJECT_NAME); - - // don't show icons in menus - QApplication::setAttribute(Qt::AA_DontShowIconsInMenus); - - // unicode in source - QTextCodec::setCodecForLocale(QTextCodec::codecForName("utf-8")); - -#if !defined(RELEASE) && defined(WINDOWS) - // css - std::filesystem::path css_path = - GpgFrontend::GlobalSettingStation::GetInstance().GetResourceDir() / - "css" / "default.qss"; - QFile file(css_path.u8string().c_str()); - file.open(QFile::ReadOnly); - QString styleSheet = QLatin1String(file.readAll()); - qApp->setStyleSheet(styleSheet); - file.close(); -#endif + // init the logging system for core + GpgFrontend::InitLoggingSystem(); /** * internationalisation. loop to restart main window @@ -131,45 +110,33 @@ int main(int argc, char* argv[]) { int r = setjmp(recover_env); #endif if (!r) { -#ifdef RELEASE - try { -#endif - QApplication::setQuitOnLastWindowClosed(true); - - // init ui library - GpgFrontend::UI::InitGpgFrontendUI(); - - // create main window - return_from_event_loop_code = GpgFrontend::UI::RunGpgFrontendUI(); -#ifdef RELEASE - } catch (...) { - // catch all unhandled exceptions and notify the user - QMessageBox::information( - nullptr, _("Unhandled Exception Thrown"), - _("Oops, an unhandled exception was thrown " - "during the running of the " - "program, and now it needs to be restarted. This is not a " - "serious problem, it may be the negligence of the programmer, " - "please report this problem if you can.")); - return_from_event_loop_code = RESTART_CODE; - continue; - } -#endif + // init ui library + GpgFrontend::UI::InitGpgFrontendUI(app); + // create main window + return_from_event_loop_code = GpgFrontend::UI::RunGpgFrontendUI(app); } else { + LOG(ERROR) << "recover from a crash"; // when signal is caught, restart the main window - QMessageBox::information( - nullptr, _("A serious error has occurred"), - _("Oh no! GpgFrontend caught a serious error in the software, so it " - "needs to be restarted. If the problem recurs, please manually " - "terminate the program and report the problem to the developer.")); - QCoreApplication::quit(); - return_from_event_loop_code = RESTART_CODE; - LOG(INFO) << "return_from_event_loop_code" << return_from_event_loop_code; - continue; + auto* message_box = new QMessageBox( + QMessageBox::Critical, _("A serious error has occurred"), + _("Oh no! GpgFrontend caught a serious error in the software, so " + "it needs to be restarted. If the problem recurs, please " + "manually terminate the program and report the problem to the " + "developer."), + QMessageBox::Ok, nullptr); + message_box->exec(); + return_from_event_loop_code = CRASH_CODE; + } + + if (return_from_event_loop_code == CRASH_CODE) { + app = GpgFrontend::UI::GpgFrontendApplication::GetInstance(argc, argv, + true); } + LOG(INFO) << "loop refresh"; - } while (return_from_event_loop_code == RESTART_CODE); + } while (return_from_event_loop_code == RESTART_CODE || + return_from_event_loop_code == CRASH_CODE); // exit the program return return_from_event_loop_code; |