mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-03-21 17:34:57 -05:00
Show dialogs after OBS_FRONTEND_EVENT_FINISHED_LOADING is fired
This commit is contained in:
parent
b23a90557f
commit
37cbe65a85
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user