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

View file

@ -257,21 +257,18 @@ void streamfx::ui::handler::on_action_about(bool checked)
_about_dialog->show(); _about_dialog->show();
} }
static std::shared_ptr<streamfx::ui::handler> _handler_singleton; std::shared_ptr<streamfx::ui::handler> streamfx::ui::handler::instance()
void streamfx::ui::handler::initialize()
{ {
_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() std::unique_lock<decltype(mtx)> lock(mtx);
{ auto instance = winst.lock();
_handler_singleton.reset(); if (!instance) {
} instance = std::shared_ptr<streamfx::ui::handler>(new streamfx::ui::handler());
winst = instance;
std::shared_ptr<streamfx::ui::handler> streamfx::ui::handler::get() }
{ return instance;
return _handler_singleton;
} }
streamfx::ui::translator::translator(QObject* parent) {} streamfx::ui::translator::translator(QObject* parent) {}
@ -294,3 +291,14 @@ QString streamfx::ui::translator::translate(const char* context, const char* sou
} }
return QString(); 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; std::shared_ptr<streamfx::ui::updater> _updater;
#endif #endif
public: private:
handler(); handler();
public:
~handler(); ~handler();
bool have_shown_about_streamfx(bool shown = false); bool have_shown_about_streamfx(bool shown = false);
@ -63,11 +65,7 @@ namespace streamfx::ui {
void on_action_about(bool); void on_action_about(bool);
public /* Singleton */: public /* Singleton */:
static void initialize(); static std::shared_ptr<ui::handler> instance();
static void finalize();
static std::shared_ptr<ui::handler> get();
}; };
class translator : public QTranslator { class translator : public QTranslator {