impr: Various web build improvements, API cleanup (#1541)

This commit is contained in:
Nik
2024-02-10 23:31:05 +01:00
committed by GitHub
parent 4b20e35fd2
commit bcbcb1f23c
43 changed files with 977 additions and 847 deletions

View File

@@ -331,18 +331,7 @@ namespace hex {
static Achievement& addAchievement(auto && ... args) {
auto newAchievement = std::make_unique<T>(std::forward<decltype(args)>(args)...);
const auto &category = newAchievement->getUnlocalizedCategory();
const auto &name = newAchievement->getUnlocalizedName();
auto [categoryIter, categoryInserted] = getAchievements().insert({ category, std::unordered_map<std::string, std::unique_ptr<Achievement>>{} });
auto &[categoryKey, achievements] = *categoryIter;
auto [achievementIter, achievementInserted] = achievements.insert({ name, std::move(newAchievement) });
auto &[achievementKey, achievement] = *achievementIter;
achievementAdded();
return *achievement;
return addAchievementImpl(std::move(newAchievement));
}
/**
@@ -371,7 +360,7 @@ namespace hex {
* @brief Returns all registered achievements
* @return All achievements
*/
static std::unordered_map<std::string, std::unordered_map<std::string, std::unique_ptr<Achievement>>>& getAchievements();
static const std::unordered_map<std::string, std::unordered_map<std::string, std::unique_ptr<Achievement>>>& getAchievements();
/**
* @brief Returns all achievement start nodes
@@ -379,14 +368,14 @@ namespace hex {
* @param rebuild Whether to rebuild the list of start nodes
* @return All achievement start nodes
*/
static std::unordered_map<std::string, std::vector<AchievementNode*>>& getAchievementStartNodes(bool rebuild = true);
static const std::unordered_map<std::string, std::vector<AchievementNode*>>& getAchievementStartNodes(bool rebuild = true);
/**
* @brief Returns all achievement nodes
* @param rebuild Whether to rebuild the list of nodes
* @return All achievement nodes
*/
static std::unordered_map<std::string, std::list<AchievementNode>>& getAchievementNodes(bool rebuild = true);
static const std::unordered_map<std::string, std::list<AchievementNode>>& getAchievementNodes(bool rebuild = true);
/**
* @brief Loads the progress of all achievements from the achievements save file
@@ -398,11 +387,6 @@ namespace hex {
*/
static void storeProgress();
/**
* @brief Removes all registered achievements from the tree
*/
static void clear();
/**
* @brief Removes all temporary achievements from the tree
*/
@@ -416,6 +400,8 @@ namespace hex {
private:
static void achievementAdded();
static Achievement& addAchievementImpl(std::unique_ptr<Achievement> &&newAchievement);
};
}

View File

@@ -272,9 +272,9 @@ namespace hex {
void store();
void clear();
std::vector<Category> &getSettings();
const std::vector<Category>& getSettings();
nlohmann::json& getSetting(const UnlocalizedString &unlocalizedCategory, const UnlocalizedString &unlocalizedName, const nlohmann::json &defaultValue);
nlohmann::json &getSettingsData();
const nlohmann::json& getSettingsData();
Widgets::Widget* add(const UnlocalizedString &unlocalizedCategory, const UnlocalizedString &unlocalizedSubCategory, const UnlocalizedString &unlocalizedName, std::unique_ptr<Widgets::Widget> &&widget);
@@ -352,8 +352,8 @@ namespace hex {
DisplayCallback displayCallback;
};
std::vector<Entry> &getEntries();
std::vector<Handler> &getHandlers();
const std::vector<Entry>& getEntries();
const std::vector<Handler>& getHandlers();
}
@@ -408,10 +408,10 @@ namespace hex {
VisualizerFunctionCallback callback;
};
std::map<std::string, Visualizer> &getVisualizers();
std::map<std::string, Visualizer> &getInlineVisualizers();
std::map<std::string, pl::api::PragmaHandler> &getPragmas();
std::vector<FunctionDefinition> &getFunctions();
const std::map<std::string, Visualizer>& getVisualizers();
const std::map<std::string, Visualizer>& getInlineVisualizers();
const std::map<std::string, pl::api::PragmaHandler>& getPragmas();
const std::vector<FunctionDefinition>& getFunctions();
}
@@ -504,7 +504,7 @@ namespace hex {
namespace impl {
void add(std::unique_ptr<View> &&view);
std::map<std::string, std::unique_ptr<View>> &getEntries();
const std::map<std::string, std::unique_ptr<View>>& getEntries();
}
@@ -535,12 +535,11 @@ namespace hex {
using Callback = std::function<void()>;
struct Entry {
std::string name;
UnlocalizedString unlocalizedName;
Callback function;
bool detached;
};
std::vector<Entry> &getEntries();
const std::vector<Entry>& getEntries();
}
@@ -576,7 +575,7 @@ namespace hex {
std::optional<EditingFunction> editingFunction;
};
std::vector<Entry> &getEntries();
const std::vector<Entry>& getEntries();
}
@@ -627,7 +626,7 @@ namespace hex {
void add(const Entry &entry);
std::vector<Entry> &getEntries();
const std::vector<Entry>& getEntries();
}
@@ -670,8 +669,8 @@ namespace hex {
namespace impl {
std::map<std::string, std::string> &getLanguages();
std::map<std::string, std::vector<LocalizationManager::LanguageDefinition>> &getLanguageDefinitions();
const std::map<std::string, std::string>& getLanguages();
const std::map<std::string, std::vector<LocalizationManager::LanguageDefinition>>& getLanguageDefinitions();
}
@@ -725,14 +724,16 @@ namespace hex {
constexpr static auto SeparatorValue = "$SEPARATOR$";
constexpr static auto SubMenuValue = "$SUBMENU$";
std::multimap<u32, MainMenuItem> &getMainMenuItems();
std::multimap<u32, MenuItem> &getMenuItems();
const std::multimap<u32, MainMenuItem>& getMainMenuItems();
std::vector<DrawCallback> &getWelcomeScreenEntries();
std::vector<DrawCallback> &getFooterItems();
std::vector<DrawCallback> &getToolbarItems();
std::vector<SidebarItem> &getSidebarItems();
std::vector<TitleBarButton> &getTitleBarButtons();
const std::multimap<u32, MenuItem>& getMenuItems();
std::multimap<u32, MenuItem>& getMenuItemsMutable();
const std::vector<DrawCallback>& getWelcomeScreenEntries();
const std::vector<DrawCallback>& getFooterItems();
const std::vector<DrawCallback>& getToolbarItems();
const std::vector<SidebarItem>& getSidebarItems();
const std::vector<TitleBarButton>& getTitlebarButtons();
}
@@ -901,10 +902,10 @@ namespace hex {
void addProviderName(const UnlocalizedString &unlocalizedName);
using ProviderCreationFunction = prv::Provider*(*)();
using ProviderCreationFunction = std::unique_ptr<prv::Provider>(*)();
void add(const std::string &typeName, ProviderCreationFunction creationFunction);
std::vector<std::string> &getEntries();
const std::vector<std::string>& getEntries();
}
@@ -917,8 +918,8 @@ namespace hex {
void add(bool addToList = true) {
auto typeName = T().getTypeName();
impl::add(typeName, [] -> prv::Provider* {
return new T();
impl::add(typeName, [] -> std::unique_ptr<prv::Provider> {
return std::make_unique<T>();
});
if (addToList)
@@ -938,7 +939,7 @@ namespace hex {
Callback callback;
};
std::vector<Entry> &getEntries();
const std::vector<Entry>& getEntries();
}
@@ -963,7 +964,7 @@ namespace hex {
Callback callback;
};
std::vector<Entry> &getEntries();
const std::vector<Entry>& getEntries();
}
@@ -1019,8 +1020,8 @@ namespace hex {
void addDataVisualizer(std::shared_ptr<DataVisualizer> &&visualizer);
std::vector<std::shared_ptr<DataVisualizer>> &getVisualizers();
std::vector<std::shared_ptr<MiniMapVisualizer>> &getMiniMapVisualizers();
const std::vector<std::shared_ptr<DataVisualizer>>& getVisualizers();
const std::vector<std::shared_ptr<MiniMapVisualizer>>& getMiniMapVisualizers();
}
@@ -1082,7 +1083,7 @@ namespace hex {
namespace impl {
std::vector<std::unique_ptr<Algorithm>> &getAlgorithms();
const std::vector<std::unique_ptr<Algorithm>>& getAlgorithms();
void addAlgorithm(std::unique_ptr<Algorithm> &&hash);
@@ -1119,7 +1120,7 @@ namespace hex {
[[nodiscard]] Hash *getType() { return m_type; }
[[nodiscard]] const Hash *getType() const { return m_type; }
[[nodiscard]] const std::string &getName() const { return m_name; }
[[nodiscard]] const std::string& getName() const { return m_name; }
const std::vector<u8>& get(const Region& region, prv::Provider *provider) {
if (m_cache.empty()) {
@@ -1147,7 +1148,7 @@ namespace hex {
[[nodiscard]] virtual nlohmann::json store() const = 0;
virtual void load(const nlohmann::json &json) = 0;
[[nodiscard]] const UnlocalizedString &getUnlocalizedName() const {
[[nodiscard]] const UnlocalizedString& getUnlocalizedName() const {
return m_unlocalizedName;
}
@@ -1162,7 +1163,7 @@ namespace hex {
namespace impl {
std::vector<std::unique_ptr<Hash>> &getHashes();
const std::vector<std::unique_ptr<Hash>>& getHashes();
void add(std::unique_ptr<Hash> &&hash);
@@ -1199,7 +1200,7 @@ namespace hex {
namespace impl {
using NetworkCallback = std::function<nlohmann::json(const nlohmann::json &)>;
std::map<std::string, NetworkCallback> &getNetworkEndpoints();
const std::map<std::string, NetworkCallback>& getNetworkEndpoints();
}
void registerNetworkEndpoint(const std::string &endpoint, const impl::NetworkCallback &callback);
@@ -1216,7 +1217,7 @@ namespace hex {
bool enabled;
};
std::map<std::string, Experiment> &getExperiments();
const std::map<std::string, Experiment>& getExperiments();
}
void addExperiment(
@@ -1240,7 +1241,7 @@ namespace hex {
Callback callback;
};
std::vector<ReportGenerator>& getGenerators();
const std::vector<ReportGenerator>& getGenerators();
}

View File

@@ -35,8 +35,8 @@ namespace hex {
Highlighting() = default;
Highlighting(Region region, color_t color);
[[nodiscard]] const Region &getRegion() const { return m_region; }
[[nodiscard]] const color_t &getColor() const { return m_color; }
[[nodiscard]] const Region& getRegion() const { return m_region; }
[[nodiscard]] const color_t& getColor() const { return m_color; }
private:
Region m_region = {};
@@ -48,9 +48,9 @@ namespace hex {
Tooltip() = default;
Tooltip(Region region, std::string value, color_t color);
[[nodiscard]] const Region &getRegion() const { return m_region; }
[[nodiscard]] const color_t &getColor() const { return m_color; }
[[nodiscard]] const std::string &getValue() const { return m_value; }
[[nodiscard]] const Region& getRegion() const { return m_region; }
[[nodiscard]] const color_t& getColor() const { return m_color; }
[[nodiscard]] const std::string& getValue() const { return m_value; }
private:
Region m_region = {};
@@ -70,12 +70,12 @@ namespace hex {
using HighlightingFunction = std::function<std::optional<color_t>(u64, const u8*, size_t, bool)>;
std::map<u32, Highlighting> &getBackgroundHighlights();
std::map<u32, HighlightingFunction> &getBackgroundHighlightingFunctions();
std::map<u32, Highlighting> &getForegroundHighlights();
std::map<u32, HighlightingFunction> &getForegroundHighlightingFunctions();
std::map<u32, Tooltip> &getTooltips();
std::map<u32, TooltipFunction> &getTooltipFunctions();
const std::map<u32, Highlighting>& getBackgroundHighlights();
const std::map<u32, HighlightingFunction>& getBackgroundHighlightingFunctions();
const std::map<u32, Highlighting>& getForegroundHighlights();
const std::map<u32, HighlightingFunction>& getForegroundHighlightingFunctions();
const std::map<u32, Tooltip>& getTooltips();
const std::map<u32, TooltipFunction>& getTooltipFunctions();
void setCurrentSelection(const std::optional<ProviderRegion> &region);
}
@@ -279,7 +279,7 @@ namespace hex {
* @brief Gets a list of all currently loaded data providers
* @return The currently loaded data providers
*/
const std::vector<prv::Provider *> &getProviders();
std::vector<prv::Provider*> getProviders();
/**
* @brief Sets the currently selected data provider
@@ -323,7 +323,7 @@ namespace hex {
* @param skipLoadInterface Whether to skip the provider's loading interface (see property documentation)
* @param select Whether to select the provider after adding it
*/
void add(prv::Provider *provider, bool skipLoadInterface = false, bool select = true);
void add(std::unique_ptr<prv::Provider> &&provider, bool skipLoadInterface = false, bool select = true);
/**
* @brief Creates a new provider and adds it to the list of providers
@@ -332,7 +332,7 @@ namespace hex {
*/
template<std::derived_from<prv::Provider> T>
void add(auto &&...args) {
add(new T(std::forward<decltype(args)>(args)...));
add(std::make_unique<T>(std::forward<decltype(args)>(args)...));
}
/**
@@ -497,7 +497,14 @@ namespace hex {
* @brief Gets the init arguments passed to ImHex from the splash screen
* @return Init arguments
*/
std::map<std::string, std::string> &getInitArguments();
const std::map<std::string, std::string>& getInitArguments();
/**
* @brief Gets a init arguments passed to ImHex from the splash screen
* @param key The key of the init argument
* @return Init argument
*/
std::string getInitArgument(const std::string &key);
/**
* @brief Sets if ImHex should follow the system theme
@@ -516,7 +523,7 @@ namespace hex {
* @brief Gets the currently set additional folder paths
* @return The currently set additional folder paths
*/
std::vector<std::filesystem::path> &getAdditionalFolderPaths();
const std::vector<std::filesystem::path>& getAdditionalFolderPaths();
/**
* @brief Sets the additional folder paths
@@ -529,7 +536,7 @@ namespace hex {
* @brief Gets the current GPU vendor
* @return The current GPU vendor
*/
const std::string &getGPUVendor();
const std::string& getGPUVendor();
/**
* @brief Checks if ImHex is running in portable mode
@@ -633,11 +640,12 @@ namespace hex {
namespace Messaging {
namespace impl {
using MessagingHandler = std::function<void(const std::vector<u8> &)>;
std::map<std::string, MessagingHandler> &getHandlers();
const std::map<std::string, MessagingHandler>& getHandlers();
void runHandler(const std::string &eventName, const std::vector<u8> &args);
}
/**
@@ -661,7 +669,7 @@ namespace hex {
namespace impl {
std::vector<Font>& getFonts();
const std::vector<Font>& getFonts();
void setCustomFontPath(const std::fs::path &path);
void setFontSize(float size);
@@ -687,7 +695,7 @@ namespace hex {
* @brief Gets the current custom font path
* @return The current custom font path
*/
std::filesystem::path &getCustomFontPath();
const std::filesystem::path& getCustomFontPath();
/**
* @brief Gets the current font size

View File

@@ -4,6 +4,8 @@
#include <string>
struct ImGuiTextBuffer;
namespace hex {
class LayoutManager {
@@ -13,6 +15,9 @@ namespace hex {
std::fs::path path;
};
using LoadCallback = std::function<void(std::string_view)>;
using StoreCallback = std::function<void(ImGuiTextBuffer *)>;
/**
* @brief Save the current layout
* @param name Name of the layout
@@ -76,6 +81,12 @@ namespace hex {
*/
static void closeAllViews();
static void registerLoadCallback(const LoadCallback &callback);
static void registerStoreCallback(const StoreCallback &callback);
static void onStore(ImGuiTextBuffer *buffer);
static void onLoad(std::string_view line);
private:
LayoutManager() = default;
};

View File

@@ -6,7 +6,9 @@
#include <string>
#include <wolv/io/fs.hpp>
#include <hex/helpers/logger.hpp>
#include <hex/helpers/auto_reset.hpp>
struct ImGuiContext;
@@ -109,11 +111,16 @@ namespace hex {
static void addPlugin(const std::string &name, PluginFunctions functions);
static std::list<Plugin> &getPlugins();
static std::vector<std::fs::path> &getPluginPaths();
static std::vector<std::fs::path> &getPluginLoadPaths();
static const std::list<Plugin>& getPlugins();
static const std::vector<std::fs::path>& getPluginPaths();
static const std::vector<std::fs::path>& getPluginLoadPaths();
static bool isPluginLoaded(const std::fs::path &path);
private:
static std::list<Plugin>& getPluginsMutable();
static AutoReset<std::vector<std::fs::path>> s_pluginPaths, s_pluginLoadPaths;
};
}

View File

@@ -93,30 +93,26 @@ namespace hex {
*
* @param handler The handler to register
*/
static void registerHandler(const Handler &handler) {
getHandlers().push_back(handler);
}
static void registerHandler(const Handler &handler);
/**
* @brief Register a handler for storing and loading per-provider data from a project file
*
* @param handler The handler to register
*/
static void registerPerProviderHandler(const ProviderHandler &handler) {
getProviderHandlers().push_back(handler);
}
static void registerPerProviderHandler(const ProviderHandler &handler);
/**
* @brief Get the list of registered handlers
* @return List of registered handlers
*/
static std::vector<Handler>& getHandlers();
static const std::vector<Handler>& getHandlers();
/**
* @brief Get the list of registered per-provider handlers
* @return List of registered per-provider handlers
*/
static std::vector<ProviderHandler>& getProviderHandlers();
static const std::vector<ProviderHandler>& getProviderHandlers();
private:
ProjectFile() = default;

View File

@@ -176,7 +176,7 @@ namespace hex {
static size_t getRunningTaskCount();
static size_t getRunningBackgroundTaskCount();
static std::list<std::shared_ptr<Task>> &getRunningTasks();
static const std::list<std::shared_ptr<Task>>& getRunningTasks();
static void runDeferredCalls();
private:

View File

@@ -78,8 +78,8 @@ namespace hex {
StyleMap styleMap;
};
static std::map<std::string, ThemeHandler>& getThemeHandlers();
static std::map<std::string, StyleHandler>& getStyleHandlers();
static const std::map<std::string, ThemeHandler>& getThemeHandlers();
static const std::map<std::string, StyleHandler>& getStyleHandlers();
private:
ThemeManager() = default;