Show consent to share crash data only when there are something to share

This commit is contained in:
David Capello 2021-09-23 20:40:02 -03:00
parent 8512ea6f98
commit c6c1393402
3 changed files with 29 additions and 2 deletions

View File

@ -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

View File

@ -13,6 +13,8 @@
#include "sentry.h"
#include <string>
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

View File

@ -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]{