From 6da151f7d7b37c0893d786259ce0adc547741d7a Mon Sep 17 00:00:00 2001 From: WarmUpTill <19472752+WarmUpTill@users.noreply.github.com> Date: Thu, 7 May 2026 19:34:20 +0200 Subject: [PATCH] Fix variable tab not listing variables on startup --- lib/utils/plugin-state-helpers.cpp | 30 ++++++++++++++++++++++++++++ lib/utils/plugin-state-helpers.hpp | 2 ++ lib/variables/variable-tab.cpp | 1 - lib/variables/variable.cpp | 4 ++-- tests/stubs/plugin-state-helpers.cpp | 2 ++ 5 files changed, 36 insertions(+), 3 deletions(-) diff --git a/lib/utils/plugin-state-helpers.cpp b/lib/utils/plugin-state-helpers.cpp index fa4fce75..75ca49b7 100644 --- a/lib/utils/plugin-state-helpers.cpp +++ b/lib/utils/plugin-state-helpers.cpp @@ -75,6 +75,18 @@ static std::vector> &getStopSteps() return steps; } +static std::vector> &getEarlySaveSteps() +{ + static std::vector> steps; + return steps; +} + +static std::vector> &getEarlyLoadSteps() +{ + static std::vector> steps; + return steps; +} + static std::vector> &getSaveSteps() { static std::vector> steps; @@ -109,6 +121,18 @@ void LoadPluginSettings(obs_data_t *obj) GetSwitcher()->LoadSettings(obj); } +void AddEarlySaveStep(std::function step) +{ + std::lock_guard lock(mutex); + getEarlySaveSteps().emplace_back(step); +} + +void AddEarlyLoadStep(std::function step) +{ + std::lock_guard lock(mutex); + getEarlyLoadSteps().emplace_back(step); +} + void AddSaveStep(std::function step) { std::lock_guard lock(mutex); @@ -136,6 +160,9 @@ void AddIntervalResetStep(std::function step) void RunSaveSteps(obs_data_t *obj) { std::lock_guard lock(mutex); + for (const auto &func : getEarlySaveSteps()) { + func(obj); + } for (const auto &func : getSaveSteps()) { func(obj); } @@ -144,6 +171,9 @@ void RunSaveSteps(obs_data_t *obj) void RunLoadSteps(obs_data_t *obj) { std::lock_guard lock(mutex); + for (const auto &func : getEarlyLoadSteps()) { + func(obj); + } for (const auto &func : getLoadSteps()) { func(obj); } diff --git a/lib/utils/plugin-state-helpers.hpp b/lib/utils/plugin-state-helpers.hpp index 1df274d3..0ee36edc 100644 --- a/lib/utils/plugin-state-helpers.hpp +++ b/lib/utils/plugin-state-helpers.hpp @@ -8,6 +8,8 @@ namespace advss { void SavePluginSettings(obs_data_t *); EXPORT void LoadPluginSettings(obs_data_t *); +void AddEarlySaveStep(std::function); +void AddEarlyLoadStep(std::function); EXPORT void AddSaveStep(std::function); EXPORT void AddLoadStep(std::function); EXPORT void AddPostLoadStep(std::function); diff --git a/lib/variables/variable-tab.cpp b/lib/variables/variable-tab.cpp index 3a4ed292..84f3d534 100644 --- a/lib/variables/variable-tab.cpp +++ b/lib/variables/variable-tab.cpp @@ -63,7 +63,6 @@ static void load(obs_data_t *data) { tabSettings.Load(data, "tabSettings"); dockSettings.Load(data, "dockSettings"); - enableDock(obs_data_get_bool(data, "addVariablesDock")); } diff --git a/lib/variables/variable.cpp b/lib/variables/variable.cpp index 61b3ec8d..9ae25c07 100644 --- a/lib/variables/variable.cpp +++ b/lib/variables/variable.cpp @@ -20,8 +20,8 @@ static std::chrono::high_resolution_clock::time_point lastVariableChange{}; static bool setup() { - AddSaveStep(SaveVariables); - AddLoadStep(LoadVariables); + AddEarlySaveStep(SaveVariables); + AddEarlyLoadStep(LoadVariables); AddPluginCleanupStep([]() { variables.clear(); }); return true; } diff --git a/tests/stubs/plugin-state-helpers.cpp b/tests/stubs/plugin-state-helpers.cpp index eb94fb8b..b037ba56 100644 --- a/tests/stubs/plugin-state-helpers.cpp +++ b/tests/stubs/plugin-state-helpers.cpp @@ -4,6 +4,8 @@ namespace advss { void SavePluginSettings(obs_data_t *) {} void LoadPluginSettings(obs_data_t *) {} +void AddEarlySaveStep(std::function) {} +void AddEarlyLoadStep(std::function) {} void AddSaveStep(std::function) {} void AddLoadStep(std::function) {} void AddPostLoadStep(std::function) {}