code: Migrate ui::handler to new dynamic loader

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2023-05-14 06:50:27 +02:00 committed by Xaymar
parent acf4dde783
commit b4e6bb57e4
3 changed files with 25 additions and 29 deletions

View File

@ -212,11 +212,6 @@ MODULE_EXPORT bool obs_module_load(void)
#endif
}
// Frontend
#ifdef ENABLE_FRONTEND
streamfx::ui::handler::initialize();
#endif
DLOG_INFO("Loaded Version %s", STREAMFX_VERSION_STRING);
return true;
} catch (std::exception const& ex) {
@ -233,11 +228,6 @@ MODULE_EXPORT void obs_module_unload(void)
try {
DLOG_INFO("Unloading Version %s", STREAMFX_VERSION_STRING);
// Frontend
#ifdef ENABLE_FRONTEND
streamfx::ui::handler::finalize();
#endif
// Transitions
{
#ifdef ENABLE_TRANSITION_SHADER

View File

@ -257,21 +257,18 @@ void streamfx::ui::handler::on_action_about(bool checked)
_about_dialog->show();
}
static std::shared_ptr<streamfx::ui::handler> _handler_singleton;
void streamfx::ui::handler::initialize()
std::shared_ptr<streamfx::ui::handler> streamfx::ui::handler::instance()
{
_handler_singleton = std::make_shared<streamfx::ui::handler>();
}
static std::weak_ptr<streamfx::ui::handler> winst;
static std::mutex mtx;
void streamfx::ui::handler::finalize()
{
_handler_singleton.reset();
}
std::shared_ptr<streamfx::ui::handler> streamfx::ui::handler::get()
{
return _handler_singleton;
std::unique_lock<decltype(mtx)> lock(mtx);
auto instance = winst.lock();
if (!instance) {
instance = std::shared_ptr<streamfx::ui::handler>(new streamfx::ui::handler());
winst = instance;
}
return instance;
}
streamfx::ui::translator::translator(QObject* parent) {}
@ -294,3 +291,14 @@ QString streamfx::ui::translator::translate(const char* context, const char* sou
}
return QString();
}
static std::shared_ptr<streamfx::ui::handler> loader_instance;
static auto loader = streamfx::loader(
[]() { // Initalizer
loader_instance = streamfx::ui::handler::instance();
},
[]() { // Finalizer
loader_instance.reset();
},
streamfx::loader_priority::LOWEST); // Must be loaded after all other functionality.

View File

@ -36,8 +36,10 @@ namespace streamfx::ui {
std::shared_ptr<streamfx::ui::updater> _updater;
#endif
public:
private:
handler();
public:
~handler();
bool have_shown_about_streamfx(bool shown = false);
@ -63,11 +65,7 @@ namespace streamfx::ui {
void on_action_about(bool);
public /* Singleton */:
static void initialize();
static void finalize();
static std::shared_ptr<ui::handler> get();
static std::shared_ptr<ui::handler> instance();
};
class translator : public QTranslator {