diff --git a/src/app/sentry_wrapper.cpp b/src/app/sentry_wrapper.cpp index 3154faa6c..0dd6a8cf0 100644 --- a/src/app/sentry_wrapper.cpp +++ b/src/app/sentry_wrapper.cpp @@ -11,6 +11,7 @@ #include "app/sentry_wrapper.h" #include "app/resource_finder.h" +#include "base/fs.h" #include "base/string.h" #include "ver/info.h" @@ -18,6 +19,9 @@ namespace app { +// Directory where Sentry database is saved. +std::string Sentry::m_dbdir; + void Sentry::init() { sentry_options_t* options = sentry_options_new(); @@ -70,17 +74,32 @@ void Sentry::revokeConsent() sentry_user_consent_revoke(); } +// static +bool Sentry::areThereCrashesToReport() +{ + if (m_dbdir.empty()) + return false; + + for (auto f : base::list_files(base::join_path(m_dbdir, "completed"))) { + if (base::get_file_extension(f) == "dmp") + return true; // At least one .dmp file in the completed/ directory + } + return false; +} + void Sentry::setupDirs(sentry_options_t* options) { ResourceFinder rf; rf.includeUserDir("crashdb"); - std::string dir = rf.getFirstOrCreateDefault(); + const std::string dir = rf.getFirstOrCreateDefault(); #if SENTRY_PLATFORM_WINDOWS sentry_options_set_database_pathw(options, base::from_utf8(dir).c_str()); #else sentry_options_set_database_path(options, dir.c_str()); #endif + + m_dbdir = dir; } } // namespace app diff --git a/src/app/sentry_wrapper.h b/src/app/sentry_wrapper.h index 6a78df3e2..97873016c 100644 --- a/src/app/sentry_wrapper.h +++ b/src/app/sentry_wrapper.h @@ -13,6 +13,8 @@ #include "sentry.h" +#include + namespace app { class Sentry { @@ -25,10 +27,15 @@ public: static void giveConsent(); static void revokeConsent(); + // Returns true if there are some crash to report. Used to display + // the "give consent" check box for first time. + static bool areThereCrashesToReport(); + private: void setupDirs(sentry_options_t* options); bool m_init = false; + static std::string m_dbdir; }; } // namespace app diff --git a/src/app/ui/home_view.cpp b/src/app/ui/home_view.cpp index 7a95f0720..482773b8c 100644 --- a/src/app/ui/home_view.cpp +++ b/src/app/ui/home_view.cpp @@ -75,7 +75,8 @@ HomeView::HomeView() #if ENABLE_SENTRY // Show this option in home tab only when we require consent for the // first time and there is crash data available to report - if (Sentry::requireConsent()) { + if (Sentry::requireConsent() && + Sentry::areThereCrashesToReport()) { shareCrashdb()->setVisible(true); shareCrashdb()->Click.connect( [this]{