1
0
mirror of synced 2025-02-20 04:01:01 +01:00

impr: Display background scripts in about page

This commit is contained in:
WerWolv 2024-05-08 22:30:53 +02:00
parent 89f360d1a7
commit 8a3739ee1c
5 changed files with 35 additions and 13 deletions

View File

@ -131,8 +131,8 @@ void* PluginSubCommandsFunctionHelper<T>::getSubCommands() {
std::vector<hex::SubCommand> g_subCommands
#define IMHEX_FEATURE_ENABLED(feature) WOLV_TOKEN_CONCAT(WOLV_TOKEN_CONCAT(WOLV_TOKEN_CONCAT(IMHEX_PLUGIN_, IMHEX_PLUGIN_NAME), _FEATURE_), feature)
#define IMHEX_PLUGIN_FEATURES() IMHEX_PLUGIN_FEATURES_IMPL()
#define IMHEX_PLUGIN_FEATURES_IMPL() \
#define IMHEX_DEFINE_PLUGIN_FEATURES() IMHEX_DEFINE_PLUGIN_FEATURES_IMPL()
#define IMHEX_DEFINE_PLUGIN_FEATURES_IMPL() \
extern std::vector<hex::Feature> g_features; \
template<> \
struct PluginFeatureFunctionHelper<PluginFunctionHelperInstantiation> { \
@ -142,3 +142,5 @@ void* PluginSubCommandsFunctionHelper<T>::getSubCommands() {
return &g_features; \
} \
std::vector<hex::Feature> g_features
#define IMHEX_PLUGIN_FEATURES g_features

View File

@ -14,7 +14,7 @@ namespace hex::plugin::decompress {
using namespace hex;
using namespace hex::plugin::decompress;
IMHEX_PLUGIN_FEATURES() {
IMHEX_DEFINE_PLUGIN_FEATURES() {
{ "bzip2 Support", IMHEX_FEATURE_ENABLED(BZIP2) },
{ "zlib Support", IMHEX_FEATURE_ENABLED(ZLIB) },
{ "LZMA Support", IMHEX_FEATURE_ENABLED(LIBLZMA) },

View File

@ -8,6 +8,7 @@ namespace hex::script::loader {
struct Script {
std::string name;
bool background;
std::function<void()> entryPoint;
};
@ -19,8 +20,8 @@ namespace hex::script::loader {
virtual bool initialize() = 0;
virtual bool loadAll() = 0;
void addScript(std::string name, std::function<void()> entryPoint) {
m_scripts.emplace_back(std::move(name), std::move(entryPoint));
void addScript(std::string name, bool background, std::function<void()> entryPoint) {
m_scripts.emplace_back(std::move(name), background, std::move(entryPoint));
}
const auto& getScripts() const {

View File

@ -262,13 +262,15 @@ namespace hex::script::loader {
continue;
if (m_methodExists("Main", scriptPath)) {
this->addScript(entry.path().stem().string(), [this, scriptPath] {
this->addScript(entry.path().stem().string(), false, [this, scriptPath] {
hex::unused(m_runMethod("Main", false, scriptPath));
});
}
if (m_methodExists("OnLoad", scriptPath)) {
hex::unused(m_runMethod("OnLoad", true, scriptPath));
this->addScript(entry.path().stem().string(), true, [this, scriptPath] {
hex::unused(m_runMethod("OnLoad", true, scriptPath));
});
}
}
}

View File

@ -1,3 +1,4 @@
#include <fonts/codicons_font.h>
#include <hex/plugin.hpp>
#include <hex/api/content_registry.hpp>
#include <hex/api/task_manager.hpp>
@ -20,6 +21,8 @@ using ScriptLoaders = std::tuple<
#endif
>;
IMHEX_DEFINE_PLUGIN_FEATURES(){ };
namespace {
ScriptLoaders s_loaders;
@ -32,17 +35,29 @@ namespace {
}
std::vector<const Script*> loadAllScripts() {
std::vector<const Script*> plugins;
std::vector<const Script*> scripts;
try {
std::apply([&plugins](auto&&... args) {
(loadScript(plugins, args), ...);
std::apply([&scripts](auto&&... args) {
(loadScript(scripts, args), ...);
}, s_loaders);
} catch (const std::exception &e) {
log::error("Error when loading scripts: {}", e.what());
}
return plugins;
{
std::vector<hex::Feature> features;
for (const auto &script : scripts) {
if (!script->background)
continue;
features.emplace_back(script->name, true);
}
IMHEX_PLUGIN_FEATURES = features;
}
return scripts;
}
void initializeLoader(u32 &count, auto &loader) {
@ -74,7 +89,7 @@ namespace {
hex::ContentRegistry::Interface::addMenuItemSubMenu({ "hex.builtin.menu.extras" }, 5000, [] {
static bool menuJustOpened = true;
if (ImGui::BeginMenu("hex.script_loader.menu.run_script"_lang)) {
if (ImGui::BeginMenuEx("hex.script_loader.menu.run_script"_lang, ICON_VS_LIBRARY)) {
if (menuJustOpened) {
menuJustOpened = false;
if (!updaterTask.isRunning()) {
@ -91,7 +106,9 @@ namespace {
}
for (const auto &script : scripts) {
const auto &[name, entryPoint] = *script;
const auto &[name, background, entryPoint] = *script;
if (background)
continue;
if (ImGui::MenuItem(name.c_str())) {
runnerTask = TaskManager::createTask("Running script...", TaskManager::NoProgress, [entryPoint](auto&) {