Regroup the slicer's MCP commands and let each run from its arguments

Outside the Design tab an agent had 175 commands, 50 of them in the tool
list. There are now 118, named by what they act on (`object_`, `plate_`,
`preset_`, `filament_`, `plugin_` and so on), and 115 are listed. Each takes
its target and values in the call, acts on the selection when it names no
target and says what it acted on; an old name is refused. Printers and
system filaments install and uninstall, preferences read and write, plugins
enable, reload, uninstall and refresh, and objects reorder, with no dialog
to drive.

The Speed Dial keeps its 129 tiles under the same ids. Eight defects in the
rows these commands share with the menus are fixed. For a person: an object
row that cannot run says why instead of "Select an object first.", rows
that failed no longer claim success, Duplicate Plate can be undone, and
Refresh Plugins picked while a refresh runs now runs after it instead of
beside it.
This commit is contained in:
SoftFever committed 2026-11-18 16:50:32 +08:00
1 parent 74c98e197c
commit d64e10f4dd
287 files changed
+40484 -16770

No files matched your search

+145 -309
View File
@@ -20,6 +20,8 @@
#include <slic3r/GUI/NotificationManager.hpp>
#include <slic3r/GUI/Plater.hpp>
#include "slic3r/GUI/Operations/Outcome.hpp"
#include "slic3r/GUI/Operations/PluginOps.hpp"
#include "slic3r/GUI/PluginPermissionValidation.hpp"
#include "slic3r/GUI/PluginSource.hpp"
#include "slic3r/GUI/PluginStatus.hpp"
@@ -34,8 +36,10 @@
#include <boost/log/trivial.hpp>
#include <algorithm>
#include <functional>
#include <memory>
#include <mutex>
#include <optional>
#include <string>
#include <utility>
#include <vector>
@@ -149,21 +153,6 @@ PluginCapabilityType primary_capability_type_of(PluginManager& manager, const st
return capabilities.empty() ? PluginCapabilityType::Unknown : capabilities.front()->type();
}
PluginDescriptor as_cloud_only_descriptor(PluginDescriptor descriptor)
{
descriptor.plugin_root.clear();
descriptor.entry_path.clear();
descriptor.installed_version.clear();
// No local package is left behind, so the package verdict and any load error it produced go with it.
descriptor.metadata_valid = false;
descriptor.clear_error();
if (descriptor.cloud.has_value()) {
descriptor.cloud->installed = false;
descriptor.cloud->update_available = false;
}
return descriptor;
}
std::string to_string(PluginUpdateStatus status);
nlohmann::json build_context_actions_payload(const PluginAvailableActions& available_actions);
@@ -265,55 +254,30 @@ std::string to_string(PluginUpdateStatus status)
return "normal";
}
PluginSource derive_plugin_source(const PluginDescriptor& descriptor)
{
const bool has_cloud_meta = descriptor.cloud.has_value();
const bool is_cloud = descriptor.is_cloud_plugin();
const bool is_mine = is_cloud && has_cloud_meta && descriptor.cloud->is_mine;
if (is_cloud && has_cloud_meta && descriptor.cloud->orphaned)
return PluginSource::Orphaned;
if (is_mine)
return PluginSource::Mine;
if (is_cloud)
return PluginSource::Subscribed;
return PluginSource::Local;
}
PluginAvailableActions evaluate_action_policy(const PluginDialogItem& item)
// The row's switch and menu items, from what Ops::plugin_actions() says the row offers.
PluginAvailableActions evaluate_action_policy(const PluginDescriptor& descriptor, bool loading)
{
PluginAvailableActions available_actions;
const bool is_loading = item.status == PluginStatus::Loading;
const bool is_cloud = item.is_cloud_plugin;
const bool is_orphaned = item.orphaned;
const bool is_mine = item.source == PluginSource::Mine;
const bool has_local = item.has_local_package;
const bool authorized_for_install = !item.unauthorized;
available_actions.toggle_installs_cloud_plugin = is_cloud && !is_orphaned && !has_local && authorized_for_install;
available_actions.can_toggle = !is_loading && (has_local || available_actions.toggle_installs_cloud_plugin);
const Ops::PluginActions offered = Ops::plugin_actions(descriptor, loading);
available_actions.toggle_installs_cloud_plugin = offered.toggle_installs_cloud_plugin;
available_actions.can_toggle = offered.can_toggle;
auto add_action = [&available_actions](const char* id, const char* label, bool enabled = true, bool danger = false) {
available_actions.context_actions.push_back(PluginContextAction{id, _u8L(label), enabled, danger});
};
// Owned cloud plugins fall through to the local delete: it removes the installed package only.
// Deleting a plugin from the cloud is a plugin hub operation and is never offered here.
if (is_cloud && !is_orphaned && !is_mine) {
if (offered.unsubscribe)
add_action("unsubscribe_plugin", L("Unsubscribe"), true, true);
} else if (has_local) {
else if (offered.remove)
add_action("delete_plugin", L("Delete"), true, true);
}
add_action("open_folder", L("Show in folder"), has_local);
add_action("open_folder", L("Show in folder"), offered.open_folder);
if (!is_orphaned) {
if (is_cloud) {
add_action("reinstall_plugin", L("Reinstall"));
} else {
add_action("reload_plugin", L("Reload"));
add_action("clear_cache_reload_plugin", L("Delete cache and reload"));
}
if (offered.reinstall)
add_action("reinstall_plugin", L("Reinstall"));
if (offered.reload) {
add_action("reload_plugin", L("Reload"));
add_action("clear_cache_reload_plugin", L("Delete cache and reload"));
}
return available_actions;
@@ -331,11 +295,7 @@ PluginDialogItem build_plugin_dialog_item(const PluginDescriptor& descriptor)
(descriptor.description.empty() ? _u8L("No description.") : descriptor.description);
item.author = descriptor.author;
item.version = descriptor.version;
// The cloud merge overwrites `version` with the latest cloud version, so prefer the preserved local
// one, falling back to `version` for local-only / pre-merge descriptors.
item.installed_version = descriptor.has_local_package() ?
(descriptor.installed_version.empty() ? descriptor.version : descriptor.installed_version) :
std::string{};
item.installed_version = Ops::installed_plugin_version(descriptor);
item.latest_version = descriptor.latest_available_version();
item.sort_version = item.installed_version.empty() ? item.latest_version : item.installed_version;
// A package that is not loaded has no capabilities, so its row contributes none and does not
@@ -362,7 +322,7 @@ PluginDialogItem build_plugin_dialog_item(const PluginDescriptor& descriptor)
}
for (const PluginChangelog& entry : descriptor.changelog)
item.changelog.push_back({entry.version, entry.changelog, entry.created_time});
item.source = derive_plugin_source(descriptor);
item.source = Ops::plugin_source(descriptor);
item.update_status = descriptor.get_update_status();
item.error_text = descriptor.normalized_error();
item.has_error = descriptor.has_error();
@@ -389,7 +349,7 @@ PluginDialogItem build_plugin_dialog_item(const PluginDescriptor& descriptor)
item.status = resolve_plugin_status(item.loading, item.has_error, item.is_loaded);
item.available_actions = evaluate_action_policy(item);
item.available_actions = evaluate_action_policy(descriptor, item.loading);
const bool has_enabled_script = std::any_of(item.capabilities.begin(), item.capabilities.end(),
[](const PluginCapabilityView& capability) {
return capability.id.type == PluginCapabilityType::Script && capability.enabled;
@@ -425,25 +385,24 @@ nlohmann::json build_context_actions_payload(const PluginAvailableActions& avail
return payload;
}
// The outcome of an operation run behind a progress dialog, handed from its worker to its completion.
struct PluginOperationState
{
std::mutex mutex;
bool succeeded = false;
std::string error;
std::mutex mutex;
std::optional<Ops::Outcome<Ops::Done>> outcome;
};
void store_plugin_operation_result(const std::shared_ptr<PluginOperationState>& state, bool succeeded, std::string error)
void store_plugin_operation_result(const std::shared_ptr<PluginOperationState>& state, Ops::Outcome<Ops::Done> outcome)
{
std::lock_guard<std::mutex> lock(state->mutex);
state->succeeded = succeeded;
state->error = std::move(error);
state->outcome.emplace(std::move(outcome));
}
bool take_plugin_operation_result(const std::shared_ptr<PluginOperationState>& state, std::string& error)
// The worker's outcome; none where it ended without one (it threw).
std::optional<Ops::Outcome<Ops::Done>> take_plugin_operation_result(const std::shared_ptr<PluginOperationState>& state)
{
std::lock_guard<std::mutex> lock(state->mutex);
error = std::move(state->error);
return state->succeeded;
return state->outcome;
}
// A full-access or permission-save request carries an opaque correlation token that the webview
@@ -545,7 +504,11 @@ void open_plugin_hub()
wxLaunchDefaultBrowser(wxString::FromUTF8(cloud_base_url + "/app/plugins/plugin-hub"));
}
bool install_local_plugin_package(const boost::filesystem::path& package_file, wxWindow* parent, wxString& message)
bool install_local_plugin_package(const boost::filesystem::path& package_file,
wxWindow* parent,
wxString& message,
std::optional<bool> overwrite,
std::optional<Ops::Refusal>* refused)
{
message.clear();
if (package_file.empty())
@@ -582,9 +545,22 @@ bool install_local_plugin_package(const boost::filesystem::path& package_file, w
return failed({});
}
if (existing_installation) {
if (existing_installation && overwrite == false) {
const std::string plugin_name = plugin_descriptor.name.empty() ? package_file.filename().string() : plugin_descriptor.name;
// The overwrite prompt's question is the reason.
const Ops::Refusal installed{Ops::RefusalKind::Precondition, "plugin_installed",
// TRN %s is a plugin's name.
L("Plugin \"%s\" is already installed.\n\n"
"Installing this package will overwrite the existing plugin."),
{plugin_name}};
message = installed.translated();
if (refused != nullptr)
*refused = installed;
return false;
}
if (existing_installation && !overwrite) {
const wxString plugin_name = from_u8(plugin_descriptor.name.empty() ? package_file.filename().string() : plugin_descriptor.name);
// Orca's own message dialog rather than a native box, which answer_dialog can't press on every platform.
// Orca's own message dialog rather than a native box, which dialog_answer can't press on every platform.
MessageDialog dialog(parent,
wxString::Format(_L("Plugin \"%s\" is already installed.\n\nInstalling this package will overwrite the existing plugin."),
plugin_name),
@@ -944,10 +920,7 @@ nlohmann::json PluginsDialog::build_plugins_payload() const
bool PluginsDialog::get_descriptor(const std::string& plugin_key, PluginDescriptor& descriptor) const
{
PluginManager& manager = PluginManager::instance();
if (manager.try_get_valid_plugin_descriptor(plugin_key, descriptor))
return true;
return manager.try_get_plugin_descriptor(plugin_key, descriptor) && descriptor.is_invalid_package();
return Ops::plugin_descriptor(plugin_key, descriptor);
}
void PluginsDialog::refresh_plugin_metadata_async(const wxString& title, const wxString& message, bool fetch_cloud)
@@ -1131,30 +1104,34 @@ void PluginsDialog::toggle_plugin(const std::string& plugin_key, bool enabled)
if (plugin_key.empty())
return;
BOOST_LOG_TRIVIAL(info) << "Toggle plugin request. plugin_key=" << plugin_key << " enabled=" << enabled;
PluginDescriptor row_data;
if (!get_descriptor(plugin_key, row_data)) {
Ops::SetPluginEnabledArgs args;
args.plugin = plugin_key;
args.enabled = enabled;
// Switching on a cloud plugin that is not installed downloads it behind this dialog's progress dialog.
args.run_download = [this, plugin_key](const std::function<Ops::Outcome<Ops::Done>()>& download) {
PluginDescriptor descriptor;
const wxString name = get_descriptor(plugin_key, descriptor) ? from_u8(descriptor.name) : from_u8(plugin_key);
return run_with_dialog_wait(download, _L("Downloading plugin"), _L("Downloading") + ": " + name);
};
const Ops::Outcome<Ops::PluginEnabled> done = Ops::set_plugin_enabled(args);
if (!done) {
const Ops::Refusal& refusal = done.refusal();
const std::string code = refusal.code;
if (code == "unauthorized_plugin") {
// The row shows why it stays off.
PluginManager::instance().set_plugin_error(plugin_key, into_u8(refusal.translated()));
show_status(refusal.translated(), "warn");
} else if (code == "not_unloaded" || code == "manifest_not_found") {
show_status(refusal.translated(), "warn");
} else if (code == "download_failed") {
show_status(refusal.translated(), "error");
}
// Otherwise the row shows how the plugin stands: gone, loading, or with its error.
send_plugins();
return;
}
PluginDialogItem dialog_item = build_plugin_dialog_item(row_data);
PluginAvailableActions available_actions = dialog_item.available_actions;
PluginManager& manager = PluginManager::instance();
if (!enabled) {
if (!manager.unload_plugin(plugin_key)) {
BOOST_LOG_TRIVIAL(error) << "Failed to unload plugin from Plugins dialog: " << plugin_key;
show_status(_L("Failed to unload plugin."), "warn");
send_plugins();
return;
}
BOOST_LOG_TRIVIAL(info) << "Plugin unloaded from Plugins dialog: " << plugin_key;
// A user-disabled plugin has no meaningful error state.
if (!manager.clear_plugin_error(plugin_key))
BOOST_LOG_TRIVIAL(warning) << "Failed to clear plugin error for " << plugin_key << " (failed to find)";
// A prior activation of this plugin is moot now; drop it so no stale "Activated" arrives later.
if (m_activating_plugin_key == plugin_key)
m_activating_plugin_key.clear();
@@ -1163,56 +1140,9 @@ void PluginsDialog::toggle_plugin(const std::string& plugin_key, bool enabled)
return;
}
if (!available_actions.can_toggle) {
if (dialog_item.unauthorized && available_actions.toggle_installs_cloud_plugin == false && row_data.has_local_package() == false) {
const std::string install_error = _u8L("Unauthorized cloud plugins cannot be installed.");
manager.set_plugin_error(plugin_key, install_error);
show_status(from_u8(install_error), "warn");
}
send_plugins();
return;
}
if (available_actions.toggle_installs_cloud_plugin) {
if (!install_cloud_plugin(row_data.plugin_key, row_data.version, from_u8(row_data.name))) {
BOOST_LOG_TRIVIAL(warning) << "Cloud plugin install was not completed for " << plugin_key;
send_plugins();
return;
}
BOOST_LOG_TRIVIAL(info) << "Cloud plugin installed locally from Plugins dialog: " << plugin_key;
// download_and_install_cloud_plugin already updated the descriptor, so no rescan is needed here.
if (!get_descriptor(plugin_key, row_data)) {
send_plugins();
return;
}
dialog_item = build_plugin_dialog_item(row_data);
if (dialog_item.has_error) {
send_plugins();
return;
}
}
if (manager.is_plugin_loaded(plugin_key)) {
send_plugins();
return;
}
PluginDescriptor valid_descriptor;
if (!manager.try_get_valid_plugin_descriptor(plugin_key, valid_descriptor)) {
show_status(_L("Plugin manifest was not found."), "warn");
send_plugins();
return;
}
if (manager.is_plugin_load_in_progress(plugin_key)) {
send_plugins();
return;
}
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": Starting plugin load from web dialog: " << plugin_key;
manager.load_plugin(plugin_key);
send_plugins();
if (done.value().change != Ops::PluginChange::LoadStarted)
return;
// Loading is asynchronous: show a pending message now; resolve_pending_activation() turns it into
// Activated/Failed once the loader's completion callback runs update_plugin_dialog_ui().
m_activating_plugin_key = plugin_key;
@@ -1227,30 +1157,16 @@ void PluginsDialog::toggle_plugin_capability(const std::string& plugin_key,
if (plugin_key.empty() || capability_name.empty() || type == PluginCapabilityType::Unknown)
return;
PluginDescriptor row_data;
if (!get_descriptor(plugin_key, row_data)) {
send_plugins();
return;
}
if (!PluginManager::instance().get_plugin_capability({type, capability_name, plugin_key}, /*only_enabled=*/false)) {
BOOST_LOG_TRIVIAL(warning) << "Cannot toggle missing plugin capability: " << plugin_key << " | " << capability_name;
send_plugins();
return;
}
PluginManager& manager = PluginManager::instance();
if (enabled) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": Enabling plugin capability: " << plugin_key << " | " << capability_name;
manager.set_capability_enabled({type, capability_name, plugin_key}, true);
} else {
// check if the capability is currently in use here.
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": Disabling plugin capability: " << plugin_key << " | " << capability_name;
manager.set_capability_enabled({type, capability_name, plugin_key}, false);
}
Ops::SetPluginEnabledArgs args;
args.plugin = plugin_key;
args.capability = capability_name;
args.capability_type = type;
args.enabled = enabled;
const Ops::Outcome<Ops::PluginEnabled> done = Ops::set_plugin_enabled(args);
send_plugins();
show_status(wxString::Format(enabled ? _L("Enabled \"%s\".") : _L("Disabled \"%s\"."), from_u8(capability_name)), "success");
// A plugin or capability that is gone leaves the rows to show it.
if (done)
show_status(wxString::Format(enabled ? _L("Enabled \"%s\".") : _L("Disabled \"%s\"."), from_u8(capability_name)), "success");
}
void PluginsDialog::handle_plugin_menu_action(const std::string& plugin_key, const std::string& action)
@@ -1333,31 +1249,13 @@ bool PluginsDialog::install_cloud_plugin(const std::string& plugin_key, const st
if (plugin_key.empty())
return false;
BOOST_LOG_TRIVIAL(info) << "Downloading cloud plugin. plugin_key=" << plugin_key << " name=" << into_u8(name);
std::string error;
bool downloaded = false;
try {
downloaded = run_with_dialog_wait(
[plugin_key, &error, version]() {
return PluginManager::instance().download_and_install_cloud_plugin(plugin_key, version, error);
},
_L("Downloading plugin"), _L("Downloading") + ": " + name);
} catch (const std::exception& ex) {
error = ex.what();
} catch (...) {
error = _u8L("Unknown error");
}
const Ops::Outcome<Ops::Done> downloaded = run_with_dialog_wait(
[plugin_key, version]() { return Ops::download_cloud_plugin(plugin_key, version); }, _L("Downloading plugin"),
_L("Downloading") + ": " + name);
if (!downloaded) {
BOOST_LOG_TRIVIAL(error) << "Cloud plugin download failed. plugin_key=" << plugin_key << " error=" << error;
PluginManager::instance().set_plugin_error(plugin_key, error);
show_status(error.empty() ? _L("Plugin download failed.") : from_u8(error), "error");
show_status(downloaded.refusal().translated(), "error");
return false;
}
BOOST_LOG_TRIVIAL(info) << "Cloud plugin downloaded successfully. plugin_key=" << plugin_key;
return true;
}
@@ -1554,30 +1452,21 @@ void PluginsDialog::delete_local_plugin(const PluginDescriptor& plugin)
if (rc != wxYES)
return;
auto state = std::make_shared<PluginOperationState>();
run_with_dialog(
[plugin_key = plugin.plugin_key, cloud_row = as_cloud_only_descriptor(plugin), state]() {
std::string error;
const bool succeeded = PluginManager::instance().delete_plugin(plugin_key, error);
// Keep the cloud row listed so the plugin stays reinstallable without waiting on a cloud fetch.
if (succeeded && cloud_row.is_cloud_plugin())
PluginManager::instance().update_cloud_metadata(std::vector<PluginDescriptor>{cloud_row});
store_plugin_operation_result(state, succeeded, std::move(error));
},
[this, state, plugin_name]() {
std::string error;
if (!take_plugin_operation_result(state, error)) {
show_status(error.empty() ? _L("Failed to delete plugin.") : from_u8(error), "error");
return;
}
const Ops::PluginUninstall plan{plugin.plugin_key, plugin.name, /*unsubscribe=*/false, plugin};
auto state = std::make_shared<PluginOperationState>();
run_with_dialog([plan, state]() { store_plugin_operation_result(state, Ops::uninstall_plugin(plan)); },
[this, state, plugin_name]() {
const std::optional<Ops::Outcome<Ops::Done>> deleted = take_plugin_operation_result(state);
if (!deleted || !*deleted) {
show_status(deleted ? deleted->refusal().translated() : _L("Failed to delete plugin."), "error");
return;
}
send_plugins();
// The package is gone only now; the unload callback rechecked the notices too early.
if (Plater* plater = wxGetApp().plater())
plater->refresh_missing_plugin_notifications();
show_status(wxString::Format(_L("Deleted \"%s\"."), plugin_name), "success");
},
_L("Deleting plugin"), _L("Deleting plugin..."));
send_plugins();
Ops::plugin_uninstalled();
show_status(wxString::Format(_L("Deleted \"%s\"."), plugin_name), "success");
},
_L("Deleting plugin"), _L("Deleting plugin..."));
}
void PluginsDialog::unsubscribe_cloud_plugin(const PluginDescriptor& plugin)
@@ -1591,27 +1480,22 @@ void PluginsDialog::unsubscribe_cloud_plugin(const PluginDescriptor& plugin)
if (rc != wxYES)
return;
auto state = std::make_shared<PluginOperationState>();
run_with_dialog(
[plugin_key = plugin.plugin_key, state]() {
std::string error;
const bool succeeded = PluginManager::instance().delete_and_unsubscribe_cloud_plugin(plugin_key, error);
store_plugin_operation_result(state, succeeded, std::move(error));
},
[this, state, plugin_name]() {
std::string error;
if (!take_plugin_operation_result(state, error)) {
show_status(error.empty() ? _L("Failed to unsubscribe plugin.") : from_u8(error), "error");
return;
}
const Ops::PluginUninstall plan{plugin.plugin_key, plugin.name, /*unsubscribe=*/true, plugin};
auto state = std::make_shared<PluginOperationState>();
run_with_dialog([plan, state]() { store_plugin_operation_result(state, Ops::uninstall_plugin(plan)); },
[this, state, plugin_name]() {
const std::optional<Ops::Outcome<Ops::Done>> unsubscribed = take_plugin_operation_result(state);
if (!unsubscribed || !*unsubscribed) {
show_status(unsubscribed ? unsubscribed->refusal().translated() : _L("Failed to unsubscribe plugin."),
"error");
return;
}
send_plugins();
// The package is gone only now; the unload callback rechecked the notices too early.
if (Plater* plater = wxGetApp().plater())
plater->refresh_missing_plugin_notifications();
show_status(wxString::Format(_L("Unsubscribed \"%s\"."), plugin_name), "success");
},
_L("Unsubscribing plugin"), _L("Deleting local files and unsubscribing plugin..."));
send_plugins();
Ops::plugin_uninstalled();
show_status(wxString::Format(_L("Unsubscribed \"%s\"."), plugin_name), "success");
},
_L("Unsubscribing plugin"), _L("Deleting local files and unsubscribing plugin..."));
}
void PluginsDialog::reload_local_plugin(const std::string& plugin_key, bool clear_cache)
@@ -1619,57 +1503,14 @@ void PluginsDialog::reload_local_plugin(const std::string& plugin_key, bool clea
if (plugin_key.empty())
return;
const bool was_loaded = PluginManager::instance().is_plugin_loaded(plugin_key);
std::pair<bool, std::string> reload_result{false, ""};
try {
reload_result = run_with_dialog_wait(
[plugin_key, was_loaded, clear_cache]() -> std::pair<bool, std::string> {
PluginManager& manager = PluginManager::instance();
boost::filesystem::path cache_dir;
if (clear_cache) {
PluginDescriptor descriptor;
if (!manager.try_get_plugin_descriptor(plugin_key, descriptor))
return {false, _u8L("Plugin not found.")};
boost::filesystem::path resolved_root;
std::string resolve_error;
if (!resolve_allowed_plugin_root(descriptor, {get_orca_plugins_dir()},
_u8L("Refusing to clear a plugin cache outside the local plugin directory."),
resolved_root, resolve_error))
return {false, resolve_error};
cache_dir = resolved_root / "__whl_extracted__";
}
if (!manager.unload_plugin(plugin_key))
return {false, _u8L("Failed to unload plugin.")};
if (clear_cache) {
boost::system::error_code ec;
boost::filesystem::remove_all(cache_dir, ec);
if (ec)
return {false, GUI::format(_u8L("Failed to clear plugin cache: %1%"), ec.message())};
}
manager.load_plugin(plugin_key, false);
std::string error;
if (!manager.wait_for_plugin_load(plugin_key, std::chrono::minutes(5), error) || !manager.is_plugin_loaded(plugin_key))
return {false, error.empty() ? _u8L("Plugin failed to load.") : error};
if (!was_loaded && !manager.unload_plugin(plugin_key))
return {false, _u8L("Plugin reloaded, but failed to restore the inactive state.")};
return {true, {}};
},
_L("Reloading plugin"), _L("Reloading plugin"));
} catch (const std::exception& ex) {
reload_result = {false, ex.what()};
} catch (...) {
reload_result = {false, _u8L("Unknown plugin reload error.")};
const Ops::Outcome<Ops::PluginReload> plan = Ops::plugin_reload_plan(plugin_key, clear_cache);
if (!plan) {
show_status(plan.refusal().translated(), "warn");
send_plugins();
return;
}
if (!reload_result.first) {
show_status(reload_result.second.empty() ? _L("Failed to reload plugin.") : from_u8(reload_result.second), "warn");
if (const Ops::Outcome<Ops::Done> reloaded = run_reload([plan = plan.value()]() { return Ops::reload_plugin(plan); }); !reloaded) {
show_status(reloaded.refusal().translated(), "warn");
send_plugins();
return;
}
@@ -1678,24 +1519,36 @@ void PluginsDialog::reload_local_plugin(const std::string& plugin_key, bool clea
show_status(wxString::Format(_L("Reloaded \"%s\"."), plugin_display_name(plugin_key)), "success");
}
Ops::Outcome<Ops::Done> PluginsDialog::run_reload(const std::function<Ops::Outcome<Ops::Done>()>& work)
{
Ops::Outcome<Ops::Done> reloaded = Ops::Done{};
try {
reloaded = run_with_dialog_wait(work, _L("Reloading plugin"), _L("Reloading plugin"));
} catch (const std::exception& ex) {
reloaded = Ops::Refusal{Ops::RefusalKind::Failed, "not_loaded", ex.what()};
} catch (...) {
reloaded = Ops::Refusal{Ops::RefusalKind::Failed, "not_loaded", L("Unknown plugin reload error.")};
}
// A failure with no text of its own.
if (!reloaded && reloaded.refusal().msgid.empty())
return Ops::Refusal{Ops::RefusalKind::Failed, reloaded.refusal().code, L("Failed to reload plugin.")};
return reloaded;
}
void PluginsDialog::reinstall_cloud_plugin(const PluginDescriptor& plugin)
{
const std::string plugin_key = plugin.plugin_key;
if (plugin_key.empty())
return;
PluginManager& manager = PluginManager::instance();
const bool was_loaded = PluginManager::instance().is_plugin_loaded(plugin_key);
const bool was_loaded = PluginManager::instance().is_plugin_loaded(plugin_key);
std::string error;
if (plugin.has_local_package()) {
if (!manager.delete_plugin(plugin_key, error)) {
show_status(error.empty() ? _L("Failed to delete plugin.") : from_u8(error), "error");
if (const Ops::Outcome<Ops::Done> removed = Ops::remove_plugin_package_for_reinstall(plugin); !removed) {
show_status(removed.refusal().translated(), "error");
send_plugins();
return;
}
manager.update_cloud_metadata(std::vector<PluginDescriptor>{as_cloud_only_descriptor(plugin)});
}
if (!install_cloud_plugin(plugin_key, plugin.version, from_u8(plugin.name))) {
@@ -1704,26 +1557,9 @@ void PluginsDialog::reinstall_cloud_plugin(const PluginDescriptor& plugin)
}
if (was_loaded) {
std::pair<bool, std::string> reload_result{false, ""};
try {
reload_result = run_with_dialog_wait(
[plugin_key]() -> std::pair<bool, std::string> {
PluginManager& manager = PluginManager::instance();
manager.load_plugin(plugin_key);
std::string error;
if (!manager.wait_for_plugin_load(plugin_key, std::chrono::minutes(5), error) || !manager.is_plugin_loaded(plugin_key))
return {false, error.empty() ? _u8L("Plugin failed to load.") : error};
return {true, {}};
},
_L("Reloading plugin"), _L("Reloading plugin"));
} catch (const std::exception& ex) {
reload_result = {false, ex.what()};
} catch (...) {
reload_result = {false, _u8L("Unknown plugin reload error.")};
}
if (!reload_result.first) {
show_status(reload_result.second.empty() ? _L("Failed to reload plugin.") : from_u8(reload_result.second), "warn");
if (const Ops::Outcome<Ops::Done> reloaded = run_reload([plugin_key]() { return Ops::load_plugin_and_wait(plugin_key); });
!reloaded) {
show_status(reloaded.refusal().translated(), "warn");
send_plugins();
return;
}