ui/obs-browser-widget: Pull in browser-panel.hpp to fix MacOS

MacOS complains that QCefWidget is an undefined type, while all other compilers are fine.
This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2023-03-13 09:17:20 +01:00
parent 0fa12f1029
commit 9735e1bcec
4 changed files with 94 additions and 29 deletions

View File

@ -1003,6 +1003,9 @@ endif()
if(REQUIRE_OBS_FRONTEND_API AND obs-frontend-api_FOUND) if(REQUIRE_OBS_FRONTEND_API AND obs-frontend-api_FOUND)
list(APPEND PROJECT_LIBRARIES OBS::obs-frontend-api) list(APPEND PROJECT_LIBRARIES OBS::obs-frontend-api)
list(APPEND PROJECT_UI_SOURCE
"source/obs/browser/obs-browser-panel.hpp"
)
endif() endif()
if(REQUIRE_QT) if(REQUIRE_QT)

View File

@ -0,0 +1,66 @@
// AUTOGENERATED COPYRIGHT HEADER START
// Copyright (C) 2023 Michael Fabian 'Xaymar' Dirks <info@xaymar.com>
// AUTOGENERATED COPYRIGHT HEADER END
#pragma once
#include "warning-disable.hpp"
#include <QObject>
#include <QString>
#include <QWidget>
#include <functional>
#include <string>
#include <util/util.hpp>
#include "warning-enable.hpp"
namespace streamfx::obs {
struct QCefCookieManager {
virtual ~QCefCookieManager() {}
virtual bool DeleteCookies(const std::string& url, const std::string& name) = 0;
virtual bool SetStoragePath(const std::string& storage_path, bool persist_session_cookies = false) = 0;
virtual bool FlushStore() = 0;
typedef std::function<void(bool)> cookie_exists_cb;
virtual void CheckForCookie(const std::string& site, const std::string& cookie, cookie_exists_cb callback) = 0;
};
class QCefWidget : public QWidget {
Q_OBJECT
protected:
inline QCefWidget(QWidget* parent) : QWidget(parent) {}
public:
virtual void setURL(const std::string& url) = 0;
virtual void setStartupScript(const std::string& script) = 0;
virtual void allowAllPopups(bool allow) = 0;
virtual void closeBrowser() = 0;
virtual void reloadPage() = 0;
signals:
void titleChanged(const QString& title);
void urlChanged(const QString& url);
};
struct QCef {
virtual ~QCef() {}
virtual bool init_browser(void) = 0;
virtual bool initialized(void) = 0;
virtual bool wait_for_browser_init(void) = 0;
virtual QCefWidget* create_widget(QWidget* parent, const std::string& url,
QCefCookieManager* cookie_manager = nullptr) = 0;
virtual QCefCookieManager* create_cookie_manager(const std::string& storage_path,
bool persist_session_cookies = false) = 0;
virtual BPtr<char> get_cookie_path(const std::string& storage_path) = 0;
virtual void add_popup_whitelist_url(const std::string& url, QObject* obj) = 0;
virtual void add_force_popup_url(const std::string& url, QObject* obj) = 0;
};
} // namespace streamfx::obs

View File

@ -8,8 +8,6 @@
#include <QGridLayout> #include <QGridLayout>
#include <QLabel> #include <QLabel>
#include "../third-party/obs-studio/plugins/obs-browser/panel/browser-panel.hpp"
#include <mutex> #include <mutex>
#include <stdexcept> #include <stdexcept>
#ifdef D_PLATFORM_LINUX #ifdef D_PLATFORM_LINUX
@ -24,7 +22,7 @@ streamfx::ui::obs_browser_cef::obs_browser_cef()
{ {
// Load the "obs-browser" module. // Load the "obs-browser" module.
_module = util::library::load(obs_get_module("obs-browser")); _module = util::library::load(obs_get_module("obs-browser"));
auto fn = reinterpret_cast<QCef* (*)(void)>(_module->load_symbol("obs_browser_create_qcef")); auto fn = reinterpret_cast<streamfx::obs::QCef* (*)(void)>(_module->load_symbol("obs_browser_create_qcef"));
if (!fn) { if (!fn) {
throw std::runtime_error("Failed to load obs-browser module."); throw std::runtime_error("Failed to load obs-browser module.");
} }
@ -34,26 +32,25 @@ streamfx::ui::obs_browser_cef::obs_browser_cef()
if (!_cef) { if (!_cef) {
throw std::runtime_error("Failed to create or get QCef instance."); throw std::runtime_error("Failed to create or get QCef instance.");
} }
reinterpret_cast<QCef*>(_cef)->init_browser(); _cef->init_browser();
reinterpret_cast<QCef*>(_cef)->wait_for_browser_init(); _cef->wait_for_browser_init();
// Create a generic Cookie manager for widgets. // Create a generic Cookie manager for widgets.
_cookie = _cookie = _cef->create_cookie_manager(streamfx::config_file_path("cookies").u8string(), false);
reinterpret_cast<QCef*>(_cef)->create_cookie_manager(streamfx::config_file_path("cookies").u8string(), false);
} }
streamfx::ui::obs_browser_cef::~obs_browser_cef() streamfx::ui::obs_browser_cef::~obs_browser_cef()
{ {
delete reinterpret_cast<QCefCookieManager*>(_cookie); delete _cookie;
delete reinterpret_cast<QCef*>(_cef); delete _cef;
} }
void* streamfx::ui::obs_browser_cef::cef() streamfx::obs::QCef* streamfx::ui::obs_browser_cef::cef()
{ {
return _cef; return _cef;
} }
void* streamfx::ui::obs_browser_cef::cookie_manager() streamfx::obs::QCefCookieManager* streamfx::ui::obs_browser_cef::cookie_manager()
{ {
return _cookie; return _cookie;
} }
@ -82,13 +79,11 @@ streamfx::ui::obs_browser_widget::obs_browser_widget(QUrl url, QWidget* parent)
// Create CEF Widget // Create CEF Widget
_cef = obs_browser_cef::instance(); _cef = obs_browser_cef::instance();
_widget = reinterpret_cast<QCef*>(_cef->cef()) _widget = _cef->cef()->create_widget(this, url.toString().toStdString(), _cef->cookie_manager());
->create_widget(this, url.toString().toStdString(),
reinterpret_cast<QCefCookieManager*>(_cef->cookie_manager()));
if (!_widget) { if (!_widget) {
throw std::runtime_error("Failed to create CEF Widget."); throw std::runtime_error("Failed to create CEF Widget.");
} }
dynamic_cast<QCefWidget*>(_widget)->allowAllPopups(false); _widget->allowAllPopups(false);
_widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); _widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
layout->addWidget(_widget, 0, 0); layout->addWidget(_widget, 0, 0);
@ -101,24 +96,24 @@ streamfx::ui::obs_browser_widget::obs_browser_widget(QUrl url, QWidget* parent)
streamfx::ui::obs_browser_widget::~obs_browser_widget() {} streamfx::ui::obs_browser_widget::~obs_browser_widget() {}
QWidget* streamfx::ui::obs_browser_widget::cefwidget() streamfx::obs::QCefWidget* streamfx::ui::obs_browser_widget::cefwidget()
{ {
return _widget; return _widget;
} }
void streamfx::ui::obs_browser_widget::set_url(QUrl url) void streamfx::ui::obs_browser_widget::set_url(QUrl url)
{ {
dynamic_cast<QCefWidget*>(_widget)->setURL(url.toString().toStdString()); _widget->setURL(url.toString().toStdString());
} }
bool streamfx::ui::obs_browser_widget::is_available() bool streamfx::ui::obs_browser_widget::is_available()
{ {
#ifdef D_PLATFORM_LINUX #ifdef D_PLATFORM_LINUX
const char env_key[] = "XDG_SESSION_TYPE"; const char env_key[] = "XDG_SESSION_TYPE";
const char wayland[] = "wayland"; const char wayland[] = "wayland";
#ifdef __STDC_LIB_EXT1__ #ifdef __STDC_LIB_EXT1__
char env_value[2048]; char env_value[2048];
size_t env_value_len = sizeof(env_value); size_t env_value_len = sizeof(env_value);
if (getenv_s(&env_value_len, env_value, sizeof(env_key), env_key) == 0) { if (getenv_s(&env_value_len, env_value, sizeof(env_key), env_key) == 0) {
if (sizeof(wayland) == env_value_len) { if (sizeof(wayland) == env_value_len) {
if (strncmp(wayland, env_value, sizeof(wayland)) == 0) { if (strncmp(wayland, env_value, sizeof(wayland)) == 0) {
@ -126,12 +121,12 @@ bool streamfx::ui::obs_browser_widget::is_available()
} }
} }
} }
#else #else
const char* env_value = getenv(env_key); const char* env_value = getenv(env_key);
if (strncmp(env_value, wayland, sizeof(wayland)) == 0) { if (strncmp(env_value, wayland, sizeof(wayland)) == 0) {
return false; return false;
} }
#endif #endif
#endif #endif
return true; return true;
} }

View File

@ -10,14 +10,15 @@
#include <memory> #include <memory>
#include "warning-enable.hpp" #include "warning-enable.hpp"
#include "obs/browser/obs-browser-panel.hpp"
#include "util/util-library.hpp" #include "util/util-library.hpp"
namespace streamfx::ui { namespace streamfx::ui {
class obs_browser_cef { class obs_browser_cef {
std::shared_ptr<::streamfx::util::library> _module; std::shared_ptr<::streamfx::util::library> _module;
void* _cef; streamfx::obs::QCef* _cef;
void* _cookie; streamfx::obs::QCefCookieManager* _cookie;
private: private:
obs_browser_cef(); obs_browser_cef();
@ -25,9 +26,9 @@ namespace streamfx::ui {
public: public:
~obs_browser_cef(); ~obs_browser_cef();
void* cef(); streamfx::obs::QCef* cef();
void* cookie_manager(); streamfx::obs::QCefCookieManager* cookie_manager();
public: // Singleton public: // Singleton
static std::shared_ptr<obs_browser_cef> instance(); static std::shared_ptr<obs_browser_cef> instance();
@ -38,7 +39,7 @@ namespace streamfx::ui {
private: private:
std::shared_ptr<obs_browser_cef> _cef; std::shared_ptr<obs_browser_cef> _cef;
QWidget* _widget; streamfx::obs::QCefWidget* _widget;
public: public:
obs_browser_widget(QUrl url, QWidget* parent = nullptr); obs_browser_widget(QUrl url, QWidget* parent = nullptr);
@ -46,7 +47,7 @@ namespace streamfx::ui {
void set_url(QUrl url); void set_url(QUrl url);
QWidget* cefwidget(); streamfx::obs::QCefWidget* cefwidget();
public: public:
static bool is_available(); static bool is_available();