47#include <wx/translation.h>
48#include <wx/notifmsg.h>
73 wxString release_date;
75 wxString downloads_url;
81#define UPDATE_QUERY_ENDPOINT wxS( "https://downloads.kicad.org/api/v1/update" )
104 const size_t aSizeLimit )
106 bool size_exceeded =
false;
108 TRANSFER_CALLBACK callback = [&](
size_t dltotal,
size_t dlnow,
size_t ultotal,
size_t ulnow )
110 if( aSizeLimit > 0 && ( dltotal > aSizeLimit || dlnow > aSizeLimit ) )
112 size_exceeded =
true;
123 aReporter->
Report( wxString::Format(
_(
"Downloading %lld/%lld kB" ), dlnow / 1000,
139 curl.
SetHeader(
"Accept",
"application/json" );
140 curl.
SetHeader(
"Content-Type",
"application/json" );
143 curl.
SetURL( aUrl.ToUTF8().data() );
154 if( code != CURLE_OK )
158 if( code == CURLE_ABORTED_BY_CALLBACK && size_exceeded )
159 aReporter->
Report(
_(
"Download is too large." ) );
160 else if( code != CURLE_ABORTED_BY_CALLBACK )
180 auto update_check = [aNoticeParent,
this]() ->
void
184 std::stringstream update_json_stream;
185 std::stringstream request_json_stream;
188 reporter->SetNumPhases( 1 );
189 reporter->Report(
_(
"Requesting update info" ) );
195#if defined( __WXMSW__ )
196 requestContent.
platform =
"windows";
198 #if defined( KICAD_BUILD_ARCH_X64 )
199 requestContent.
arch =
"amd64";
200 #elif defined( KICAD_BUILD_ARCH_X86 )
201 requestContent.
arch =
"i686";
202 #elif defined( KICAD_BUILD_ARCH_ARM )
203 requestContent.
arch =
"arm";
204 #elif defined( KICAD_BUILD_ARCH_ARM64 )
205 requestContent.
arch =
"arm64";
207#elif defined( __WXOSX__ )
209 requestContent.
arch =
"unified";
213 requestContent.
arch =
"";
216 verString.Replace(
"~",
"-" );
224 nlohmann::json requestJson = nlohmann::json( requestContent );
225 request_json_stream << requestJson;
227 int responseCode =
PostRequest( aUrl, request_json_stream.str(), &update_json_stream,
228 reporter.get(), 20480 );
232 if( responseCode == 200 && !
Pgm().m_Quitting )
234 nlohmann::json update_json;
235 UPDATE_RESPONSE response;
239 update_json_stream >> update_json;
240 response = update_json.get<UPDATE_RESPONSE>();
244 aNoticeParent->CallAfter(
245 [aNoticeParent, response]()
247 if(
Pgm().m_Quitting )
252 response.details_url,
253 response.downloads_url );
255 int retCode = notice->ShowModal();
257 if( retCode != wxID_RETRY )
262 cfg->m_lastReceivedUpdate = response.version;
267 catch(
const std::exception& e )
269 wxLogError( wxString::Format(
_(
"Unable to parse update response: %s" ), e.what() ) );
wxString GetSemanticVersion()
Get the semantic version string for KiCad defined inside the KiCadVersion.cmake file in the variable ...
std::shared_ptr< BACKGROUND_JOB > Create(const wxString &aName)
Creates a background job with the given name.
void Remove(std::shared_ptr< BACKGROUND_JOB > job)
Removes the given background job from any lists and frees it.
int Perform()
Equivalent to curl_easy_perform.
bool SetPostFields(const std::vector< std::pair< std::string, std::string > > &aFields)
Set fields for application/x-www-form-urlencoded POST request.
int GetResponseStatusCode()
void SetHeader(const std::string &aName, const std::string &aValue)
Set an arbitrary header for the HTTP(s) request.
bool SetTransferCallback(const TRANSFER_CALLBACK &aCallback, size_t aInterval)
bool SetURL(const std::string &aURL)
Set the request URL.
bool SetFollowRedirects(bool aFollow)
Enable the following of HTTP(s) and other redirects, by default curl does not follow redirects.
bool SetTimeout(long aTimeoutSecs)
Set the total operation timeout in seconds.
bool SetOutputStream(const std::ostream *aOutput)
const std::string GetErrorText(int aCode)
Fetch CURL's "friendly" error string for a given error code.
wxString m_lastUpdateCheckTime
wxString m_lastReceivedUpdate
virtual BACKGROUND_JOBS_MONITOR & GetBackgroundJobMonitor() const
virtual wxString GetLanguageTag()
A progress reporter interface for use in multi-threaded environments.
virtual bool IsCancelled() const =0
virtual bool KeepRefreshing(bool aWait=false)=0
Update the UI (if any).
virtual void Report(const wxString &aMessage)=0
Display aMessage in the progress bar dialog.
virtual void SetCurrentProgress(double aProgress)=0
Set the progress value to aProgress (0..1).
std::shared_ptr< BACKGROUND_JOB > m_updateBackgroundJob
int PostRequest(const wxString &aUrl, std::string aRequestBody, std::ostream *aOutput, PROGRESS_REPORTER *aReporter, const size_t aSizeLimit)
void CheckForUpdate(wxWindow *aNoticeParent)
std::atomic< bool > m_working
std::future< void > m_updateTask
std::function< int(size_t, size_t, size_t, size_t)> TRANSFER_CALLBACK
Wrapper interface around the curl_easy API/.
PGM_BASE & Pgm()
The global program "get" accessor.
T * GetAppSettings(const char *aFilename)
thread_pool & GetKiCadThreadPool()
Get a reference to the current thread pool.
BS::priority_thread_pool thread_pool
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(UPDATE_REQUEST, platform, arch, current_version, lang, last_check) struct UPDATE_RESPONSE
#define UPDATE_QUERY_ENDPOINT