41#include <nlohmann/json.hpp>
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" )
91 const size_t aSizeLimit )
93 bool size_exceeded =
false;
95 TRANSFER_CALLBACK callback = [&](
size_t dltotal,
size_t dlnow,
size_t ultotal,
size_t ulnow )
97 if( aSizeLimit > 0 && ( dltotal > aSizeLimit || dlnow > aSizeLimit ) )
110 aReporter->
Report( wxString::Format(
_(
"Downloading %lld/%lld kB" ), dlnow / 1000,
126 curl.
SetHeader(
"Accept",
"application/json" );
127 curl.
SetHeader(
"Content-Type",
"application/json" );
130 curl.
SetURL( aUrl.ToUTF8().data() );
140 if( code != CURLE_OK )
144 if( code == CURLE_ABORTED_BY_CALLBACK && size_exceeded )
145 aReporter->
Report(
_(
"Download is too large." ) );
146 else if( code != CURLE_ABORTED_BY_CALLBACK )
166 auto update_check = [aNoticeParent,
this]() ->
void
168 std::stringstream update_json_stream;
169 std::stringstream request_json_stream;
179#if defined( __WXMSW__ )
180 requestContent.
platform =
"windows";
182 #if defined( KICAD_BUILD_ARCH_X64 )
183 requestContent.
arch =
"amd64";
184 #elif defined( KICAD_BUILD_ARCH_X86 )
185 requestContent.
arch =
"i686";
186 #elif defined( KICAD_BUILD_ARCH_ARM )
187 requestContent.
arch =
"arm";
188 #elif defined( KICAD_BUILD_ARCH_ARM64 )
189 requestContent.
arch =
"arm64";
191#elif defined( __WXOSX__ )
193 requestContent.
arch =
"unified";
197 requestContent.
arch =
"";
200 verString.Replace(
"~",
"-" );
208 nlohmann::json requestJson = nlohmann::json( requestContent );
209 request_json_stream << requestJson;
212 PostRequest( aUrl, request_json_stream.str(), &update_json_stream, NULL, 20480 );
216 if( responseCode == 200 )
218 nlohmann::json update_json;
219 UPDATE_RESPONSE response;
223 update_json_stream >> update_json;
224 response = update_json.get<UPDATE_RESPONSE>();
228 aNoticeParent->CallAfter(
229 [aNoticeParent, response]()
233 response.details_url,
234 response.downloads_url );
236 int retCode = notice->ShowModal();
238 if( retCode != wxID_RETRY )
249 catch(
const std::exception& e )
251 wxLogError( wxString::Format(
_(
"Unable to parse update response: %s" ),
264 tp.push_task( update_check );
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 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()
virtual SETTINGS_MANAGER & GetSettingsManager() const
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).
T * GetAppSettings()
Returns a handle to the a given settings by type If the settings have already been loaded,...
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::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.
BS::thread_pool thread_pool
thread_pool & GetKiCadThreadPool()
Get a reference to the current thread pool.
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(UPDATE_REQUEST, platform, arch, current_version, lang, last_check) struct UPDATE_RESPONSE
#define UPDATE_QUERY_ENDPOINT