diff options
author | Saturneric <[email protected]> | 2021-12-13 11:24:42 +0000 |
---|---|---|
committer | Saturneric <[email protected]> | 2021-12-13 11:24:42 +0000 |
commit | 53ab9c982e7d895d48d5ddddf7bae2022e9c583a (patch) | |
tree | 2a610bf2cb303a0410344336952811155ff53b10 /src | |
parent | Update Translate & Added. (diff) | |
download | GpgFrontend-53ab9c982e7d895d48d5ddddf7bae2022e9c583a.tar.gz GpgFrontend-53ab9c982e7d895d48d5ddddf7bae2022e9c583a.zip |
Add Stable Restart from Exception Function
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 42 | ||||
-rw-r--r-- | src/ui/MainWindow.cpp | 12 |
2 files changed, 32 insertions, 22 deletions
diff --git a/src/main.cpp b/src/main.cpp index 3bd9e8a1..aad4b8fd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,7 +25,9 @@ #include <cstdlib> #include "GpgFrontendBuildInfo.h" +#include "gpg/GpgContext.h" #include "ui/MainWindow.h" +#include "ui/WaitingDialog.h" #include "ui/settings/GlobalSettingStation.h" // Easy Logging Cpp @@ -78,17 +80,37 @@ int main(int argc, char* argv[]) { */ int return_from_event_loop_code; - do { - // i18n - init_locale(); - - QApplication::setQuitOnLastWindowClosed(true); - - auto main_window = std::make_unique<GpgFrontend::UI::MainWindow>(); - main_window->init(); - main_window->show(); - return_from_event_loop_code = QApplication::exec(); + // Create & Check Gnupg Context Status + if (!GpgFrontend::GpgContext::GetInstance().good()) { + QMessageBox::critical( + nullptr, _("ENV Loading Failed"), + _("Gnupg(gpg) is not installed correctly, please follow the " + "ReadME " + "instructions in Github to install Gnupg and then open " + "GpgFrontend.")); + QCoreApplication::quit(); + exit(0); + } + do { + try { + // i18n + init_locale(); + + QApplication::setQuitOnLastWindowClosed(true); + + auto main_window = std::make_unique<GpgFrontend::UI::MainWindow>(); + main_window->init(); + main_window->show(); + return_from_event_loop_code = QApplication::exec(); + + } catch (...) { + 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.")); + continue; + } } while (return_from_event_loop_code == RESTART_CODE); return return_from_event_loop_code; diff --git a/src/ui/MainWindow.cpp b/src/ui/MainWindow.cpp index f9266297..6d55aeb5 100644 --- a/src/ui/MainWindow.cpp +++ b/src/ui/MainWindow.cpp @@ -38,18 +38,7 @@ MainWindow::MainWindow() { } void MainWindow::init() noexcept { - LOG(INFO) << _("Called"); try { - // Check Context Status - if (!GpgContext::GetInstance().good()) { - QMessageBox::critical( - nullptr, _("ENV Loading Failed"), - _("Gnupg is not installed correctly, please follow the ReadME " - "instructions to install gnupg and then open GpgFrontend.")); - QCoreApplication::quit(); - exit(0); - } - networkAccessManager = new QNetworkAccessManager(this); /* get path where app was started */ @@ -139,7 +128,6 @@ void MainWindow::init() noexcept { version_thread->start(); #endif - } catch (...) { LOG(FATAL) << _("Critical error occur while loading GpgFrontend."); QMessageBox::critical(nullptr, _("Loading Failed"), |