Move Sentry class impl to a .cpp file

This commit is contained in:
David Capello 2021-09-23 12:55:30 -03:00
parent 024cd73f62
commit 6cafec8d06
3 changed files with 65 additions and 40 deletions

View File

@ -403,7 +403,9 @@ if(ENABLE_UI)
endif()
set(send_crash_files)
if(NOT ENABLE_SENTRY)
if(ENABLE_SENTRY)
set(send_crash_files sentry_wrapper.cpp)
else()
set(send_crash_files send_crash.cpp)
endif()

View File

@ -0,0 +1,59 @@
// Aseprite
// Copyright (C) 2021 Igara Studio S.A.
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "app/sentry_wrapper.h"
#include "app/resource_finder.h"
#include "base/string.h"
#include "ver/info.h"
#include "sentry.h"
namespace app {
void Sentry::init()
{
sentry_options_t* options = sentry_options_new();
sentry_options_set_dsn(options, SENTRY_DNS);
std::string release = "aseprite@";
release += get_app_version();
sentry_options_set_release(options, release.c_str());
#if _DEBUG
sentry_options_set_debug(options, 1);
#endif
setupDirs(options);
if (sentry_init(options) == 0)
m_init = true;
}
Sentry::~Sentry()
{
if (m_init)
sentry_close();
}
void Sentry::setupDirs(sentry_options_t* options)
{
ResourceFinder rf;
rf.includeUserDir("crashdb");
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
}
} // namespace app

View File

@ -11,53 +11,17 @@
#error ENABLE_SENTRY must be defined
#endif
#include "app/resource_finder.h"
#include "base/string.h"
#include "sentry.h"
namespace app {
class Sentry {
public:
void init()
{
sentry_options_t* options = sentry_options_new();
sentry_options_set_dsn(options, SENTRY_DNS);
std::string release = "aseprite@";
release += get_app_version();
sentry_options_set_release(options, release.c_str());
#if _DEBUG
sentry_options_set_debug(options, 1);
#endif
setupDirs(options);
if (sentry_init(options) == 0)
m_init = true;
}
~Sentry()
{
if (m_init)
sentry_close();
}
void init();
~Sentry();
private:
void setupDirs(sentry_options_t* options)
{
ResourceFinder rf;
rf.includeUserDir("crashdb");
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
}
void setupDirs(sentry_options_t* options);
bool m_init = false;
};