From 2a2477eda0cb32b5d4dc2fb47aeebc02336eca39 Mon Sep 17 00:00:00 2001 From: Dmitry Vedenko Date: Wed, 14 Jul 2021 22:15:11 +0300 Subject: [PATCH] Adds a dialog, that notifies the user about update checks. This dialog is only shown once. It has links to privacy policy and application preferences. --- src/CMakeLists.txt | 2 + src/prefs/KeyConfigPrefs.cpp | 4 +- src/prefs/PrefsDialog.cpp | 5 ++ src/update/UpdateManager.cpp | 22 ++++++ src/update/UpdateNoticeDialog.cpp | 127 ++++++++++++++++++++++++++++++ src/update/UpdateNoticeDialog.h | 30 +++++++ 6 files changed, 189 insertions(+), 1 deletion(-) create mode 100644 src/update/UpdateNoticeDialog.cpp create mode 100644 src/update/UpdateNoticeDialog.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 23c8d5929..4fa7af0e4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -995,6 +995,8 @@ list( APPEND SOURCES update/UpdateDataParser.cpp update/UpdateManager.h update/UpdateManager.cpp + update/UpdateNoticeDialog.h + update/UpdateNoticeDialog.cpp update/UpdatePopupDialog.h update/UpdatePopupDialog.cpp prefs/ApplicationPrefs.h diff --git a/src/prefs/KeyConfigPrefs.cpp b/src/prefs/KeyConfigPrefs.cpp index 1d1def9a3..b7c25c1ef 100644 --- a/src/prefs/KeyConfigPrefs.cpp +++ b/src/prefs/KeyConfigPrefs.cpp @@ -475,7 +475,9 @@ void KeyConfigPrefs::OnShow(wxShowEvent & event) { event.Skip(); - if (event.IsShown()) + // This is required to prevent a crash if Preferences + // were opened without a project. + if (event.IsShown() && mView != nullptr) { mView->Refresh(); } diff --git a/src/prefs/PrefsDialog.cpp b/src/prefs/PrefsDialog.cpp index 5db3d0fdb..eb63a90cf 100644 --- a/src/prefs/PrefsDialog.cpp +++ b/src/prefs/PrefsDialog.cpp @@ -782,6 +782,11 @@ void PrefsDialog::SelectPageByName(const wxString &pageName) for (size_t i = 0; i < n; i++) { if (mCategories->GetPageText(i) == pageName) { mCategories->SetSelection(i); + // This covers the case, when ShowModal is called + // after selecting the page. + // ShowModal will select the page previously used by + // user + SavePreferredPage(); return; } } diff --git a/src/update/UpdateManager.cpp b/src/update/UpdateManager.cpp index f7637f4db..5270536b3 100644 --- a/src/update/UpdateManager.cpp +++ b/src/update/UpdateManager.cpp @@ -8,7 +8,9 @@ **********************************************************************/ #include "UpdateManager.h" + #include "UpdatePopupDialog.h" +#include "UpdateNoticeDialog.h" #include "AudioIO.h" #include "NetworkManager.h" @@ -26,6 +28,9 @@ static const char* prefsUpdateScheduledTime = "/Update/UpdateScheduledTime"; +static BoolSetting + prefUpdatesNoticeShown(wxT("/Update/UpdateNoticeShown"), false); + using Clock = std::chrono::system_clock; using TimePoint = Clock::time_point; @@ -51,10 +56,27 @@ void UpdateManager::Start() auto& instance = GetInstance(); static std::once_flag flag; + std::call_once(flag, [&instance] { instance.mTimer.SetOwner(&instance, ID_TIMER); instance.mTimer.StartOnce(1); }); + + // Show the dialog only once. + if (!prefUpdatesNoticeShown.Read()) + { + // DefaultUpdatesCheckingFlag survives the "Reset Preferences" + // action, so check, if the updates were previously disabled as well. + if (DefaultUpdatesCheckingFlag.Read()) + { + UpdateNoticeDialog notice(nullptr); + + notice.ShowModal(); + } + + prefUpdatesNoticeShown.Write(true); + gPrefs->Flush(); + } } VersionPatch UpdateManager::GetVersionPatch() const diff --git a/src/update/UpdateNoticeDialog.cpp b/src/update/UpdateNoticeDialog.cpp new file mode 100644 index 000000000..66735a368 --- /dev/null +++ b/src/update/UpdateNoticeDialog.cpp @@ -0,0 +1,127 @@ + +/*!******************************************************************** + + Audacity: A Digital Audio Editor + + @file UpdateNoticeDialog.cpp + @brief Declare a dialog to notify the user about automatic update checking. + + Dmitry Vedenko + **********************************************************************/ + +#include "UpdateNoticeDialog.h" + +#include +#include + +#include "ShuttleGui.h" +#include "CodeConversions.h" +#include "prefs/PrefsDialog.h" +#include "ui/AccessibleLinksFormatter.h" + + +static const auto title = + /* i18n-hint: Title of the app update notice dialog. */ + XO("App update checking"); + +static const auto firstParagraph = + /* i18-hint: The first paragraph of app update notice dialog. */ + XO("To stay up to date, you will receive an in-app notification whenever there is a new version of Audacity available to download."); + +static const auto secondParagraph = + /* i18-hint: The second paragraph of app update notice dialog */ + XO("In order to protect your privacy, Audacity does not collect any personal information. However, app update checking does require network access."); + +static const auto thirdParagraph = + /* i18-hint: Hint to the user about how to turn the app update off. %s is replaced with "Preferences > Application" link*/ + XO("You can turn off app update checking at any time in %s."); + + +BEGIN_EVENT_TABLE(UpdateNoticeDialog, wxDialogWrapper) + EVT_BUTTON(wxID_OK, UpdateNoticeDialog::OnOk) +END_EVENT_TABLE() + +IMPLEMENT_CLASS(UpdateNoticeDialog, wxDialogWrapper) + +UpdateNoticeDialog::UpdateNoticeDialog(wxWindow* parent) + : wxDialogWrapper( + /* i18n-hint: Title of the app update notice dialog. */ + parent, -1, XO("App updates"), wxDefaultPosition, wxDefaultSize, + wxCAPTION | wxCLOSE_BOX) +{ + ShuttleGui S(this, eIsCreating); + + S.StartVerticalLay(); + { + S.AddSpace(0, 16); + + S.StartHorizontalLay(); + { + S.AddSpace(24, 0); + + S.StartPanel(); + { + S.SetBorder(8); + + wxStaticText* titleCtrl = S.AddVariableText(title, false, 0, 500); + + wxFont font = titleCtrl->GetFont().MakeLarger().MakeBold(); + + titleCtrl->SetFont(font); + + S.AddFixedText(firstParagraph, false, 500); + + S.AddFixedText(secondParagraph, false, 500); + + /* i18n-hint: %s will be replaced with "our Privacy Policy" */ + AccessibleLinksFormatter privacyPolicy(XO("See %s for more info.")); + + privacyPolicy.FormatLink( + /* i18n-hint: Title of hyperlink to the privacy policy. This is an object of "See". */ + wxT("%s"), XO("our Privacy Policy"), + "https://www.audacityteam.org/about/desktop-privacy-notice/"); + + privacyPolicy.Populate(S); + + S.AddSpace(0, 8); + + AccessibleLinksFormatter preferencesMessage(thirdParagraph); + + preferencesMessage.FormatLink( + wxT("%s"), XO("Preferences > Application"), [this]() { + GlobalPrefsDialog dialog(this /* parent */, nullptr); + + dialog.SelectPageByName(XO("Application").Translation()); + dialog.ShowModal(); + }); + + preferencesMessage.Populate(S); + } + S.EndPanel(); + + S.AddSpace(24, 0); + } + S.EndHorizontalLay(); + + S.StartHorizontalLay(wxEXPAND, 0); + { + S.AddSpace(1, 0, 1); + + S.Id(wxID_OK).AddButton(XO("&OK"))->SetFocus(); + + S.AddSpace(8, 0); + } + S.EndHorizontalLay(); + } + + S.EndVerticalLay(); + + Layout(); + Fit(); + Center(); +} + +void UpdateNoticeDialog::OnOk(wxCommandEvent&) +{ + EndModal(wxOK); +} diff --git a/src/update/UpdateNoticeDialog.h b/src/update/UpdateNoticeDialog.h new file mode 100644 index 000000000..c9bf6b154 --- /dev/null +++ b/src/update/UpdateNoticeDialog.h @@ -0,0 +1,30 @@ +/*!******************************************************************** + + Audacity: A Digital Audio Editor + + @file UpdateNoticeDialog.h + @brief Define a dialog to notify the user about automatic update checking. + + Dmitry Vedenko + **********************************************************************/ + +#pragma once + +#include "widgets/wxPanelWrapper.h" +#include "wx/string.h" + +class HtmlWindow; +class wxWindow; + +//! Dialog, that notifies the users about automatic updates checking +class UpdateNoticeDialog final : public wxDialogWrapper +{ + DECLARE_DYNAMIC_CLASS (AboutDialog) +public: + explicit UpdateNoticeDialog (wxWindow* parent); + + private: + void OnOk (wxCommandEvent& event); + + DECLARE_EVENT_TABLE () +};