mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-08-05 01:02:08 +00:00
cleanup
This commit is contained in:
@@ -20,9 +20,8 @@ namespace Slic3r {
|
||||
|
||||
namespace {
|
||||
|
||||
// The version of the plugin package currently running. PluginDescriptor::version is
|
||||
// overwritten with the latest cloud version when a cloud merge happens, so it can name a
|
||||
// version that is not the one on disk; installed_version is what actually loaded.
|
||||
// PluginDescriptor::version is overwritten with the latest cloud version on a cloud merge, so it can
|
||||
// name a version that is not the one on disk; installed_version is what actually loaded.
|
||||
std::string running_plugin_version(const std::string& plugin_key)
|
||||
{
|
||||
PluginDescriptor descriptor;
|
||||
@@ -31,10 +30,9 @@ std::string running_plugin_version(const std::string& plugin_key)
|
||||
return descriptor.installed_version.empty() ? descriptor.version : descriptor.installed_version;
|
||||
}
|
||||
|
||||
// The identity a capability is allowed to address: its own. PluginLoader stamps both halves
|
||||
// onto the instance when it materializes the capability, so the caller never supplies them
|
||||
// and cannot name another capability's entry. Empty means the instance was never materialized
|
||||
// (so it has no config to address) and we refuse rather than read or clobber a wrong entry.
|
||||
// PluginLoader stamps both halves onto the instance when it materializes the capability, so the
|
||||
// caller never supplies them and cannot name another capability's entry. Empty means the instance
|
||||
// was never materialized: refuse rather than read or clobber a wrong entry.
|
||||
std::pair<std::string, std::string> capability_identity(const PluginCapabilityInterface& capability, const char* api_name)
|
||||
{
|
||||
std::pair<std::string, std::string> id{capability.audit_plugin_key(), capability.audit_capability_name()};
|
||||
@@ -44,11 +42,11 @@ std::pair<std::string, std::string> capability_identity(const PluginCapabilityIn
|
||||
return id;
|
||||
}
|
||||
|
||||
// The identity above, completed with the type, which decides which preset may override the
|
||||
// capability (see preset_type_for_capability). Taken from the instance rather than from the loader's
|
||||
// registry: a capability calling get_config() from on_load() is not registered yet, and it must
|
||||
// still see its preset's config. get_type() is the plugin's own method, so a raising one costs it
|
||||
// only the preset layer — Unknown names no preset, and the base config answers as it always did.
|
||||
// The identity above plus the type, which decides which preset may override the capability (see
|
||||
// preset_type_for_capability). Taken from the instance, not the loader's registry: a capability
|
||||
// calling get_config() from on_load() is not registered yet and must still see its preset's config.
|
||||
// A raising get_type() costs it only the preset layer — Unknown names no preset, so the base config
|
||||
// answers.
|
||||
PluginCapabilityIdentifier capability_full_identity(const PluginCapabilityInterface& capability, const char* api_name)
|
||||
{
|
||||
const auto [plugin_key, capability_name] = capability_identity(capability, api_name);
|
||||
@@ -113,8 +111,8 @@ bool PluginConfig::save()
|
||||
return false;
|
||||
}
|
||||
|
||||
// Write to a PID-suffixed file and rename it into place, so a crash mid-write cannot
|
||||
// truncate an existing config. Same approach as AppConfig::save().
|
||||
// Write to a PID-suffixed file and rename it into place, so a crash mid-write cannot truncate an
|
||||
// existing config. Same approach as AppConfig::save().
|
||||
const std::string path_pid = (boost::format("%1%.%2%") % path % get_current_pid()).str();
|
||||
|
||||
boost::nowide::ofstream file;
|
||||
@@ -198,18 +196,16 @@ bool PluginConfig::dirty() const
|
||||
|
||||
nlohmann::json capability_get_config(const PluginCapabilityInterface& capability)
|
||||
{
|
||||
// The active preset's override, when it has one, is the config this run must use: it is what the
|
||||
// user attached to the preset being sliced, and config.json is the fallback. The resolution is
|
||||
// shared with the dialogs, so a capability reads back exactly the config its UI showed as
|
||||
// effective. Stored in neither layer: an empty object, so a plugin can index it unconditionally.
|
||||
// Shares its resolution with the dialogs, so a capability reads back exactly the config its UI
|
||||
// showed as effective. Stored in neither layer: an empty object, so a plugin can index it
|
||||
// unconditionally.
|
||||
return active_capability_config(capability_full_identity(capability, "get_config")).config;
|
||||
}
|
||||
|
||||
std::string capability_get_config_version(const PluginCapabilityInterface& capability)
|
||||
{
|
||||
// The version that wrote the config get_config() just handed out, whichever layer that was: the
|
||||
// two must come from the same layer, or a plugin would migrate one layer's config by another's
|
||||
// version stamp.
|
||||
// Must resolve through the same layer as get_config(), or a plugin would migrate one layer's
|
||||
// config by another's version stamp.
|
||||
return active_capability_config(capability_full_identity(capability, "get_config_version")).stored_plugin_version;
|
||||
}
|
||||
|
||||
@@ -226,8 +222,7 @@ nlohmann::json PluginConfig::capabilities_payload(const std::vector<PluginCapabi
|
||||
|
||||
nlohmann::json payload = nlohmann::json::array();
|
||||
for (const PluginCapabilityIdentifier& id : caps) {
|
||||
// Read has_config_ui off the live capability rather than trusting the caller's copy: a
|
||||
// capability that has been unloaded since the list was built has nothing to configure.
|
||||
// A capability unloaded since the list was built has nothing to configure.
|
||||
const auto capability = loader.get_plugin_capability_by_name(id);
|
||||
if (!capability)
|
||||
continue;
|
||||
@@ -243,9 +238,8 @@ nlohmann::json PluginConfig::capabilities_payload(const std::vector<PluginCapabi
|
||||
return payload;
|
||||
}
|
||||
|
||||
// Replies with one capability's stored config, plus the custom HTML UI when the capability provides
|
||||
// one. Config is sent as a JSON value, not text: the default editor pretty-prints it into its
|
||||
// textarea, and a custom UI receives it as-is through window.orca.
|
||||
// Config is sent as a JSON value, not text: the default editor pretty-prints it into its textarea,
|
||||
// and a custom UI receives it as-is through window.orca.
|
||||
nlohmann::json PluginConfig::get_config_response(const PluginCapabilityIdentifier& id)
|
||||
{
|
||||
nlohmann::json response;
|
||||
@@ -258,7 +252,7 @@ nlohmann::json PluginConfig::get_config_response(const PluginCapabilityIdentifie
|
||||
response["error"] = "";
|
||||
|
||||
// Scoped to the full identity, so a stale request from a page that has not caught up with a
|
||||
// refresh cannot read a different plugin's config — it just misses.
|
||||
// refresh misses rather than reading a different plugin's config.
|
||||
const auto cap = PluginManager::instance().get_loader().get_plugin_capability_by_name(id);
|
||||
if (!cap) {
|
||||
BOOST_LOG_TRIVIAL(warning) << "Ignoring config request for a capability that is no longer loaded. plugin_key="
|
||||
@@ -270,9 +264,8 @@ nlohmann::json PluginConfig::get_config_response(const PluginCapabilityIdentifie
|
||||
response["config"] = PluginManager::instance().get_config().get_config(id.plugin_key, id.name).config;
|
||||
|
||||
if (cap->has_config_ui) {
|
||||
// Plugin-authored HTML. A raising or empty get_config_ui() costs the capability only its
|
||||
// custom UI: we report the failure and let the page fall back to the default JSON editor,
|
||||
// which edits the very same stored config.
|
||||
// A raising or empty get_config_ui() costs the capability only its custom UI: report the
|
||||
// failure and let the page fall back to the default JSON editor over the same stored config.
|
||||
std::string html;
|
||||
std::string error;
|
||||
{
|
||||
@@ -324,8 +317,8 @@ nlohmann::json PluginConfig::save_config_response(const PluginCapabilityIdentifi
|
||||
|
||||
nlohmann::json parsed = config;
|
||||
if (config.is_string()) {
|
||||
// The page validates as the user types, but it is not the authority: re-parse here so a
|
||||
// malformed document is rejected before it can reach config.json.
|
||||
// The page validates as the user types, but it is not the authority: re-parse so a malformed
|
||||
// document is rejected before it can reach config.json.
|
||||
parsed = nlohmann::json::parse(config.get<std::string>(), nullptr, /* allow_exceptions */ false);
|
||||
if (parsed.is_discarded()) {
|
||||
response["error"] = GUI::into_u8(_L("The configuration is not valid JSON. Your changes were not saved."));
|
||||
@@ -342,15 +335,14 @@ nlohmann::json PluginConfig::save_config_response(const PluginCapabilityIdentifi
|
||||
|
||||
BOOST_LOG_TRIVIAL(info) << "Saved plugin capability config. plugin_key=" << id.plugin_key << " capability_name=" << id.name;
|
||||
|
||||
// Echo the persisted value back so the editor reloads from what is actually stored rather than
|
||||
// from what the user typed.
|
||||
// Echo back what was persisted, not what the user typed, so the editor reloads from the store.
|
||||
response["ok"] = true;
|
||||
response["config"] = PluginManager::instance().get_config().get_config(id.plugin_key, id.name).config;
|
||||
return response;
|
||||
}
|
||||
|
||||
// The host does not invent the default: a capability that does not override get_default_config()
|
||||
// restores an empty config, which is exactly right for one that applies its own defaults on read.
|
||||
// The host never invents the default: a capability that does not override get_default_config()
|
||||
// restores an empty config, which is right for one that applies its own defaults on read.
|
||||
nlohmann::json PluginConfig::restore_config_response(const PluginCapabilityIdentifier& id)
|
||||
{
|
||||
nlohmann::json response;
|
||||
@@ -383,8 +375,8 @@ nlohmann::json PluginConfig::restore_config_response(const PluginCapabilityIdent
|
||||
}
|
||||
}
|
||||
|
||||
// A raising hook leaves the stored config exactly as it was: better to restore nothing than to
|
||||
// wipe the user's settings on the strength of a broken plugin.
|
||||
// A raising hook leaves the stored config as it was: better to restore nothing than to wipe the
|
||||
// user's settings on the strength of a broken plugin.
|
||||
if (!error.empty()) {
|
||||
BOOST_LOG_TRIVIAL(error) << "Plugin capability get_default_config() failed. plugin_key=" << id.plugin_key
|
||||
<< " capability_name=" << id.name << " error=" << error;
|
||||
@@ -404,7 +396,6 @@ nlohmann::json PluginConfig::restore_config_response(const PluginCapabilityIdent
|
||||
BOOST_LOG_TRIVIAL(info) << "Restored default plugin capability config. plugin_key=" << id.plugin_key
|
||||
<< " capability_name=" << id.name;
|
||||
|
||||
// Reuses the saved reply, so both editors reload from what was actually persisted.
|
||||
response["ok"] = true;
|
||||
response["config"] = PluginManager::instance().get_config().get_config(id.plugin_key, id.name).config;
|
||||
return response;
|
||||
|
||||
@@ -32,32 +32,8 @@ Example config.json shape
|
||||
"plugin_key": "some_name",
|
||||
"capability": "capability_name",
|
||||
"plugin_version": "1.0.0",
|
||||
"cap_config": {
|
||||
"some": "plugin",
|
||||
"capability": "specific",
|
||||
"stuff": "here"
|
||||
}
|
||||
},
|
||||
{
|
||||
"plugin_key": "some_name",
|
||||
"capability": "capability_name",
|
||||
"plugin_version": "1.0.0",
|
||||
"cap_config": {
|
||||
"some": "plugin",
|
||||
"capability": "specific",
|
||||
"stuff": "here"
|
||||
}
|
||||
},
|
||||
{
|
||||
"plugin_key": "some_name",
|
||||
"capability": "capability_name",
|
||||
"plugin_version": "1.0.0",
|
||||
"cap_config": {
|
||||
"some": "plugin",
|
||||
"capability": "specific",
|
||||
"stuff": "here"
|
||||
}
|
||||
},
|
||||
"cap_config": { "plugin": "specific", "stuff": "here" }
|
||||
}
|
||||
]
|
||||
}
|
||||
*/
|
||||
@@ -73,14 +49,12 @@ struct BaseConfig {
|
||||
bool empty() const { return plugin_key.empty() || capability_name.empty(); }
|
||||
};
|
||||
|
||||
// Consolidated store for every plugin capability's configuration, persisted as a single
|
||||
// config.json alongside the installed plugins. The shape of `cap_config` belongs to the
|
||||
// plugin; this class only round-trips it.
|
||||
// Store for every plugin capability's configuration, persisted as a single config.json alongside the
|
||||
// installed plugins. The shape of `cap_config` belongs to the plugin; this class only round-trips it.
|
||||
//
|
||||
// A capability is identified by (plugin_key, capability_name). `plugin_version` is metadata
|
||||
// recording which version last wrote the entry, letting an upgraded plugin spot a stale
|
||||
// config and migrate it. Version is deliberately not part of the identity, so upgrading a
|
||||
// plugin does not silently reset the user's settings.
|
||||
// A capability is identified by (plugin_key, capability_name). `plugin_version` records which version
|
||||
// last wrote the entry, so an upgraded plugin can spot a stale config and migrate it. It is
|
||||
// deliberately not part of the identity: upgrading a plugin must not reset the user's settings.
|
||||
//
|
||||
// Plugin code runs on worker threads, so every entry point is mutex-guarded.
|
||||
class PluginConfig
|
||||
@@ -88,51 +62,42 @@ class PluginConfig
|
||||
public:
|
||||
static const std::string plugin_config_file() { return (boost::filesystem::path(get_orca_plugins_dir()) / PLUGIN_CONFIG_DIR).string(); }
|
||||
|
||||
// Replaces the in-memory store with what is on disk. A missing or malformed file leaves
|
||||
// the store empty rather than throwing: a bad plugin config must not block startup.
|
||||
// A missing or malformed file leaves the store empty rather than throwing: a bad plugin config
|
||||
// must not block startup.
|
||||
void load();
|
||||
|
||||
// Rewrites config.json atomically. Clears the dirty flag only once the file is in place.
|
||||
// False means the config on disk is unchanged.
|
||||
// Rewrites config.json atomically. False means the config on disk is unchanged.
|
||||
bool save();
|
||||
|
||||
void save_config(const std::string& plugin_key, const std::string& capability_name, const std::string& version, const nlohmann::json& config);
|
||||
void save_config(const BaseConfig& config);
|
||||
|
||||
// Replaces one capability's cap_config and writes config.json straight away, stamping the
|
||||
// entry with the plugin version currently running. Every other entry is round-tripped
|
||||
// untouched, so saving one capability cannot disturb another's config.
|
||||
// The single mutation entry point for both the Plugins dialog and the Python binding.
|
||||
// Replaces one capability's cap_config and writes config.json straight away, stamping the entry
|
||||
// with the plugin version currently running. Every other entry is round-tripped untouched, so
|
||||
// saving one capability cannot disturb another's config.
|
||||
bool store_capability_config(const std::string& plugin_key, const std::string& capability_name, const nlohmann::json& config);
|
||||
bool erase_capability_config(const std::string& plugin_key, const std::string& capability_name);
|
||||
|
||||
// Returns a default-constructed BaseConfig (see BaseConfig::empty) when the capability has
|
||||
// no stored config.
|
||||
// A default-constructed BaseConfig (see BaseConfig::empty) when there is no stored config.
|
||||
BaseConfig get_config(const std::string& plugin_key, const std::string& capability_name) const;
|
||||
bool has_config(const std::string& plugin_key, const std::string& capability_name) const;
|
||||
|
||||
bool dirty() const;
|
||||
|
||||
// ---- Webview-facing helpers, shared by PluginsDialog's Config tab and PluginsConfigDialog ----
|
||||
//
|
||||
// These build the payloads both dialogs' config views speak, so the two pages stay in step and
|
||||
// neither dialog owns the config protocol. They are static because a capability's config is
|
||||
// addressed globally by (plugin_key, capability_name) through PluginManager's store, not through
|
||||
// any one PluginConfig instance.
|
||||
//
|
||||
// The caller owns the UI: it confirms destructive restores and shows status toasts. These only
|
||||
// touch the store, the loaded capability, and the payload.
|
||||
// Static because a capability's config is addressed globally by (plugin_key, capability_name)
|
||||
// through PluginManager's store, not through any one PluginConfig instance. The caller owns the
|
||||
// UI: it confirms destructive restores and shows status toasts.
|
||||
|
||||
// The config sidebar's rows: one entry per capability, in the order given. Capabilities that are
|
||||
// no longer loaded are skipped — the sidebar only offers what can actually be configured.
|
||||
// The config sidebar's rows, in the order given. Capabilities that are no longer loaded are
|
||||
// skipped — the sidebar only offers what can actually be configured.
|
||||
static nlohmann::json capabilities_payload(const std::vector<PluginCapabilityIdentifier>& caps);
|
||||
|
||||
// One capability's stored config, plus its custom HTML UI when it provides one.
|
||||
static nlohmann::json get_config_response(const PluginCapabilityIdentifier& id);
|
||||
|
||||
// Persists one capability's config. `config` is either text straight from the default editor
|
||||
// (re-parsed here, so malformed JSON can never reach config.json) or a structured value from a
|
||||
// custom UI.
|
||||
// Persists one capability's config. `config` is either text from the default editor (re-parsed
|
||||
// here, so malformed JSON can never reach config.json) or a structured value from a custom UI.
|
||||
static nlohmann::json save_config_response(const PluginCapabilityIdentifier& id, const nlohmann::json& config);
|
||||
|
||||
// Overwrites one capability's stored config with its get_default_config(). The caller must have
|
||||
@@ -145,23 +110,21 @@ private:
|
||||
bool m_dirty = false;
|
||||
};
|
||||
|
||||
// Host implementations behind the capability-level Python config API (bound onto every
|
||||
// capability class in PythonPluginBridge). The capability addresses only itself: the
|
||||
// (plugin_key, capability_name) pair is read off the instance the call arrived on, never
|
||||
// passed in from Python, so a capability cannot reach another capability's config.
|
||||
// Throw std::runtime_error (surfacing to Python as RuntimeError) on an unmaterialized instance.
|
||||
// Host implementations behind the capability-level Python config API (bound onto every capability
|
||||
// class in PythonPluginBridge). The capability addresses only itself: the (plugin_key,
|
||||
// capability_name) pair is read off the instance the call arrived on, never passed in from Python,
|
||||
// so a capability cannot reach another capability's config. Throws std::runtime_error (RuntimeError
|
||||
// in Python) on an unmaterialized instance.
|
||||
|
||||
// Only the user-editable cap_config, resolved the way the config UI presents it: the active preset's
|
||||
// override when it has one, otherwise the config stored here (see active_capability_config). An
|
||||
// empty object when neither layer holds one.
|
||||
// The cap_config resolved as the config UI presents it: the active preset's override when it has
|
||||
// one, otherwise the config stored here (see active_capability_config). Empty object when neither.
|
||||
nlohmann::json capability_get_config(const PluginCapabilityInterface& capability);
|
||||
// The plugin version that last wrote the config get_config() returns — the same layer it came from —
|
||||
// so a plugin can migrate a stale cap_config. Empty when the capability has no stored config.
|
||||
// The plugin version that wrote the config get_config() returns — the same layer it came from — so a
|
||||
// plugin can migrate a stale cap_config. Empty when the capability has no stored config.
|
||||
std::string capability_get_config_version(const PluginCapabilityInterface& capability);
|
||||
// Replaces cap_config and persists. Host-managed identity and version metadata are preserved.
|
||||
// Writes the store here, never a preset: presets are the user's to edit, and a plugin saving from a
|
||||
// worker thread cannot mark one dirty. A capability whose active preset overrides it will therefore
|
||||
// keep reading that override back, not what it saved.
|
||||
// Replaces cap_config and persists. Always writes the store, never a preset: presets are the user's
|
||||
// to edit, and a plugin saving from a worker thread cannot mark one dirty. A capability whose active
|
||||
// preset overrides it will therefore keep reading that override back, not what it saved.
|
||||
bool capability_save_config(const PluginCapabilityInterface& capability, const nlohmann::json& config);
|
||||
|
||||
} // namespace Slic3r
|
||||
|
||||
@@ -28,18 +28,16 @@ namespace Slic3r {
|
||||
|
||||
namespace {
|
||||
|
||||
// Return the name of the tracked option in `preset` whose value references `ref`'s capability, or
|
||||
// an empty string when no active option uses it. The result doubles as the "Jump to" target and as
|
||||
// the signal that the plugin is still required: a missing plugin with no referencing option is
|
||||
// considered resolved and dropped from the missing set.
|
||||
// The tracked option in `preset` whose value references `ref`'s capability, or "" when none does.
|
||||
// Doubles as the "Jump to" target and as the signal that the plugin is still required: a missing
|
||||
// plugin with no referencing option is dropped from the set.
|
||||
std::string find_option_for_capability(Preset::Type type, const Preset& preset, const PluginCapabilityRef& ref)
|
||||
{
|
||||
if (type != Preset::TYPE_PRINT && type != Preset::TYPE_PRINTER && type != Preset::TYPE_FILAMENT)
|
||||
return {};
|
||||
|
||||
// Plugin-bearing options opt in via ConfigOptionDef::is_plugin_backed (a non-empty plugin_type),
|
||||
// so scan the preset's definition rather than maintaining a hardcoded per-type field list. A typed
|
||||
// preset's config only contains keys for its own type, so this naturally stays scoped to `type`.
|
||||
// Options opt in via ConfigOptionDef::is_plugin_backed, so scan the definition rather than keep a
|
||||
// hardcoded per-type field list. A typed preset's config only holds keys for its own type.
|
||||
const ConfigDef* def = preset.config.def();
|
||||
if (def == nullptr)
|
||||
return {};
|
||||
@@ -80,8 +78,7 @@ std::string find_option_for_capability(Preset::Type type, const Preset& preset,
|
||||
|
||||
} // namespace
|
||||
|
||||
// One missing-plugin set per tracked preset type, keyed by the full "name;uuid;capability" ref.
|
||||
// Only TYPE_PRINT (process), TYPE_PRINTER (machine) and TYPE_FILAMENT are tracked.
|
||||
// One set per tracked preset type, keyed by the full "name;uuid;capability" ref.
|
||||
static std::map<Preset::Type, std::unordered_map<std::string, MissingPlugin>> s_missing;
|
||||
static std::mutex s_missing_mutex;
|
||||
// Installed-but-inactive capabilities (not loaded, or loaded-but-disabled); resolvable locally.
|
||||
@@ -108,7 +105,6 @@ std::vector<PluginCapabilityRef> referenced_capabilities(Preset::Type type, cons
|
||||
const auto ref = parse_capability_ref(entry);
|
||||
if (!ref)
|
||||
continue;
|
||||
// The same test the missing-plugin path uses: an entry no option points at is not in use.
|
||||
if (find_option_for_capability(type, preset, *ref).empty())
|
||||
continue;
|
||||
refs.push_back(*ref);
|
||||
@@ -119,15 +115,15 @@ std::vector<PluginCapabilityRef> referenced_capabilities(Preset::Type type, cons
|
||||
namespace {
|
||||
|
||||
// Resolve one preset's referenced capabilities to loaded capability identifiers, appending to `out`.
|
||||
// A ref whose plugin is not in the catalog, or whose capability is not currently loaded, is dropped:
|
||||
// there is no instance to ask for a config UI or defaults, so there is nothing to configure.
|
||||
// A ref not in the catalog, or whose capability is not loaded, is dropped: no instance means nothing
|
||||
// to configure.
|
||||
void collect_capabilities_in_use(Preset::Type type, const Preset& preset, std::vector<PluginCapabilityIdentifier>& out)
|
||||
{
|
||||
PluginLoader& loader = PluginManager::instance().get_loader();
|
||||
const PluginCatalog& catalog = PluginManager::instance().get_catalog();
|
||||
|
||||
for (const PluginCapabilityRef& ref : referenced_capabilities(type, preset)) {
|
||||
// Cloud plugins resolve by UUID, local plugins by plugin_key — the rule refresh_missing_plugins uses.
|
||||
// Cloud plugins resolve by UUID, local plugins by plugin_key.
|
||||
const std::string key = ref.uuid.empty() ? ref.name : ref.uuid;
|
||||
if (key.empty())
|
||||
continue;
|
||||
@@ -156,8 +152,8 @@ std::vector<PluginCapabilityIdentifier> capabilities_in_use(const PresetBundle&
|
||||
} else if (type == Preset::TYPE_PRINTER) {
|
||||
collect_capabilities_in_use(type, preset_bundle.printers.get_edited_preset(), result);
|
||||
} else {
|
||||
// Filament: every selected filament preset, tested against its own config. (Note that
|
||||
// refresh_missing_plugins cannot do this — it unions the manifests and loses the preset.)
|
||||
// Each filament preset is tested against its own config; refresh_missing_plugins cannot do
|
||||
// that, as it unions the manifests and loses the preset.
|
||||
for (const std::string& filament_name : preset_bundle.filament_presets)
|
||||
if (const Preset* filament = preset_bundle.filaments.find_preset(filament_name))
|
||||
collect_capabilities_in_use(type, *filament, result);
|
||||
@@ -233,9 +229,7 @@ std::string resolve_recovery_url(const PluginCapabilityRef& ref)
|
||||
return resolve_cloud_base_url() + "/app/plugins/plugin-hub?search=" + Http::url_encode(ref.name);
|
||||
}
|
||||
|
||||
// Reports whether the loaded plugin currently exposes the referenced capability (in any enabled
|
||||
// state) and whether that capability is enabled. Returns {false, false} when the plugin is not
|
||||
// loaded or does not provide the capability.
|
||||
// {present, enabled}; {false, false} when the plugin is not loaded or does not provide the capability.
|
||||
static std::pair<bool, bool> loaded_capability_state(const std::string& plugin_key, const PluginCapabilityRef& ref)
|
||||
{
|
||||
bool present = false, enabled = false;
|
||||
@@ -312,7 +306,7 @@ void refresh_missing_plugins(Preset::Type type, const ConfigOptionStrings* manif
|
||||
continue;
|
||||
|
||||
if (!installed) {
|
||||
// Not on disk — needs download/install (existing behavior).
|
||||
// Not on disk — needs download/install.
|
||||
std::string recovery_url = ref->uuid.empty() ? resolve_recovery_url(*ref) : std::string();
|
||||
missing_set.emplace(entry, MissingPlugin{*ref, std::move(recovery_url), std::move(opt), type, PluginCapabilityType::Unknown});
|
||||
} else if (!loaded || cap_present) {
|
||||
@@ -406,7 +400,6 @@ static void report_install_failure(const std::string& message)
|
||||
|
||||
void resolve_missing_plugins(const std::vector<std::string>& refs, PluginInstallProgress progress)
|
||||
{
|
||||
// Collect the unique cloud UUIDs to install; local refs are handled via the browser flow.
|
||||
std::vector<std::string> uuids;
|
||||
for (const std::string& r : refs) {
|
||||
const auto ref = parse_capability_ref(r);
|
||||
@@ -430,7 +423,6 @@ void resolve_missing_plugins(const std::vector<std::string>& refs, PluginInstall
|
||||
|
||||
const std::string& uuid = uuids[i];
|
||||
|
||||
// Use a friendly name for the progress message when the catalog already knows it.
|
||||
std::string display_name = uuid;
|
||||
PluginDescriptor known;
|
||||
if (mgr.get_catalog().try_get_plugin_descriptor(uuid, known) && !known.name.empty())
|
||||
@@ -466,8 +458,7 @@ void resolve_inactive_plugins(const std::vector<std::string>& refs)
|
||||
PluginManager& mgr = PluginManager::instance();
|
||||
PluginCatalog& catalog = mgr.get_catalog();
|
||||
|
||||
// Group the requested capabilities by owning plugin so each plugin is loaded once with the full
|
||||
// set to enable.
|
||||
// Group by owning plugin so each plugin is loaded once with the full set to enable.
|
||||
std::map<std::string, std::vector<std::string>> by_plugin;
|
||||
for (const std::string& r : refs) {
|
||||
const auto ref = parse_capability_ref(r);
|
||||
@@ -482,11 +473,9 @@ void resolve_inactive_plugins(const std::vector<std::string>& refs)
|
||||
if (by_plugin.empty())
|
||||
return;
|
||||
|
||||
// load_plugin loads+enables a not-loaded plugin (async) and enables the listed capabilities on an
|
||||
// already-loaded one. The fresh-load path does NOT fire the capability-load callback the GUI uses
|
||||
// to clear the notification, so wait for each load off the UI thread and then re-validate once —
|
||||
// mirroring the cloud-install flow. This clears the inactive notification, or flips it to broken
|
||||
// if the loaded plugin turns out not to provide the capability.
|
||||
// The fresh-load path does NOT fire the capability-load callback the GUI uses to clear the
|
||||
// notification, so wait for each load off the UI thread and re-validate once. That clears the
|
||||
// inactive notification, or flips it to broken if the plugin does not provide the capability.
|
||||
std::vector<std::pair<std::string, std::vector<std::string>>> work(by_plugin.begin(), by_plugin.end());
|
||||
std::thread([work = std::move(work)]() {
|
||||
PluginManager& mgr = PluginManager::instance();
|
||||
@@ -506,7 +495,6 @@ void resolve_inactive_plugins(const std::vector<std::string>& refs)
|
||||
|
||||
void open_missing_plugins_on_cloud(const std::vector<std::string>& local_refs)
|
||||
{
|
||||
// One missing plugin: deep-link a search for it. Multiple: just open the plugin hub.
|
||||
if (local_refs.size() == 1) {
|
||||
if (const auto ref = parse_capability_ref(local_refs.front())) {
|
||||
wxLaunchDefaultBrowser(GUI::from_u8(resolve_recovery_url(*ref)), wxBROWSER_NEW_WINDOW);
|
||||
|
||||
@@ -24,10 +24,9 @@ struct MissingPlugin
|
||||
PluginCapabilityType type{PluginCapabilityType::Unknown};
|
||||
};
|
||||
|
||||
// Rebuild the missing-plugin set owned by a single preset type from that preset's "plugins"
|
||||
// manifest, comparing each ref against the live plugin catalog and loaded/enabled capabilities. A
|
||||
// null/empty manifest clears the set for that type. Only TYPE_PRINT (process), TYPE_PRINTER
|
||||
// (machine) and TYPE_FILAMENT are tracked; other types are ignored.
|
||||
// Rebuild one preset type's missing-plugin set from its "plugins" manifest, comparing each ref
|
||||
// against the live catalog and loaded/enabled capabilities. A null/empty manifest clears the set.
|
||||
// Only TYPE_PRINT, TYPE_PRINTER and TYPE_FILAMENT are tracked.
|
||||
void refresh_missing_plugins(Preset::Type type, const ConfigOptionStrings* manifest, const Preset* preset = nullptr);
|
||||
void refresh_missing_plugins(const PresetBundle& preset_bundle);
|
||||
|
||||
@@ -37,22 +36,16 @@ std::vector<MissingPlugin> get_missing_cloud_plugins();
|
||||
std::vector<MissingPlugin> get_missing_local_plugins();
|
||||
bool has_missing_plugins();
|
||||
|
||||
// Installed-but-inactive capabilities: the plugin has a local package but the referenced capability
|
||||
// is not active because the plugin is not loaded, or it is loaded but the capability is disabled.
|
||||
// Resolved locally by loading the plugin and/or enabling the capability — no download.
|
||||
// Installed-but-inactive: the plugin has a local package but is not loaded, or is loaded with the
|
||||
// capability disabled. Resolved locally by loading and/or enabling — no download.
|
||||
std::vector<MissingPlugin> get_inactive_plugins();
|
||||
bool has_inactive_plugins();
|
||||
|
||||
// Broken references: the plugin is installed AND loaded but does not provide the referenced
|
||||
// capability at all (renamed/removed/outdated plugin). Activation cannot fix these; surfaced as an
|
||||
// informational notification pointing the user at OrcaCloud to update the plugin.
|
||||
// capability at all (renamed/removed/outdated plugin). Activation cannot fix these.
|
||||
std::vector<MissingPlugin> get_broken_plugins();
|
||||
bool has_broken_plugins();
|
||||
|
||||
// Resolution actions invoked from the missing-plugin notifications:
|
||||
// - cloud refs are subscribed/installed and loaded on a detached worker thread; failures are
|
||||
// reported through a non-blocking notification. Non-cloud refs are ignored.
|
||||
|
||||
// Optional progress hook for the cloud install worker. All three callbacks fire on the worker
|
||||
// thread; implementations must only touch thread-safe state or marshal to the UI thread.
|
||||
struct PluginInstallProgress
|
||||
@@ -65,43 +58,39 @@ struct PluginInstallProgress
|
||||
std::function<void()> on_finished;
|
||||
};
|
||||
|
||||
// Cloud refs only; local refs are handled via the browser flow. `progress` is optional — a
|
||||
// default-constructed value preserves the previous silent behavior.
|
||||
// Subscribe, install and load the cloud refs on a detached worker; failures are reported through a
|
||||
// non-blocking notification. Local refs are ignored — they go through the browser flow below.
|
||||
void resolve_missing_plugins(const std::vector<std::string>& refs,
|
||||
PluginInstallProgress progress = {});
|
||||
|
||||
// Activate inactive plugins: load each referenced plugin (passing the capabilities to enable) and/or
|
||||
// enable already-loaded-but-disabled capabilities. Local only — no network. The loads run on a
|
||||
// background worker that waits for them and then re-validates the plate, clearing the notification
|
||||
// (or reclassifying the ref as broken if the loaded plugin turns out not to provide the capability).
|
||||
// Load each referenced plugin and/or enable its disabled capabilities. Local only — no network. The
|
||||
// loads run on a background worker that waits for them and then re-validates the plate, clearing the
|
||||
// notification (or reclassifying the ref as broken if the plugin does not provide the capability).
|
||||
void resolve_inactive_plugins(const std::vector<std::string>& refs);
|
||||
|
||||
// - local refs are opened on the OrcaCloud plugin hub (search when exactly one ref, hub otherwise).
|
||||
// Opens the OrcaCloud plugin hub (a search when there is exactly one ref, the hub otherwise).
|
||||
void open_missing_plugins_on_cloud(const std::vector<std::string>& local_refs);
|
||||
|
||||
std::string create_full_ref(const PluginCapabilityRef& ref);
|
||||
std::string resolve_recovery_url(const PluginCapabilityRef& ref);
|
||||
|
||||
// The capabilities `preset`'s "plugins" manifest declares AND that one of its plugin-backed options
|
||||
// (ConfigOptionDef::is_plugin_backed) currently references. A manifest entry nobody points at is not
|
||||
// in use. Pure preset logic — the plugin catalog and loader are not consulted. Empty for untracked
|
||||
// preset types.
|
||||
// (ConfigOptionDef::is_plugin_backed) currently references: a manifest entry nobody points at is not
|
||||
// in use. Pure preset logic — the catalog and loader are not consulted. Empty for untracked types.
|
||||
std::vector<PluginCapabilityRef> referenced_capabilities(Preset::Type type, const Preset& preset);
|
||||
std::vector<PluginCapabilityIdentifier> capabilities_in_use(Preset::Type type, const Preset& preset);
|
||||
|
||||
// The preset type that owns capabilities of `type` — the one whose presets can reference them and
|
||||
// therefore carry their overrides. Derived from the ConfigDef rather than hardcoded: a plugin-backed
|
||||
// option names the capability type it accepts (ConfigOptionDef::plugin_type) and belongs to exactly
|
||||
// one preset type, so declaring the option is all it takes to map a new capability type.
|
||||
// TYPE_INVALID when no option accepts the type (nothing can reference it, so no preset owns it).
|
||||
// The preset type whose presets can reference capabilities of `type` and therefore carry their
|
||||
// overrides. Derived from the ConfigDef rather than hardcoded: a plugin-backed option names the
|
||||
// capability type it accepts (ConfigOptionDef::plugin_type) and belongs to exactly one preset type,
|
||||
// so declaring the option is all it takes to map a new capability type. TYPE_INVALID when no option
|
||||
// accepts the type — nothing can reference it, so no preset owns it.
|
||||
Preset::Type preset_type_for_capability(PluginCapabilityType type);
|
||||
|
||||
// The capabilities the active preset(s) of `type` reference (see referenced_capabilities) and that
|
||||
// are loaded right now: the set that can actually be configured. Missing and broken refs are absent,
|
||||
// having no instance to ask for a config UI or defaults. A loaded-but-disabled capability IS listed —
|
||||
// it still has stored config worth editing, and disabling it is not a reason to hide that.
|
||||
// TYPE_FILAMENT unions every selected filament preset; a capability used by two extruders is listed
|
||||
// once. Deduped on the full identity, so two plugins exposing a same-named capability stay distinct.
|
||||
// The referenced capabilities of the active preset(s) of `type` that are loaded right now: the set
|
||||
// that can actually be configured. Missing and broken refs are absent, having no instance to ask for
|
||||
// a config UI or defaults. A loaded-but-disabled capability IS listed — it still has stored config
|
||||
// worth editing.
|
||||
std::vector<PluginCapabilityIdentifier> capabilities_in_use(const PresetBundle& preset_bundle, Preset::Type type);
|
||||
|
||||
bool check_capability_in_use(const std::string& capability_refs);
|
||||
|
||||
@@ -26,8 +26,8 @@ std::string running_plugin_version(const std::string& plugin_key)
|
||||
return descriptor.installed_version.empty() ? descriptor.version : descriptor.installed_version;
|
||||
}
|
||||
|
||||
// Null wherever the plugin host runs without the GUI app (the unit tests): there are no presets
|
||||
// then, only the base config. wxGetApp() dereferences the app unconditionally, so ask wxWidgets.
|
||||
// Null wherever the plugin host runs without the GUI app (the unit tests). wxGetApp() dereferences
|
||||
// the app unconditionally, so ask wxWidgets instead.
|
||||
const PresetBundle* active_preset_bundle()
|
||||
{
|
||||
const auto* app = dynamic_cast<const GUI::GUI_App*>(wxApp::GetInstance());
|
||||
@@ -46,22 +46,15 @@ const Preset* active_preset_for(Preset::Type type)
|
||||
case Preset::TYPE_PRINT: return &bundle->prints.get_edited_preset();
|
||||
case Preset::TYPE_PRINTER: return &bundle->printers.get_edited_preset();
|
||||
|
||||
// Deliberately unimplemented, not forgotten.
|
||||
//
|
||||
// There is no single active filament preset: one is selected per extruder, and a capability
|
||||
// calls get_config() without saying which extruder it is running for, so we cannot tell which
|
||||
// of them owns the config. Guessing (first override wins, or extruder 0) would hand a plugin
|
||||
// another extruder's settings and look like a plugin bug, so it reads the base config instead —
|
||||
// the value it had before presets could override anything.
|
||||
//
|
||||
// Nothing reaches this today: preset_type_for_capability only names TYPE_FILAMENT once a
|
||||
// filament option declares a plugin_type, and none does (the two plugin-backed options are
|
||||
// print and printer ones). Solve it with the first filament-backed capability, by pushing the
|
||||
// extruder onto the plugin call context the trampoline already maintains
|
||||
// (ScopedPluginAuditContext) along with the override text snapshotted off the preset, and
|
||||
// resolving the preset here from that instead of from the bundle. The extruder must be optional:
|
||||
// whole slicing steps (posSlice, psGCodePostProcess) span every extruder and have no current
|
||||
// filament, and this fallback is the honest answer for them.
|
||||
// Deliberately unimplemented, not forgotten. There is no single active filament preset — one is
|
||||
// selected per extruder, and get_config() does not say which extruder the capability runs for —
|
||||
// so guessing (extruder 0, or first override wins) would hand a plugin another extruder's
|
||||
// settings. Filament capabilities read the base config instead. Nothing reaches this today:
|
||||
// preset_type_for_capability only names TYPE_FILAMENT once a filament option declares a
|
||||
// plugin_type, and none does. To lift it, push the extruder onto the plugin call context the
|
||||
// trampoline already maintains (ScopedPluginAuditContext) and resolve the preset from that. The
|
||||
// extruder must be optional: whole slicing steps (posSlice, psGCodePostProcess) span every
|
||||
// extruder and have no current filament, and this fallback is the honest answer for them.
|
||||
case Preset::TYPE_FILAMENT: return nullptr;
|
||||
|
||||
default: return nullptr;
|
||||
@@ -146,8 +139,8 @@ MutationResult PresetPluginConfigService::set_preset_override(CapabilityConfigDo
|
||||
const CapabilityConfigId config_id = make_id(id);
|
||||
const std::string version = running_plugin_version(id.plugin_key);
|
||||
|
||||
// A no-op is a successful unchanged result, not a reason to rewrite the preset: re-saving the
|
||||
// displayed value must not be able to mark it dirty.
|
||||
// A no-op is a successful unchanged result: re-saving the displayed value must not mark the
|
||||
// preset dirty.
|
||||
const auto existing = overrides.find(config_id);
|
||||
if (existing && existing->cap_config == value && existing->plugin_version == version) {
|
||||
result.ok = true;
|
||||
@@ -169,7 +162,6 @@ MutationResult PresetPluginConfigService::remove_preset_override(CapabilityConfi
|
||||
MutationResult result;
|
||||
result.ok = true;
|
||||
result.changed = overrides.erase(make_id(id));
|
||||
// Reads back as the base value now that the override is gone.
|
||||
result.effective = get_effective_config(overrides, id);
|
||||
return result;
|
||||
}
|
||||
@@ -182,8 +174,7 @@ EffectiveCapabilityConfig active_capability_config(const PluginCapabilityIdentif
|
||||
if (const Preset* preset = active_preset_for(preset_type_for_capability(id.type))) {
|
||||
std::string error;
|
||||
if (!parse_plugin_overrides(plugin_overrides_of(*preset), overrides, error)) {
|
||||
// Text we cannot read is not an override. Say so and resolve against the base config,
|
||||
// which is what the capability ran with before anything was written into the preset.
|
||||
// Text we cannot read is not an override: log it and resolve against the base config.
|
||||
BOOST_LOG_TRIVIAL(error) << "Preset \"" << preset->name << "\": " << error;
|
||||
overrides = CapabilityConfigDocument();
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ std::string plugin_overrides_of(const Preset& preset);
|
||||
bool parse_plugin_overrides(const std::string& raw, CapabilityConfigDocument& document, std::string& error);
|
||||
|
||||
// The document as compact JSON text, and "" once it holds no entries. Empty text — rather than a
|
||||
// removed option — is what records "cleared here" against an inheriting parent that has overrides.
|
||||
// removed option — records "cleared here" against an inheriting parent that has overrides.
|
||||
std::string serialize_plugin_overrides(const CapabilityConfigDocument& document);
|
||||
|
||||
struct EffectiveCapabilityConfig
|
||||
@@ -49,12 +49,10 @@ struct MutationResult
|
||||
std::string plugin_config_source_to_string(PluginConfigSource source);
|
||||
|
||||
// Resolves a capability's effective config as `preset override -> base config -> none`, and mutates
|
||||
// the override layer.
|
||||
//
|
||||
// It works on a CapabilityConfigDocument the caller owns, never on a Preset and never on the base
|
||||
// config file. That is what keeps the two layers from writing to each other: PluginConfigField holds
|
||||
// the document, and feeds the edited text back through the normal field/dirty pipeline, so the
|
||||
// preset is written exactly the way every other setting is.
|
||||
// the override layer. It works on a CapabilityConfigDocument the caller owns, never on a Preset and
|
||||
// never on the base config file, which is what keeps the two layers from writing to each other:
|
||||
// PluginConfigField holds the document and feeds the edited text back through the normal field/dirty
|
||||
// pipeline, so the preset is written the way every other setting is.
|
||||
class PresetPluginConfigService
|
||||
{
|
||||
public:
|
||||
@@ -67,15 +65,11 @@ public:
|
||||
const PluginCapabilityIdentifier& id) const;
|
||||
};
|
||||
|
||||
// The same `preset override -> base config -> none` resolution, against the preset that is active
|
||||
// right now instead of a document the caller holds: this is what a running capability reads through
|
||||
// the Python config API, so a preset that overrides a capability configures the slice it drives.
|
||||
//
|
||||
// Only one preset type can reference a given capability type (preset_type_for_capability), so there
|
||||
// is exactly one preset to consult. Filament capabilities are the exception and are not supported:
|
||||
// the active filament preset is per-extruder and a capability does not say which extruder it runs
|
||||
// for, so they read the base config. See active_preset_for() for why, and for what it will take to
|
||||
// lift that. Base config also in a host with no preset bundle (the plugin unit tests).
|
||||
// The same resolution against the preset that is active right now, rather than a document the caller
|
||||
// holds: this is what a running capability reads through the Python config API. Only one preset type
|
||||
// can reference a given capability type (preset_type_for_capability), so there is exactly one preset
|
||||
// to consult. Falls back to the base config for filament capabilities (see active_preset_for) and in
|
||||
// a host with no preset bundle (the plugin unit tests).
|
||||
EffectiveCapabilityConfig active_capability_config(const PluginCapabilityIdentifier& id);
|
||||
|
||||
} // namespace Slic3r
|
||||
|
||||
@@ -12,17 +12,14 @@
|
||||
#include "PythonJsonUtils.hpp"
|
||||
#include "PluginAuditManager.hpp"
|
||||
|
||||
// Trampoline variants of pybind11's override macros. Every C++->Python plugin call
|
||||
// crosses through a trampoline method, so this single boundary is where we (1) log the
|
||||
// full Python traceback (to sys.stderr -> session log) and rethrow the exception intact,
|
||||
// and (2) open the plugin's filesystem audit scope for the duration of the call.
|
||||
// We catch ONLY error_already_set (a Python-side raise); other pybind11_fail/runtime_error
|
||||
// like a pure-virtual-missing failure must keep their own path and are deliberately not
|
||||
// caught here.
|
||||
// Trampoline variants of pybind11's override macros. Every C++->Python plugin call crosses a
|
||||
// trampoline method, so this single boundary is where we (1) log the full Python traceback and
|
||||
// rethrow the exception intact, and (2) open the plugin's filesystem audit scope for the call.
|
||||
// We catch ONLY error_already_set (a Python-side raise); other pybind11_fail/runtime_error, such as
|
||||
// a pure-virtual-missing failure, must keep their own path and are deliberately not caught here.
|
||||
|
||||
// Logs (and rethrows) a Python exception from a pybind11 override call, preserving the
|
||||
// traceback. Internal helper shared by the public macros below and by trampolines that
|
||||
// manage their own audit scope (e.g. the G-code plugin).
|
||||
// Shared by the macros below and by trampolines that manage their own audit scope (e.g. the G-code
|
||||
// plugin).
|
||||
#define ORCA_PY_LOGGED_OVERRIDE_BODY(override_call) \
|
||||
try { \
|
||||
override_call; \
|
||||
@@ -31,10 +28,9 @@
|
||||
throw; \
|
||||
}
|
||||
|
||||
// Opens the plugin's filesystem audit scope for the duration of a C++ -> Python call
|
||||
// when this trampoline instance carries a non-empty audit plugin key. Also publishes the
|
||||
// calling capability's name, so host APIs invoked from Python can tell which capability
|
||||
// they are serving. Declares a local `_orca_audit_scope`.
|
||||
// Opens the plugin's filesystem audit scope for the duration of a C++ -> Python call, and publishes
|
||||
// the calling capability's name so host APIs invoked from Python can tell which capability they are
|
||||
// serving. No-op without an audit plugin key. Declares a local `_orca_audit_scope`.
|
||||
#define ORCA_PY_AUDIT_SCOPE(mode) \
|
||||
std::optional<::Slic3r::ScopedPluginAuditContext> _orca_audit_scope; \
|
||||
if (const std::string& _orca_audit_key = this->audit_plugin_key(); \
|
||||
@@ -68,9 +64,8 @@ public:
|
||||
}
|
||||
|
||||
// Config UI hooks. Available on every capability type, so they live here rather than in
|
||||
// PyPluginInterfaceTrampoline. Audited like any other C++ -> Python call; a Python
|
||||
// exception is logged with its traceback and rethrown, and the caller (PluginLoader at
|
||||
// load time, PluginsDialog when opening the Config tab) decides the fallback.
|
||||
// PyPluginInterfaceTrampoline. A Python exception is rethrown and the caller decides the
|
||||
// fallback.
|
||||
bool has_config_ui() const override
|
||||
{
|
||||
ORCA_PY_OVERRIDE_AUDITED(
|
||||
@@ -95,15 +90,11 @@ public:
|
||||
|
||||
// Hand-rolled rather than PYBIND11_OVERRIDE: the macro casts the Python result to the return
|
||||
// type, and nlohmann::json has no pybind caster (config crosses this boundary through the
|
||||
// explicit py_to_json/json_to_py helpers instead). Otherwise identical — same audit scope, and
|
||||
// a Python exception is logged with its traceback and rethrown for the caller to handle.
|
||||
// explicit py_to_json/json_to_py helpers). Otherwise identical — same audit scope, same rethrow.
|
||||
//
|
||||
// The hook is optional, and "not implemented" must mean an EMPTY config, never a null or a
|
||||
// stray scalar landing in cap_config. Two ways to not implement it, both resolved here:
|
||||
// - no override at all -> the base's empty object
|
||||
// - an override that returns None, or any -> likewise. `def get_default_config(self): pass`
|
||||
// non-object (a list, a string, a number) is the easy mistake, and it must not be able to
|
||||
// write `"cap_config": null` to config.json.
|
||||
// The hook is optional, and "not implemented" must mean an EMPTY config: no override, or an
|
||||
// override returning None or any non-object (`def get_default_config(self): pass` is the easy
|
||||
// mistake), both fall back to the base's empty object rather than writing `"cap_config": null`.
|
||||
nlohmann::json get_default_config() const override
|
||||
{
|
||||
ORCA_PY_AUDIT_SCOPE(::Slic3r::PluginAuditManager::AuditMode::Loading);
|
||||
@@ -127,7 +118,6 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
// All plugins may define their own on_load/unload functions.
|
||||
void on_load() override
|
||||
{
|
||||
ORCA_PY_OVERRIDE_AUDITED(
|
||||
@@ -156,8 +146,6 @@ class PyPluginInterfaceTrampoline : public PyPluginCommonTrampoline<PluginCapabi
|
||||
public:
|
||||
using PyPluginCommonTrampoline<PluginCapabilityInterface>::PyPluginCommonTrampoline;
|
||||
|
||||
// get_name is implemented in PyPluginCommonTrampoline (PYBIND11_OVERRIDE_PURE).
|
||||
|
||||
PluginCapabilityType get_type() const override
|
||||
{
|
||||
ORCA_PY_OVERRIDE_AUDITED(
|
||||
|
||||
@@ -105,41 +105,33 @@ public:
|
||||
// Optional APIs
|
||||
virtual PluginCapabilityType get_type() const { return PluginCapabilityType::Unknown; }
|
||||
|
||||
// Every capability is configurable: it always appears in the Plugins dialog's Config
|
||||
// sidebar and always has the host's default JSON editor over its stored config. The only
|
||||
// question a capability answers is whether it supplies its own UI to edit that config
|
||||
// *instead of* the JSON editor.
|
||||
//
|
||||
// True when the capability ships a custom configuration UI. get_config_ui() is called
|
||||
// only when this returns true.
|
||||
// Every capability is configurable and always gets the host's default JSON editor over its
|
||||
// stored config; this only says whether it supplies its own UI *instead of* that editor.
|
||||
// get_config_ui() is called only when it returns true.
|
||||
virtual bool has_config_ui() const { return false; }
|
||||
// An HTML snippet for the custom configuration UI. An empty or throwing result is
|
||||
// treated as "no custom UI" and falls back to the default JSON editor.
|
||||
// An HTML snippet for the custom configuration UI. An empty or throwing result is treated as
|
||||
// "no custom UI" and falls back to the default JSON editor.
|
||||
virtual std::string get_config_ui() const { return ""; }
|
||||
|
||||
// The config the Config tab's "Restore defaults" action writes back. Optional.
|
||||
//
|
||||
// Not overridden -> an empty object, which is the right answer for a capability that keeps
|
||||
// its stored config sparse and applies its own defaults on read: clearing the overrides
|
||||
// *is* restoring the defaults, and it keeps a later release free to change them.
|
||||
// Override it to write an explicit starting config instead (e.g. to seed a form UI with
|
||||
// every field present). The host neither invents nor validates this value; it only stores
|
||||
// whatever comes back, so a throwing override leaves the stored config untouched.
|
||||
// The config the "Restore defaults" action writes back. Not overridden -> an empty object, which
|
||||
// is right for a capability that keeps its stored config sparse and applies its own defaults on
|
||||
// read. Override it to write an explicit starting config instead (e.g. to seed a form UI with
|
||||
// every field present). The host neither invents nor validates this value, so a throwing override
|
||||
// leaves the stored config untouched.
|
||||
virtual nlohmann::json get_default_config() const { return nlohmann::json::object(); }
|
||||
|
||||
virtual void on_load() {}
|
||||
virtual void on_unload() {}
|
||||
|
||||
// C++-only audit identity (never exposed to Python). Set by PluginLoader after
|
||||
// plugin capture so trampoline calls can scope filesystem enforcement to this
|
||||
// plugin. This is PluginDescriptor::plugin_key, the canonical runtime id.
|
||||
// C++-only audit identity (never exposed to Python), set by PluginLoader after plugin capture so
|
||||
// trampoline calls can scope filesystem enforcement to this plugin. PluginDescriptor::plugin_key.
|
||||
void set_audit_plugin_key(std::string key) { m_audit_plugin_key = std::move(key); }
|
||||
const std::string& audit_plugin_key() const { return m_audit_plugin_key; }
|
||||
|
||||
// The cached get_name() captured at load, paired with the audit plugin key to identify
|
||||
// which capability a trampoline call belongs to. Cached rather than read live: get_name()
|
||||
// is itself a trampoline call, so calling it from inside a trampoline would recurse.
|
||||
// Empty until PluginLoader materializes the capability.
|
||||
// get_name() cached at load, paired with the audit plugin key to identify which capability a
|
||||
// trampoline call belongs to. Cached rather than read live: get_name() is itself a trampoline
|
||||
// call, so calling it from inside a trampoline would recurse. Empty until PluginLoader
|
||||
// materializes the capability.
|
||||
void set_audit_capability_name(std::string name) { m_audit_capability_name = std::move(name); }
|
||||
const std::string& audit_capability_name() const { return m_audit_capability_name; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user