Ask for consent to share crash data

This commit is contained in:
David Capello 2021-09-23 15:14:03 -03:00
parent 6cafec8d06
commit 0c604ca4ba
11 changed files with 118 additions and 3 deletions

View File

@ -723,6 +723,9 @@
<style id="workspace_tabs">
<background color="workspace" />
</style>
<style id="workspace_check_box" extends="check_box" padding="4">
<text color="workspace_text" align="left middle" x="14" />
</style>
<style id="tab">
<background part="tab_normal" align="middle" />
<background part="tab_active" align="middle" state="focus" />

View File

@ -731,6 +731,11 @@ Recover files from crashed sessions or
closed sprite that were not saved in
previous sessions.
END
share_crashdb = Share crash data with Aseprite developers
share_crashdb_tooltip = <<<END
Give consent to share crash data with Aseprite developers
automatically to fix bugs for all users.
END
recent_files = Recent files:
recent_folders = Recent folders:
news = News:

View File

@ -1,5 +1,5 @@
<!-- Aseprite -->
<!-- Copyright (C) 2019 Igara Studio S.A. -->
<!-- Copyright (C) 2019-2021 Igara Studio S.A. -->
<!-- Copyright (C) 2001-2017 David Capello -->
<gui>
<vbox noborders="true" id="home_view" border="4" childspacing="2" expansive="true">
@ -14,6 +14,8 @@
</vbox>
<boxfiller />
<vbox border="4">
<check id="share_crashdb" text="@.share_crashdb"
tooltip="@.share_crashdb_tooltip" style="workspace_check_box" />
<link id="check_update" text="" style="workspace_link" />
</vbox>
</hbox>

View File

@ -68,6 +68,9 @@
text="@.color_bar_entries_separator"
tooltip="@.color_bar_entries_separator"
pref="color_bar.entries_separator" />
<check id="share_crashdb"
text="@home_view.share_crashdb"
tooltip="@home_view.share_crashdb_tooltip" />
<separator horizontal="true" />
<link id="locate_file" text="@.locate_file" />

View File

@ -27,6 +27,7 @@
#include "app/resource_finder.h"
#include "app/tx.h"
#include "app/ui/color_button.h"
#include "app/ui/main_window.h"
#include "app/ui/pref_widget.h"
#include "app/ui/separator_in_view.h"
#include "app/ui/skin/skin_theme.h"
@ -42,6 +43,10 @@
#include "render/render.h"
#include "ui/ui.h"
#if ENABLE_SENTRY
#include "app/sentry_wrapper.h"
#endif
#include "options.xml.h"
namespace app {
@ -490,6 +495,13 @@ public:
else
locateCrashFolder()->setVisible(false);
// Share crashdb
#if ENABLE_SENTRY
shareCrashdb()->setSelected(Sentry::consentGiven());
#else
shareCrashdb()->setVisible(false);
#endif
// Undo preferences
limitUndo()->Click.connect([this]{ onLimitUndoCheck(); });
limitUndo()->setSelected(m_pref.undo.sizeLimit() != 0);
@ -541,6 +553,15 @@ public:
sendMessage(msg);
}
// Share crashdb
#if ENABLE_SENTRY
if (shareCrashdb()->isSelected())
Sentry::giveConsent();
else
Sentry::revokeConsent();
App::instance()->mainWindow()->updateConsentCheckbox();
#endif
// Update language
Strings::instance()->setCurrentLanguage(
language()->getItemText(language()->getSelectedItemIndex()));

View File

@ -33,6 +33,9 @@ void Sentry::init()
setupDirs(options);
// We require the user consent to upload files.
sentry_options_set_require_user_consent(options, 1);
if (sentry_init(options) == 0)
m_init = true;
}
@ -43,6 +46,30 @@ Sentry::~Sentry()
sentry_close();
}
// static
bool Sentry::requireConsent()
{
return (sentry_user_consent_get() != SENTRY_USER_CONSENT_GIVEN);
}
// static
bool Sentry::consentGiven()
{
return (sentry_user_consent_get() == SENTRY_USER_CONSENT_GIVEN);
}
// static
void Sentry::giveConsent()
{
sentry_user_consent_give();
}
// static
void Sentry::revokeConsent()
{
sentry_user_consent_revoke();
}
void Sentry::setupDirs(sentry_options_t* options)
{
ResourceFinder rf;

View File

@ -20,6 +20,11 @@ public:
void init();
~Sentry();
static bool requireConsent();
static bool consentGiven();
static void giveConsent();
static void revokeConsent();
private:
void setupDirs(sentry_options_t* options);

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019-2020 Igara Studio S.A.
// Copyright (C) 2019-2021 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -38,6 +38,10 @@
#include "app/ui/news_listbox.h"
#endif
#if ENABLE_SENTRY
#include "app/sentry_wrapper.h"
#endif
namespace app {
using namespace ui;
@ -66,6 +70,22 @@ HomeView::HomeView()
#endif
checkUpdate()->setVisible(false);
shareCrashdb()->setVisible(false);
#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()) {
shareCrashdb()->setVisible(true);
shareCrashdb()->Click.connect(
[this]{
if (shareCrashdb()->isSelected())
Sentry::giveConsent();
else
Sentry::revokeConsent();
});
}
#endif
InitTheme.connect(
[this]{
@ -101,6 +121,21 @@ void HomeView::dataRecoverySessionsAreReady()
#endif
}
#if ENABLE_SENTRY
void HomeView::updateConsentCheckbox()
{
if (Sentry::requireConsent()) {
shareCrashdb()->setVisible(true);
shareCrashdb()->setSelected(false);
}
else if (Sentry::consentGiven()) {
shareCrashdb()->setVisible(false);
shareCrashdb()->setSelected(true);
}
layout();
}
#endif
std::string HomeView::getTabText()
{
return Strings::home_view_title();

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019 Igara Studio S.A.
// Copyright (C) 2019-2021 Igara Studio S.A.
// Copyright (C) 2001-2016 David Capello
//
// This program is distributed under the terms of
@ -46,6 +46,10 @@ namespace app {
// function is called.
void dataRecoverySessionsAreReady();
#if ENABLE_SENTRY
void updateConsentCheckbox();
#endif
// TabView implementation
std::string getTabText() override;
TabIcon getTabIcon() override;

View File

@ -223,6 +223,13 @@ CheckUpdateDelegate* MainWindow::getCheckUpdateDelegate()
}
#endif
#if ENABLE_SENTRY
void MainWindow::updateConsentCheckbox()
{
getHomeView()->updateConsentCheckbox();
}
#endif
void MainWindow::showNotification(INotificationDelegate* del)
{
m_notifications->addLink(del);

View File

@ -66,6 +66,9 @@ namespace app {
#ifdef ENABLE_UPDATER
CheckUpdateDelegate* getCheckUpdateDelegate();
#endif
#if ENABLE_SENTRY
void updateConsentCheckbox();
#endif
void start();
void showNotification(INotificationDelegate* del);