diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index 2040a86e7..1de4c0d21 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -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() diff --git a/src/app/sentry_wrapper.cpp b/src/app/sentry_wrapper.cpp new file mode 100644 index 000000000..06411b10b --- /dev/null +++ b/src/app/sentry_wrapper.cpp @@ -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 diff --git a/src/app/sentry_wrapper.h b/src/app/sentry_wrapper.h index 3eb9805f0..eac861848 100644 --- a/src/app/sentry_wrapper.h +++ b/src/app/sentry_wrapper.h @@ -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; };