mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-11-23 20:05:11 +00:00
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:
parent
0fa12f1029
commit
9735e1bcec
4 changed files with 94 additions and 29 deletions
|
@ -1003,6 +1003,9 @@ endif()
|
|||
|
||||
if(REQUIRE_OBS_FRONTEND_API AND obs-frontend-api_FOUND)
|
||||
list(APPEND PROJECT_LIBRARIES OBS::obs-frontend-api)
|
||||
list(APPEND PROJECT_UI_SOURCE
|
||||
"source/obs/browser/obs-browser-panel.hpp"
|
||||
)
|
||||
endif()
|
||||
|
||||
if(REQUIRE_QT)
|
||||
|
|
66
source/obs/browser/obs-browser-panel.hpp
Normal file
66
source/obs/browser/obs-browser-panel.hpp
Normal 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
|
|
@ -8,8 +8,6 @@
|
|||
#include <QGridLayout>
|
||||
#include <QLabel>
|
||||
|
||||
#include "../third-party/obs-studio/plugins/obs-browser/panel/browser-panel.hpp"
|
||||
|
||||
#include <mutex>
|
||||
#include <stdexcept>
|
||||
#ifdef D_PLATFORM_LINUX
|
||||
|
@ -24,7 +22,7 @@ streamfx::ui::obs_browser_cef::obs_browser_cef()
|
|||
{
|
||||
// Load the "obs-browser" module.
|
||||
_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) {
|
||||
throw std::runtime_error("Failed to load obs-browser module.");
|
||||
}
|
||||
|
@ -34,26 +32,25 @@ streamfx::ui::obs_browser_cef::obs_browser_cef()
|
|||
if (!_cef) {
|
||||
throw std::runtime_error("Failed to create or get QCef instance.");
|
||||
}
|
||||
reinterpret_cast<QCef*>(_cef)->init_browser();
|
||||
reinterpret_cast<QCef*>(_cef)->wait_for_browser_init();
|
||||
_cef->init_browser();
|
||||
_cef->wait_for_browser_init();
|
||||
|
||||
// Create a generic Cookie manager for widgets.
|
||||
_cookie =
|
||||
reinterpret_cast<QCef*>(_cef)->create_cookie_manager(streamfx::config_file_path("cookies").u8string(), false);
|
||||
_cookie = _cef->create_cookie_manager(streamfx::config_file_path("cookies").u8string(), false);
|
||||
}
|
||||
|
||||
streamfx::ui::obs_browser_cef::~obs_browser_cef()
|
||||
{
|
||||
delete reinterpret_cast<QCefCookieManager*>(_cookie);
|
||||
delete reinterpret_cast<QCef*>(_cef);
|
||||
delete _cookie;
|
||||
delete _cef;
|
||||
}
|
||||
|
||||
void* streamfx::ui::obs_browser_cef::cef()
|
||||
streamfx::obs::QCef* streamfx::ui::obs_browser_cef::cef()
|
||||
{
|
||||
return _cef;
|
||||
}
|
||||
|
||||
void* streamfx::ui::obs_browser_cef::cookie_manager()
|
||||
streamfx::obs::QCefCookieManager* streamfx::ui::obs_browser_cef::cookie_manager()
|
||||
{
|
||||
return _cookie;
|
||||
}
|
||||
|
@ -82,13 +79,11 @@ streamfx::ui::obs_browser_widget::obs_browser_widget(QUrl url, QWidget* parent)
|
|||
|
||||
// Create CEF Widget
|
||||
_cef = obs_browser_cef::instance();
|
||||
_widget = reinterpret_cast<QCef*>(_cef->cef())
|
||||
->create_widget(this, url.toString().toStdString(),
|
||||
reinterpret_cast<QCefCookieManager*>(_cef->cookie_manager()));
|
||||
_widget = _cef->cef()->create_widget(this, url.toString().toStdString(), _cef->cookie_manager());
|
||||
if (!_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);
|
||||
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() {}
|
||||
|
||||
QWidget* streamfx::ui::obs_browser_widget::cefwidget()
|
||||
streamfx::obs::QCefWidget* streamfx::ui::obs_browser_widget::cefwidget()
|
||||
{
|
||||
return _widget;
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
#ifdef D_PLATFORM_LINUX
|
||||
#ifdef D_PLATFORM_LINUX
|
||||
const char env_key[] = "XDG_SESSION_TYPE";
|
||||
const char wayland[] = "wayland";
|
||||
#ifdef __STDC_LIB_EXT1__
|
||||
char env_value[2048];
|
||||
size_t env_value_len = sizeof(env_value);
|
||||
char env_value[2048];
|
||||
size_t env_value_len = sizeof(env_value);
|
||||
if (getenv_s(&env_value_len, env_value, sizeof(env_key), env_key) == 0) {
|
||||
if (sizeof(wayland) == env_value_len) {
|
||||
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);
|
||||
if (strncmp(env_value, wayland, sizeof(wayland)) == 0) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -10,14 +10,15 @@
|
|||
#include <memory>
|
||||
#include "warning-enable.hpp"
|
||||
|
||||
#include "obs/browser/obs-browser-panel.hpp"
|
||||
#include "util/util-library.hpp"
|
||||
|
||||
namespace streamfx::ui {
|
||||
class obs_browser_cef {
|
||||
std::shared_ptr<::streamfx::util::library> _module;
|
||||
|
||||
void* _cef;
|
||||
void* _cookie;
|
||||
streamfx::obs::QCef* _cef;
|
||||
streamfx::obs::QCefCookieManager* _cookie;
|
||||
|
||||
private:
|
||||
obs_browser_cef();
|
||||
|
@ -25,9 +26,9 @@ namespace streamfx::ui {
|
|||
public:
|
||||
~obs_browser_cef();
|
||||
|
||||
void* cef();
|
||||
streamfx::obs::QCef* cef();
|
||||
|
||||
void* cookie_manager();
|
||||
streamfx::obs::QCefCookieManager* cookie_manager();
|
||||
|
||||
public: // Singleton
|
||||
static std::shared_ptr<obs_browser_cef> instance();
|
||||
|
@ -38,7 +39,7 @@ namespace streamfx::ui {
|
|||
|
||||
private:
|
||||
std::shared_ptr<obs_browser_cef> _cef;
|
||||
QWidget* _widget;
|
||||
streamfx::obs::QCefWidget* _widget;
|
||||
|
||||
public:
|
||||
obs_browser_widget(QUrl url, QWidget* parent = nullptr);
|
||||
|
@ -46,7 +47,7 @@ namespace streamfx::ui {
|
|||
|
||||
void set_url(QUrl url);
|
||||
|
||||
QWidget* cefwidget();
|
||||
streamfx::obs::QCefWidget* cefwidget();
|
||||
|
||||
public:
|
||||
static bool is_available();
|
||||
|
|
Loading…
Reference in a new issue