diff options
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 54 |
1 files changed, 30 insertions, 24 deletions
diff --git a/src/main.cpp b/src/main.cpp index 10d54958..fa4195ce 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -28,8 +28,9 @@ #include "GpgFrontendBuildInfo.h" #include "gpg/GpgContext.h" -#include "gpg/function/GpgKeyGetter.h" +#include "gpg/GpgFunctionObject.h" #include "ui/MainWindow.h" +#include "ui/function/CtxCheckThread.h" #include "ui/settings/GlobalSettingStation.h" // Easy Logging Cpp @@ -78,7 +79,9 @@ int main(int argc, char* argv[]) { #if !defined(RELEASE) && defined(WINDOWS) // css - boost::filesystem::path css_path = GpgFrontend::UI::GlobalSettingStation::GetInstance().GetResourceDir() / "css" / "default.qss"; + boost::filesystem::path css_path = + GpgFrontend::UI::GlobalSettingStation::GetInstance().GetResourceDir() / + "css" / "default.qss"; QFile file(css_path.string().c_str()); file.open(QFile::ReadOnly); QString styleSheet = QLatin1String(file.readAll()); @@ -86,21 +89,20 @@ int main(int argc, char* argv[]) { file.close(); #endif - auto* init_ctx_thread = QThread::create([]() { - // 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); - } - // Try fetching key - GpgFrontend::GpgKeyGetter::GetInstance().FetchKey(); - }); +#ifdef GPG_STANDALONE_MODE + LOG(INFO) << "GPG_STANDALONE_MODE Enabled"; + auto gpg_path = GpgFrontend::UI::GlobalSettingStation::GetInstance() + .GetStandaloneGpgBinDir(); + auto db_path = GpgFrontend::UI::GlobalSettingStation::GetInstance() + .GetStandaloneDatabaseDir(); + GpgFrontend::GpgContext::CreateInstance( + GpgFrontend::SingletonFunctionObject< + GpgFrontend::GpgContext>::GetDefaultChannel(), + std::make_unique<GpgFrontend::GpgContext>(true, db_path.string(), true, + gpg_path.string())); +#endif + + auto* init_ctx_thread = new GpgFrontend::UI::CtxCheckThread(); QApplication::connect(init_ctx_thread, &QThread::finished, init_ctx_thread, &QThread::deleteLater); @@ -118,9 +120,13 @@ int main(int argc, char* argv[]) { waiting_dialog_label->setWordWrap(true); waiting_dialog->setLabel(waiting_dialog_label); waiting_dialog->resize(420, 120); + QApplication::connect(init_ctx_thread, &QThread::finished, [=]() { + waiting_dialog->finished(0); + waiting_dialog->deleteLater(); + }); QApplication::connect(waiting_dialog, &QProgressDialog::canceled, [=]() { LOG(INFO) << "cancel clicked"; - init_ctx_thread->terminate(); + if (init_ctx_thread->isRunning()) init_ctx_thread->terminate(); QCoreApplication::quit(); exit(0); }); @@ -130,11 +136,10 @@ int main(int argc, char* argv[]) { waiting_dialog->setFocus(); init_ctx_thread->start(); - while (init_ctx_thread->isRunning()) { - QApplication::processEvents(); - } - waiting_dialog->finished(0); - waiting_dialog->deleteLater(); + QEventLoop loop; + QApplication::connect(init_ctx_thread, &QThread::finished, &loop, + &QEventLoop::quit); + loop.exec(); /** * internationalisation. loop to restart main window @@ -149,7 +154,6 @@ int main(int argc, char* argv[]) { int r = setjmp(recover_env); #endif if (!r) { - try { // i18n init_locale(); @@ -169,10 +173,12 @@ int main(int argc, char* argv[]) { "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; } } else { + QApplication::exit(RESTART_CODE); QMessageBox::information( nullptr, _("A serious error has occurred"), _("Oh no! GpgFrontend caught a serious error in the software, so it " |