plugins: fix config value usage in init

This commit is contained in:
vaxerski 2023-07-10 14:13:23 +02:00
parent da7ea2b33d
commit 0c61a1530f
4 changed files with 19 additions and 2 deletions

View File

@ -77,8 +77,12 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
static const auto METHODS = HyprlandAPI::findFunctionsByName(PHANDLE, "processMouseDownNormal");
g_pMouseDownHook = HyprlandAPI::createFunctionHook(PHANDLE, METHODS[0].address, (void*)&hkProcessMouseDownNormal);
static auto* const PBORDERCOLOR = HyprlandAPI::getConfigValue(PHANDLE, "plugin:example:border_color");
// fancy notifications
HyprlandAPI::addNotificationV2(PHANDLE, {{"text", "Example hint"}, {"time", (uint64_t)10000}, {"color", CColor(0.2, 0.2, 0.9, 1.0)}, {"icon", ICON_HINT}});
HyprlandAPI::addNotificationV2(
PHANDLE,
{{"text", "Example hint, color " + std::to_string(PBORDERCOLOR->intValue)}, {"time", (uint64_t)10000}, {"color", CColor{PBORDERCOLOR->intValue}}, {"icon", ICON_HINT}});
// Enable our hooks
g_pFocusHook->hook();

View File

@ -371,8 +371,10 @@ void CConfigManager::configSetValueSafe(const std::string& COMMAND, const std::s
CONFIGENTRY = &it->second;
}
if (!CONFIGENTRY)
if (!CONFIGENTRY) {
m_vFailedPluginConfigValues.emplace_back(std::make_pair<>(COMMAND, VALUE));
return; // silent ignore
}
} else {
CONFIGENTRY = &configValues.at(COMMAND);
}
@ -1458,6 +1460,7 @@ void CConfigManager::loadConfigLoadVars() {
setDefaultAnimationVars(); // reset anims
m_vDeclaredPlugins.clear();
m_dLayerRules.clear();
m_vFailedPluginConfigValues.clear();
// paths
configPaths.clear();
@ -2179,6 +2182,11 @@ void CConfigManager::addPluginConfigVar(HANDLE handle, const std::string& name,
}
(*CONFIGMAPIT->second)[name] = value;
if (const auto IT = std::find_if(m_vFailedPluginConfigValues.begin(), m_vFailedPluginConfigValues.end(), [&](const auto& other) { return other.first == name; });
IT != m_vFailedPluginConfigValues.end()) {
configSetValueSafe(IT->first, IT->second);
}
}
void CConfigManager::removePluginConfig(HANDLE handle) {

View File

@ -252,6 +252,8 @@ class CConfigManager {
std::vector<std::pair<std::string, std::string>> environmentVariables;
std::vector<std::pair<std::string, std::string>> m_vFailedPluginConfigValues; // for plugin values of unloaded plugins
// internal methods
void setDefaultVars();
void setDefaultAnimationVars();

View File

@ -112,6 +112,9 @@ void CPluginSystem::unloadPlugin(const CPlugin* plugin, bool eject) {
Debug::log(LOG, " [PluginSystem] Plugin %s unloaded.", plugin->name.c_str());
std::erase_if(m_vLoadedPlugins, [&](const auto& other) { return other->m_pHandle == plugin->m_pHandle; });
// reload config to fix some stuf like e.g. unloadedPluginVars
g_pConfigManager->m_bForceReload = true;
}
void CPluginSystem::unloadAllPlugins() {