Move DBus init to overlay_params so it can be enabled/disabled on the fly from a single place

This commit is contained in:
jackun 2020-04-10 22:33:27 +03:00
parent d81dc7936a
commit e5a256bfc0
No known key found for this signature in database
GPG Key ID: 119DB3F1D05A9ED3
5 changed files with 35 additions and 33 deletions

View File

@ -449,7 +449,7 @@ void dbus_manager::init()
if (m_inited)
return;
if (!m_dbus_ldr.Load("libdbus-1.so.3"))
if (!m_dbus_ldr.IsLoaded() && !m_dbus_ldr.Load("libdbus-1.so.3"))
throw std::runtime_error("Could not load libdbus-1.so.3");
m_dbus_ldr.error_init(&m_error);
@ -465,17 +465,24 @@ void dbus_manager::init()
m_inited = true;
}
void dbus_manager::deinit()
{
if (!m_inited)
return;
// unreference system bus connection instead of closing it
if (m_dbus_conn) {
disconnect_from_signals();
m_dbus_ldr.connection_unref(m_dbus_conn);
m_dbus_conn = nullptr;
}
m_dbus_ldr.error_free(&m_error);
m_inited = false;
}
dbus_manager::~dbus_manager()
{
if (m_inited) {
// unreference system bus connection instead of closing it
if (m_dbus_conn) {
disconnect_from_signals();
m_dbus_ldr.connection_unref(m_dbus_conn);
m_dbus_conn = nullptr;
}
m_dbus_ldr.error_free(&m_error);
}
deinit();
}
void dbus_manager::connect_to_signals()

View File

@ -80,6 +80,7 @@ namespace dbusmgr {
~dbus_manager();
void init();
void deinit();
void add_callback(CBENUM type, callback_func func);
void connect_to_signals();
void disconnect_from_signals();

View File

@ -31,17 +31,6 @@ void imgui_init()
init_system_info();
cfg_inited = true;
init_cpu_stats(params);
#ifdef HAVE_DBUS
if (params.enabled[OVERLAY_PARAM_ENABLED_media_player]) {
try {
dbusmgr::dbus_mgr.init();
get_spotify_metadata(dbusmgr::dbus_mgr, spotify);
} catch (std::runtime_error& e) {
std::cerr << "Failed to get initial Spotify metadata: " << e.what() << std::endl;
}
}
#endif
}
}} // namespaces

View File

@ -2531,17 +2531,6 @@ static VkResult overlay_CreateInstance(
init_cpu_stats(instance_data->params);
#ifdef HAVE_DBUS
if (instance_data->params.enabled[OVERLAY_PARAM_ENABLED_media_player]) {
try {
dbusmgr::dbus_mgr.init();
get_spotify_metadata(dbusmgr::dbus_mgr, spotify);
} catch (std::runtime_error& e) {
std::cerr << "Failed to get initial Spotify metadata: " << e.what() << std::endl;
}
}
#endif
// Adjust height for DXVK/VKD3D version number
if (engineName == "DXVK" || engineName == "VKD3D"){
if (instance_data->params.font_size){

View File

@ -33,6 +33,7 @@
#include "overlay_params.h"
#include "overlay.h"
#include "config.h"
#include "dbus_info.h"
#include "mesa/util/os_socket.h"
@ -457,4 +458,19 @@ parse_overlay_config(struct overlay_params *params,
// set frametime limit
if (params->fps_limit >= 0)
fps_limit_stats.targetFrameTime = int64_t(1000000000.0 / params->fps_limit);
}
#ifdef HAVE_DBUS
if (params->enabled[OVERLAY_PARAM_ENABLED_media_player]) {
try {
dbusmgr::dbus_mgr.init();
get_spotify_metadata(dbusmgr::dbus_mgr, spotify);
} catch (std::runtime_error& e) {
std::cerr << "Failed to get initial Spotify metadata: " << e.what() << std::endl;
}
} else {
dbusmgr::dbus_mgr.deinit();
spotify.valid = false;
}
#endif
}