PCM: Prompt to enable IPC API when required

Fixes https://gitlab.com/kicad/code/kicad/-/issues/20062


(cherry picked from commit 3525731a4eebc47a82bd96499687f8dd7eacf8eb)

Co-authored-by: Jon Evans <jon@craftyjon.com>
This commit is contained in:
Jon Evans 2025-02-23 23:07:30 +00:00
parent 337689a69e
commit 0fccad7183
8 changed files with 59 additions and 6 deletions

View File

@ -401,7 +401,7 @@ public:
* *
* Use after changing suite-wide options such as panning, autosave interval, etc. * Use after changing suite-wide options such as panning, autosave interval, etc.
*/ */
virtual void CommonSettingsChanged( int aFlags ); virtual void CommonSettingsChanged( int aFlags = 0 );
/** /**
* Calls ProjectChanged() on all KIWAY_PLAYERs. * Calls ProjectChanged() on all KIWAY_PLAYERs.

View File

@ -25,6 +25,7 @@
#include "bitmaps.h" #include "bitmaps.h"
#include "dialog_manage_repositories.h" #include "dialog_manage_repositories.h"
#include "dialog_pcm.h" #include "dialog_pcm.h"
#include <eda_base_frame.h>
#include "grid_tricks.h" #include "grid_tricks.h"
#include "ki_exception.h" #include "ki_exception.h"
#include "pcm_task_manager.h" #include "pcm_task_manager.h"
@ -54,8 +55,9 @@ static std::vector<std::pair<PCM_PACKAGE_TYPE, wxString>> PACKAGE_TYPE_LIST = {
}; };
DIALOG_PCM::DIALOG_PCM( wxWindow* parent, std::shared_ptr<PLUGIN_CONTENT_MANAGER> pcm ) : DIALOG_PCM::DIALOG_PCM( EDA_BASE_FRAME* parent, std::shared_ptr<PLUGIN_CONTENT_MANAGER> pcm ) :
DIALOG_PCM_BASE( parent ), DIALOG_PCM_BASE( parent ),
m_parentFrame( parent ),
m_pcm( pcm ) m_pcm( pcm )
{ {
// correct the min size from wxfb with fromdip // correct the min size from wxfb with fromdip

View File

@ -30,15 +30,19 @@
#include <vector> #include <vector>
class EDA_BASE_FRAME;
/** Implementing pcm main dialog. */ /** Implementing pcm main dialog. */
class DIALOG_PCM : public DIALOG_PCM_BASE class DIALOG_PCM : public DIALOG_PCM_BASE
{ {
public: public:
/** Constructor */ /** Constructor */
DIALOG_PCM( wxWindow* parent, std::shared_ptr<PLUGIN_CONTENT_MANAGER> pcm ); DIALOG_PCM( EDA_BASE_FRAME* parent, std::shared_ptr<PLUGIN_CONTENT_MANAGER> pcm );
~DIALOG_PCM(); ~DIALOG_PCM();
EDA_BASE_FRAME* ParentFrame() const { return m_parentFrame; }
///< Closes the window, asks user confirmation if there are pending actions ///< Closes the window, asks user confirmation if there are pending actions
void OnCloseClicked( wxCommandEvent& event ) override; void OnCloseClicked( wxCommandEvent& event ) override;
void OnCloseWindow( wxCloseEvent& aEvent ); void OnCloseWindow( wxCloseEvent& aEvent );
@ -102,6 +106,7 @@ private:
///< Discards specified pending action ///< Discards specified pending action
void discardAction( int aIndex ); void discardAction( int aIndex );
EDA_BASE_FRAME* m_parentFrame;
std::shared_ptr<PLUGIN_CONTENT_MANAGER> m_pcm; std::shared_ptr<PLUGIN_CONTENT_MANAGER> m_pcm;
ActionCallback m_actionCallback; ActionCallback m_actionCallback;
PinCallback m_pinCallback; PinCallback m_pinCallback;

View File

@ -30,10 +30,14 @@
#include "build_version.h" #include "build_version.h"
#include "paths.h" #include "paths.h"
#include "pcm.h" #include "pcm.h"
#include <eda_base_frame.h>
#include "dialogs/dialog_pcm.h"
#include "pgm_base.h" #include "pgm_base.h"
#include "picosha2.h" #include "picosha2.h"
#include "settings/settings_manager.h" #include "settings/settings_manager.h"
#include <wx_filename.h> #include <wx_filename.h>
#include <settings/common_settings.h>
#include <kiway.h>
#include <fstream> #include <fstream>
#include <iomanip> #include <iomanip>
@ -766,6 +770,21 @@ void PLUGIN_CONTENT_MANAGER::MarkInstalled( const PCM_PACKAGE& aPackage, const w
entry.pinned = pinned; entry.pinned = pinned;
m_installed.emplace( aPackage.identifier, entry ); m_installed.emplace( aPackage.identifier, entry );
if( m_dialog
&& ( aPackage.versions[0].runtime.value_or( PCM_PACKAGE_RUNTIME::PPR_SWIG )
== PCM_PACKAGE_RUNTIME::PPR_IPC )
&& !Pgm().GetCommonSettings()->m_Api.enable_server )
{
if( wxMessageBox( _( "This plugin requires the KiCad API, which is currently "
"disabled in preferences. Would you like to enable it?" ),
_( "Enable KiCad API" ), wxICON_QUESTION | wxYES_NO, m_dialog )
== wxYES )
{
Pgm().GetCommonSettings()->m_Api.enable_server = true;
m_dialog->ParentFrame()->Kiway().CommonSettingsChanged();
}
}
} }

View File

@ -80,6 +80,7 @@ typedef std::vector<std::tuple<wxString, wxString, wxString>> STRING_TUPLE_LIST;
struct BACKGROUND_JOB; struct BACKGROUND_JOB;
class DIALOG_PCM;
/** /**
@ -326,7 +327,7 @@ public:
* *
* @param aDialog parent dialog for progress window * @param aDialog parent dialog for progress window
*/ */
void SetDialogWindow( wxWindow* aDialog ) { m_dialog = aDialog; }; void SetDialogWindow( DIALOG_PCM* aDialog ) { m_dialog = aDialog; };
/** /**
* @brief Runs a background update thread that checks for new package versions * @brief Runs a background update thread that checks for new package versions
@ -392,7 +393,7 @@ private:
///< Returns current UTC timestamp ///< Returns current UTC timestamp
time_t getCurrentTimestamp() const; time_t getCurrentTimestamp() const;
wxWindow* m_dialog; DIALOG_PCM* m_dialog;
std::unique_ptr<JSON_SCHEMA_VALIDATOR> m_schema_validator; std::unique_ptr<JSON_SCHEMA_VALIDATOR> m_schema_validator;
wxString m_3rdparty_path; wxString m_3rdparty_path;
wxString m_cache_path; wxString m_cache_path;

View File

@ -54,6 +54,9 @@ void to_json( json& j, const PACKAGE_VERSION& v )
if( v.install_size ) if( v.install_size )
j["install_size"] = *v.install_size; j["install_size"] = *v.install_size;
if( v.runtime )
j["runtime"] = *v.runtime;
if( v.platforms.size() > 0 ) if( v.platforms.size() > 0 )
nlohmann::to_json( j["platforms"], v.platforms ); nlohmann::to_json( j["platforms"], v.platforms );
@ -77,6 +80,7 @@ void from_json( const json& j, PACKAGE_VERSION& v )
to_optional( j, "download_size", v.download_size ); to_optional( j, "download_size", v.download_size );
to_optional( j, "install_size", v.install_size ); to_optional( j, "install_size", v.install_size );
to_optional( j, "kicad_version_max", v.kicad_version_max ); to_optional( j, "kicad_version_max", v.kicad_version_max );
to_optional( j, "runtime", v.runtime );
if( j.contains( "platforms" ) ) if( j.contains( "platforms" ) )
j.at( "platforms" ).get_to( v.platforms ); j.at( "platforms" ).get_to( v.platforms );

View File

@ -66,6 +66,13 @@ enum PCM_PACKAGE_VERSION_STATUS
PVS_DEPRECATED PVS_DEPRECATED
}; };
///< The runtime a plugin package uses
enum class PCM_PACKAGE_RUNTIME
{
PPR_SWIG,
PPR_IPC
};
///< Describes a person's name and contact information ///< Describes a person's name and contact information
struct PCM_CONTACT struct PCM_CONTACT
@ -93,6 +100,7 @@ struct PACKAGE_VERSION
wxString kicad_version; wxString kicad_version;
std::optional<wxString> kicad_version_max; std::optional<wxString> kicad_version_max;
std::vector<std::string> keep_on_update; std::vector<std::string> keep_on_update;
std::optional<PCM_PACKAGE_RUNTIME> runtime;
// Not serialized fields // Not serialized fields
std::tuple<int, int, int, int> parsed_version; // Full version tuple for sorting std::tuple<int, int, int, int> parsed_version; // Full version tuple for sorting
@ -183,6 +191,12 @@ NLOHMANN_JSON_SERIALIZE_ENUM( PCM_PACKAGE_VERSION_STATUS,
{ PVS_DEPRECATED, "deprecated" }, { PVS_DEPRECATED, "deprecated" },
} ) } )
NLOHMANN_JSON_SERIALIZE_ENUM( PCM_PACKAGE_RUNTIME,
{
{ PCM_PACKAGE_RUNTIME::PPR_SWIG, "swig" },
{ PCM_PACKAGE_RUNTIME::PPR_IPC, "ipc" },
} )
// Following are templates and definitions for en/decoding above structs // Following are templates and definitions for en/decoding above structs
// to/from json // to/from json

View File

@ -191,6 +191,14 @@
"minItems": 1, "minItems": 1,
"uniqueItems": true "uniqueItems": true
}, },
"runtime": {
"type": "string",
"enum": [
"swig",
"ipc"
],
"description": "What runtime a plugin requires. Assumed to be swig if absent. Not used for non-plugin packages."
},
"kicad_version": { "kicad_version": {
"type": "string", "type": "string",
"description": "Minimum supported KiCad version", "description": "Minimum supported KiCad version",