Show dialogs after OBS_FRONTEND_EVENT_FINISHED_LOADING is fired
Some checks failed
debian-build / build (push) Has been cancelled
Push to master / Check Formatting 🔍 (push) Has been cancelled
Push to master / Build Project 🧱 (push) Has been cancelled
Push to master / Create Release 🛫 (push) Has been cancelled

This commit is contained in:
WarmUpTill 2026-02-23 17:18:15 +01:00 committed by WarmUpTill
parent 4966802f14
commit ff98ec36d6
5 changed files with 57 additions and 49 deletions

View File

@ -54,31 +54,18 @@ void AskForBackup(obs_data_t *settings)
// or crashing.
// Therefore, we ask the user whether they want to back up the settings
// asynchronously.
//
// On macOS, an additional QTimer::singleShot wrapper is required for
// this to work correctly.
auto json = obs_data_get_json(settings);
static QString jsonQString = json ? json : "";
static const auto askForBackupWrapper = [](void *) {
#ifdef __APPLE__
QTimer::singleShot(0,
static_cast<QMainWindow *>(
obs_frontend_get_main_window()),
[]() {
#endif
showBackupDialogs(jsonQString);
#ifdef __APPLE__
});
#endif
showBackupDialogs(jsonQString);
};
std::thread t([]() {
AddFinishedLoadingStep([]() {
obs_queue_task(OBS_TASK_UI, askForBackupWrapper, nullptr,
false);
});
t.detach();
}
void BackupSettingsOfCurrentVersion()

View File

@ -126,26 +126,13 @@ bool ShouldSkipPluginStartOnUncleanShutdown()
// or crashing.
// Therefore, we ask the user whether they want to start the plugin
// asynchronously.
//
// On macOS, an additional QTimer::singleShot wrapper is required for
// this to work correctly.
static const auto showDialogWrapper = [](void *) {
#ifdef __APPLE__
QTimer::singleShot(0,
static_cast<QMainWindow *>(
obs_frontend_get_main_window()),
[]() {
#endif
askForStartupSkip();
#ifdef __APPLE__
});
#endif
askForStartupSkip();
};
std::thread t([]() {
AddFinishedLoadingStep([]() {
obs_queue_task(OBS_TASK_UI, showDialogWrapper, nullptr, false);
});
t.detach();
return true;
}

View File

@ -3,12 +3,42 @@
#include "macro-signals.hpp"
#include "switcher-data.hpp"
#include "obs-frontend-api.h"
namespace advss {
static std::mutex initMutex;
static std::mutex postLoadMutex;
static std::mutex finishLoadMutex;
static std::mutex mutex;
static bool setup();
static bool setupDonw = setup();
bool loadingFinished = false;
static std::vector<std::function<void()>> &getFinishLoadSteps();
static bool setup()
{
static auto handleEvent = [](enum obs_frontend_event event, void *) {
switch (event) {
case OBS_FRONTEND_EVENT_FINISHED_LOADING: {
std::lock_guard<std::mutex> lock(finishLoadMutex);
for (const auto &step : getFinishLoadSteps()) {
step();
}
getFinishLoadSteps().clear();
loadingFinished = true;
break;
}
default:
break;
};
};
obs_frontend_add_event_callback(handleEvent, nullptr);
return true;
}
static std::vector<std::function<void()>> &getPluginInitSteps()
{
static std::vector<std::function<void()>> steps;
@ -63,6 +93,12 @@ static std::vector<std::function<void()>> &getPostLoadSteps()
return steps;
}
static std::vector<std::function<void()>> &getFinishLoadSteps()
{
static std::vector<std::function<void()>> steps;
return steps;
}
void SavePluginSettings(obs_data_t *obj)
{
GetSwitcher()->SaveSettings(obj);
@ -178,6 +214,16 @@ void RunIntervalResetSteps()
}
}
void AddFinishedLoadingStep(std::function<void()> step)
{
std::lock_guard<std::mutex> lock(finishLoadMutex);
if (loadingFinished) {
return;
}
getFinishLoadSteps().emplace_back(step);
}
void AddStartStep(std::function<void()> step)
{
std::lock_guard<std::mutex> lock(mutex);

View File

@ -34,6 +34,9 @@ void RunStartSteps();
void RunStopSteps();
void RunIntervalResetSteps();
// Steps are executed after OBS_FRONTEND_EVENT_FINISHED_LOADING is fired
EXPORT void AddFinishedLoadingStep(std::function<void()>);
enum class NoMatchBehavior { NO_SWITCH = 0, SWITCH = 1, RANDOM_SWITCH = 2 };
EXPORT void SetPluginNoMatchBehavior(NoMatchBehavior);
EXPORT NoMatchBehavior GetPluginNoMatchBehavior();

View File

@ -28,7 +28,7 @@ static bool setup()
AddSetupTabCallback("twitchConnectionTab",
TwitchConnectionsTable::Create, setupTab);
static const auto showInvalidWarnings = []() {
static const auto showInvalidWarnings = [](void *) {
const auto invalidTokens = getInvalidTokens();
for (const auto &token : invalidTokens) {
QueueUITask(
@ -47,24 +47,9 @@ static bool setup()
// or crashing.
// Therefore, we ask the user whether they want to update their Twitch
// connections asynchronously.
//
// On macOS, an additional QTimer::singleShot wrapper is required for
// this to work correctly.
AddLoadStep([](obs_data_t *) {
AddPostLoadStep([]() {
#ifdef __APPLE__
QTimer::singleShot(
0,
static_cast<QMainWindow *>(
obs_frontend_get_main_window()),
[]() {
#endif
showInvalidWarnings();
#ifdef __APPLE__
});
#endif
});
AddFinishedLoadingStep([]() {
obs_queue_task(OBS_TASK_UI, showInvalidWarnings, nullptr,
false);
});
return true;