25#include <wx/stdpaths.h>
26#include <wx/filename.h>
30#define UPDATE_LOCAL_TESTING 0
37using Clock = std::chrono::system_clock;
41#if UPDATE_LOCAL_TESTING == 1
80 static std::once_flag
flag;
81 std::call_once(
flag, [&instance] {
82 instance.mTimer.SetOwner(&instance,
ID_TIMER);
83 instance.mTimer.StartOnce(1);
114 if (!ignoreNetworkErrors)
117 XC(
"Error checking for update",
"update dialog"),
118 XC(
"Unable to connect to Audacity update server.",
"update dialog"),
130 if (!ignoreNetworkErrors)
133 XC(
"Error checking for update",
"update dialog"),
134 XC(
"Update data was corrupted.",
"update dialog"),
144#if UPDATE_LOCAL_TESTING == 0
148 gAudioIO->CallAfterRecording([
this, ignoreNetworkErrors, configurableNotification] {
150 const int code = dlg.ShowModal();
152 if (code == wxID_YES)
167 if (!ignoreNetworkErrors)
169 wxTheApp->CallAfter([] {ShowErrorDialog( {},
170 XC(
"Error downloading update",
"update dialog"),
171 XC(
"Can't open the Audacity download link.",
"update dialog"),
173 ErrorDialogOptions{ ErrorDialogType::ModalErrorReport });
182 if ((info.GetOperatingSystemId() & wxOS_WINDOWS) ||
183 info.GetOperatingSystemId() & wxOS_MAC)
188 wxTheApp->CallAfter([cmd] { wxExecute(cmd, wxEXEC_ASYNC); });
201 wxString installerExtension;
203 if (info.GetOperatingSystemId() & wxOS_WINDOWS)
204 installerExtension =
"exe";
205 else if(info.GetOperatingSystemId() & wxOS_MAC)
206 installerExtension =
"dmg";
209 wxStandardPaths::Get().GetUserDir(wxStandardPaths::Dir_Downloads), audacityPatchFilename, installerExtension)
216 downloadResponse->setDownloadProgressCallback(
217 [
this](int64_t current, int64_t expected) {
219 wxTheApp->CallAfter([
this, current, expected]{
230 std::vector<char> buffer(downloadResponse->getBytesAvailable());
232 size_t bytes = downloadResponse->readData(buffer.data(), buffer.size());
234 if (mAudacityInstaller.is_open())
235 mAudacityInstaller.write(buffer.data(), buffer.size());
241 else if (code == wxID_NO)
247#if UPDATE_LOCAL_TESTING == 0
251 if (!configurableNotification)
253 gAudioIO->CallAfterRecording([] {
268#if UPDATE_LOCAL_TESTING == 0
275 mTimer.StartOnce(std::chrono::duration_cast<std::chrono::milliseconds>(
285 const TimePoint nextUpdatesCheckingTime(std::chrono::milliseconds(
289 const TimePoint currentTime = Clock::now();
293 if (nextUpdatesCheckingTime < currentTime)
300 std::chrono::duration<int32_t, std::ratio<60 * 60 * 24>>;
302 const auto postponeUpdateUntil =
303 std::chrono::time_point_cast<DayDuration>(
304 currentTime) + DayDuration(1);
306 const std::chrono::milliseconds postponeUpdateUntilMS(
307 postponeUpdateUntil.time_since_epoch());
311 wxString(std::to_string(postponeUpdateUntilMS.count())));
Toolkit-neutral facade for basic user interface services.
Declare an interface for HTTP response.
Declare a class for performing HTTP requests.
BoolSetting DefaultUpdatesCheckingFlag
Declare a class for constructing HTTP requests.
std::chrono::system_clock Clock
static const char * prefsUpdateScheduledTime
Clock::time_point TimePoint
TimePoint::duration Duration
constexpr Duration updatesCheckInterval
static BoolSetting prefUpdatesNoticeShown(wxT("/Update/UpdateNoticeShown"), false)
Declare a class that handles managing of updates.
Define a dialog to notify the user about automatic update checking.
static VersionId CurrentBuildVersion()
Return version (VersionId) object with current Audacity build version.
This specialization of Setting for bool adds a Toggle method to negate the saved value.
virtual bool Flush(bool bCurrentOnly=false) wxOVERRIDE
Information dialog about no updates available, that allows to navigate to settings quickly.
bool Write(const T &value)
Write value to config and return true if successful.
bool Read(T *pVar) const
overload of Read returning a boolean that is true if the value was previously defined */
bool Parse(const VersionPatch::UpdateDataFormat &updateData, VersionPatch *versionPatch)
Parsing from update data format to VersionPatch fields.
A class that managing of updates.
void GetUpdates(bool ignoreNetworkErrors, bool configurableNotification)
std::unique_ptr< BasicUI::ProgressDialog > mProgressDialog
static UpdateManager & GetInstance()
std::string mAudacityInstallerPath
static void Start(bool suppressModal)
void OnTimer(wxTimerEvent &event)
UpdateDataParser mUpdateDataParser
std::ofstream mAudacityInstaller
VersionPatch GetVersionPatch() const
VersionPatch mVersionPatch
bool IsTimeForUpdatesChecking()
Scheduling update time for avoiding multiplying update notifications.
Dialog, that notifies the users about automatic updates checking.
Interface, that provides access to the data from the HTTP response.
static NetworkManager & GetInstance()
ResponsePtr doGet(const Request &request)
void ShowErrorDialog(const WindowPlacement &placement, const TranslatableString &dlogTitle, const TranslatableString &message, const ManualPageID &helpPage, const ErrorDialogOptions &options={})
Show an error dialog with a link to the manual for further help.
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
std::unique_ptr< ProgressDialog > MakeProgress(const TranslatableString &title, const TranslatableString &message, unsigned flags=(ProgressShowStop|ProgressShowCancel), const TranslatableString &remainingLabelText={})
Create and display a progress dialog.
FrameStatistics & GetInstance() noexcept
Options for variations of error dialogs; the default is for modal dialogs.
A structure that describes patch fields.
std::string UpdateDataFormat