1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-16 16:10:06 +02:00

Add recommends from review.

This commit is contained in:
gera 2021-06-11 00:12:02 +03:00 committed by Paul Licameli
parent 0ab6aefe11
commit c7a24df915
5 changed files with 35 additions and 38 deletions

View File

@ -193,7 +193,7 @@ cmake_dependent_option(
cmake_dependent_option(
${_OPT}has_updates_check
"Has a builtin support for checking of updates"
"Build updates checking features into Audacity"
On
"${_OPT}has_networking"
Off

View File

@ -1491,7 +1491,7 @@ bool AudacityApp::InitPart2()
}
#if defined(HAVE_UPDATES_CHECK)
mUpdateManager = std::make_unique<UpdateManager>(*project);
mUpdateManager = std::make_unique<UpdateManager>();
#endif
#ifdef USE_FFMPEG

View File

@ -14,10 +14,11 @@
#include "IResponse.h"
#include "Request.h"
#include "widgets/AudacityMessageBox.h"
#include "widgets/ErrorDialog.h"
#include <wx/platinfo.h>
#include <wx/utils.h>
#include <wx/frame.h>
static const char* prefsUpdatePopupDialogShown = "/Update/UpdatePopupDialogShown";
static const char* prefsUpdateScheduledTime = "/Update/UpdateScheduledTime";
@ -28,13 +29,10 @@ BEGIN_EVENT_TABLE(UpdateManager, wxEvtHandler)
EVT_TIMER(ID_TIMER, UpdateManager::OnTimer)
END_EVENT_TABLE()
UpdateManager::UpdateManager(AudacityProject& project)
UpdateManager::UpdateManager()
: mTrackingInterval(
std::chrono::milliseconds(std::chrono::hours(12)).count())
{
mParent = (wxWindow*)(&GetProjectFrame(project));
wxASSERT(mParent);
mTimer.SetOwner(this, ID_TIMER);
mTimer.StartOnce();
}
@ -44,13 +42,13 @@ UpdateManager::~UpdateManager()
mTimer.Stop();
}
void UpdateManager::enableTracking(bool enable)
void UpdateManager::enableUpdatesChecking(bool enable)
{
gPrefs->Write(prefsUpdatePopupDialogShown, enable);
gPrefs->Flush();
}
bool UpdateManager::isTrackingEnabled()
bool UpdateManager::isUpdatesCheckingEnabled()
{
return gPrefs->ReadBool(prefsUpdatePopupDialogShown, true);
}
@ -62,48 +60,50 @@ VersionPatch UpdateManager::getVersionPatch() const
void UpdateManager::getUpdates()
{
audacity::network_manager::Request request("https://updates.audacityteam.org/feed/latest.xml");
const audacity::network_manager::Request request("https://updates.audacityteam.org/feed/latest.xml");
auto response = audacity::network_manager::NetworkManager::GetInstance().doGet(request);
response->setRequestFinishedCallback([response, this](audacity::network_manager::IResponse*) {
wxFrame* parent = FindProjectFrame(GetActiveProject());
wxASSERT(parent);
if (!parent) return;
if (response->getError() != audacity::network_manager::NetworkError::NoError)
{
AudacityMessageBox(
XO("Unable to connect to Audacity update server."),
ShowExceptionDialog(parent,
XO("Error checking for update"),
wxOK | wxCENTRE,
NULL);
XO("Unable to connect to Audacity update server."),
wxString());
return;
}
if (!mUpdateDataParser.Parse(response->readAll<VersionPatch::UpdateDataFormat>(), &mVersionPatch))
{
AudacityMessageBox(
XO("Update data was corrupted."),
ShowExceptionDialog(parent,
XO("Error checking for update"),
wxOK | wxCENTRE,
NULL);
XO("Update data was corrupted."),
wxString());
return;
}
if (mVersionPatch.version > CurrentBuildVersion())
{
mParent->CallAfter([this] {
UpdatePopupDialog dlg(mParent, this);
parent->CallAfter([this, parent] {
UpdatePopupDialog dlg(parent, this);
const int code = dlg.ShowModal();
if (code == wxID_YES)
{
if (!wxLaunchDefaultBrowser(mVersionPatch.download))
{
AudacityMessageBox(
XO("Can't open the Audacity download link."),
ShowExceptionDialog(parent,
XO("Error downloading update"),
wxOK | wxCENTRE,
NULL);
XO("Can't open the Audacity download link."),
wxString());
return;
}
@ -115,7 +115,7 @@ void UpdateManager::getUpdates()
void UpdateManager::OnTimer(wxTimerEvent& WXUNUSED(event))
{
if (isTrackingEnabled() && isTimeToUpdate())
if (isUpdatesCheckingEnabled() && isTimeToUpdate())
getUpdates();
mTimer.StartOnce(mTrackingInterval);
@ -123,7 +123,7 @@ void UpdateManager::OnTimer(wxTimerEvent& WXUNUSED(event))
bool UpdateManager::isTimeToUpdate()
{
long long nextTrackingTime = std::stoll(
long long nextUpdatesCheckingTime = std::stoll(
gPrefs->Read(prefsUpdateScheduledTime, "0").ToStdString());
// Get current time in milliseconds
@ -135,12 +135,12 @@ bool UpdateManager::isTimeToUpdate()
// If next update time 0 or less then current time -> show update dialog,
// else this condition allow us to avoid from duplicating update notifications.
if (nextTrackingTime < currentTimeInMillisec)
if (nextUpdatesCheckingTime < currentTimeInMillisec)
{
nextTrackingTime = currentTimeInMillisec + mTrackingInterval;
nextUpdatesCheckingTime = currentTimeInMillisec + mTrackingInterval;
gPrefs->Write(prefsUpdateScheduledTime,
wxString(std::to_string(nextTrackingTime)));
wxString(std::to_string(nextUpdatesCheckingTime)));
gPrefs->Flush();
return true;

View File

@ -12,7 +12,6 @@
#include "VersionPatch.h"
#include "UpdateDataParser.h"
#include "Project.h"
#include "Prefs.h"
#include <wx/string.h>
@ -28,13 +27,13 @@
class UpdateManager final : public wxEvtHandler
{
public:
UpdateManager(AudacityProject& project);
UpdateManager();
~UpdateManager();
void getUpdates();
void enableTracking(bool enable);
bool isTrackingEnabled();
void enableUpdatesChecking(bool enable);
bool isUpdatesCheckingEnabled();
VersionPatch getVersionPatch() const;
@ -42,14 +41,12 @@ private:
UpdateDataParser mUpdateDataParser;
VersionPatch mVersionPatch;
wxWindow* mParent;
wxTimer mTimer;
const int mTrackingInterval;
void OnTimer(wxTimerEvent& event);
/// Scheduling update time for avoiding multiplying update notifications.
/// Scheduling update time for avoiding multiplying update notifications.
bool isTimeToUpdate();
public:

View File

@ -45,7 +45,7 @@ UpdatePopupDialog::UpdatePopupDialog (wxWindow* parent, UpdateManager* updateMan
S.SetBorder (5);
S.Id (DontShowID).AddCheckBox (
XO ("Don't show this again at start up"), !mUpdateManager->isTrackingEnabled());
XO ("Don't show this again at start up"), !mUpdateManager->isUpdatesCheckingEnabled());
S.Prop(1).AddSpace(1, 0, 1);
@ -80,7 +80,7 @@ void UpdatePopupDialog::OnSkip (wxCommandEvent&)
void UpdatePopupDialog::OnDontShow (wxCommandEvent& event)
{
mUpdateManager->enableTracking(!event.IsChecked());
mUpdateManager->enableUpdatesChecking(!event.IsChecked());
}
HtmlWindow* UpdatePopupDialog::AddHtmlContent (wxWindow* parent)