From d15d88af71f707406459d4927df61c6019e0f298 Mon Sep 17 00:00:00 2001
From: gera
Date: Fri, 11 Jun 2021 15:44:11 +0300
Subject: [PATCH] Add recommends from review.
---
src/AudacityApp.cpp | 2 +-
src/AudacityApp.h | 4 ---
src/update/UpdateManager.cpp | 57 +++++++++++++++++++++-----------
src/update/UpdateManager.h | 4 +++
src/update/UpdatePopupDialog.cpp | 15 +++++----
src/update/VersionId.cpp | 20 +++--------
6 files changed, 55 insertions(+), 47 deletions(-)
diff --git a/src/AudacityApp.cpp b/src/AudacityApp.cpp
index 5bb5666e7..2a6a89ba2 100644
--- a/src/AudacityApp.cpp
+++ b/src/AudacityApp.cpp
@@ -1491,7 +1491,7 @@ bool AudacityApp::InitPart2()
}
#if defined(HAVE_UPDATES_CHECK)
- mUpdateManager = std::make_unique();
+ UpdateManager::Start();
#endif
#ifdef USE_FFMPEG
diff --git a/src/AudacityApp.h b/src/AudacityApp.h
index aeb556e69..7e4579957 100644
--- a/src/AudacityApp.h
+++ b/src/AudacityApp.h
@@ -114,10 +114,6 @@ class AudacityApp final : public wxApp {
std::unique_ptr mIPCServ;
#endif
-#if defined(HAVE_UPDATES_CHECK)
- std::unique_ptr mUpdateManager;
-#endif
-
public:
DECLARE_EVENT_TABLE()
};
diff --git a/src/update/UpdateManager.cpp b/src/update/UpdateManager.cpp
index 9f3cf4a3b..9ca217661 100644
--- a/src/update/UpdateManager.cpp
+++ b/src/update/UpdateManager.cpp
@@ -34,12 +34,34 @@ UpdateManager::UpdateManager()
std::chrono::milliseconds(std::chrono::hours(12)).count())
{
mTimer.SetOwner(this, ID_TIMER);
- mTimer.StartOnce();
}
UpdateManager::~UpdateManager()
{
- mTimer.Stop();
+ Stop();
+}
+
+UpdateManager& UpdateManager::GetInstance()
+{
+ static UpdateManager updateManager;
+
+ return updateManager;
+}
+
+void UpdateManager::Start()
+{
+ auto& instance = GetInstance();
+
+ if (!instance.mTimer.IsRunning())
+ instance.mTimer.StartOnce();
+}
+
+void UpdateManager::Stop()
+{
+ auto& instance = GetInstance();
+
+ if (instance.mTimer.IsRunning())
+ instance.mTimer.Stop();
}
void UpdateManager::enableUpdatesChecking(bool enable)
@@ -65,47 +87,42 @@ void UpdateManager::getUpdates()
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)
{
- ShowExceptionDialog(parent,
- XO("Error checking for update"),
- XO("Unable to connect to Audacity update server."),
+ wxTheApp->CallAfter([] {ShowExceptionDialog(nullptr,
+ XC("Error checking for update", "update dialog"),
+ XC("Unable to connect to Audacity update server.", "update dialog"),
wxString());
+ });
return;
}
if (!mUpdateDataParser.Parse(response->readAll(), &mVersionPatch))
{
- ShowExceptionDialog(parent,
- XO("Error checking for update"),
- XO("Update data was corrupted."),
+ wxTheApp->CallAfter([] {ShowExceptionDialog(nullptr,
+ XC("Error checking for update", "update dialog"),
+ XC("Update data was corrupted.", "update dialog"),
wxString());
+ });
return;
}
if (mVersionPatch.version > CurrentBuildVersion())
{
- parent->CallAfter([this, parent] {
- UpdatePopupDialog dlg(parent, this);
+ wxTheApp->CallAfter([this] {
+ UpdatePopupDialog dlg(nullptr, this);
const int code = dlg.ShowModal();
if (code == wxID_YES)
{
if (!wxLaunchDefaultBrowser(mVersionPatch.download))
{
- ShowExceptionDialog(parent,
- XO("Error downloading update"),
- XO("Can't open the Audacity download link."),
+ ShowExceptionDialog(nullptr,
+ XC("Error downloading update.", "update dialog"),
+ XC("Can't open the Audacity download link.", "update dialog"),
wxString());
-
- return;
}
}
});
diff --git a/src/update/UpdateManager.h b/src/update/UpdateManager.h
index 51bcf5abb..ebdcafa2c 100644
--- a/src/update/UpdateManager.h
+++ b/src/update/UpdateManager.h
@@ -30,6 +30,10 @@ public:
UpdateManager();
~UpdateManager();
+ static UpdateManager& GetInstance();
+ static void Start();
+ static void Stop();
+
void getUpdates();
void enableUpdatesChecking(bool enable);
diff --git a/src/update/UpdatePopupDialog.cpp b/src/update/UpdatePopupDialog.cpp
index 09e0f75fd..12d5ed5e0 100644
--- a/src/update/UpdatePopupDialog.cpp
+++ b/src/update/UpdatePopupDialog.cpp
@@ -27,7 +27,7 @@ END_EVENT_TABLE()
IMPLEMENT_CLASS (UpdatePopupDialog, wxDialogWrapper)
UpdatePopupDialog::UpdatePopupDialog (wxWindow* parent, UpdateManager* updateManager)
- : wxDialogWrapper (parent, -1, XO ("Update Audacity"),
+ : wxDialogWrapper (parent, -1, XC("Update Audacity", "update dialog"),
wxDefaultPosition, wxDefaultSize,
wxCAPTION),
mUpdateManager (updateManager)
@@ -49,8 +49,8 @@ UpdatePopupDialog::UpdatePopupDialog (wxWindow* parent, UpdateManager* updateMan
S.Prop(1).AddSpace(1, 0, 1);
- S.Id (wxID_NO).AddButton (XO ("Skip"));
- S.Id (wxID_YES).AddButton (XO ("Install update"));
+ S.Id (wxID_NO).AddButton (XC ("&Skip", "update dialog"));
+ S.Id (wxID_YES).AddButton (XC("&Install update", "update dialog"));
S.SetBorder (5);
}
@@ -88,14 +88,15 @@ HtmlWindow* UpdatePopupDialog::AddHtmlContent (wxWindow* parent)
wxStringOutputStream o;
wxTextOutputStream informationStr (o);
- static const auto title = XO("Audacity %s is available!")
+ // i18n-hint Substitution of version number for %s.
+ static const auto title = XC("Audacity %s is available!", "update dialog")
.Format(mUpdateManager->getVersionPatch().version.getString());
informationStr
<< wxT("")
<< title.Translation()
<< wxT("
")
- << XO("Changelog")
+ << XC("Changelog", "update dialog")
<< wxT("
");
informationStr << wxT("
");
@@ -109,7 +110,9 @@ HtmlWindow* UpdatePopupDialog::AddHtmlContent (wxWindow* parent)
informationStr << wxT("
");
informationStr << wxT("");
- informationStr << XO("Read more on GitHub");
+ informationStr << wxT("");
+ informationStr << XC("Read more on GitHub", "update dialog");
+ informationStr << wxT("");
informationStr << wxT("
");
informationStr << wxT("");
diff --git a/src/update/VersionId.cpp b/src/update/VersionId.cpp
index a01c83803..696ac63fa 100644
--- a/src/update/VersionId.cpp
+++ b/src/update/VersionId.cpp
@@ -50,9 +50,8 @@ wxString VersionId::getString() const
bool VersionId::operator== (const VersionId& other)
{
- return mVersion == other.mVersion &&
- mRelease == other.mRelease &&
- mRevision == other.mRevision;
+ return std::tie(mVersion, mRelease, mRevision) ==
+ std::tie(other.mVersion, other.mRelease, other.mRevision);
}
bool VersionId::operator!= (const VersionId& other)
@@ -62,19 +61,8 @@ bool VersionId::operator!= (const VersionId& other)
bool VersionId::operator< (const VersionId& other)
{
- if (mVersion < other.mVersion)
- return true;
-
- if (mRelease < other.mRelease &&
- mVersion == other.mVersion)
- return true;
-
- if (mRevision < other.mRevision &&
- mVersion == other.mVersion &&
- mRelease == other.mRelease)
- return true;
-
- return false;
+ return std::tie(mVersion, mRelease, mRevision) <
+ std::tie(other.mVersion, other.mRelease, other.mRevision);
}
bool VersionId::operator> (const VersionId& other)