Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI: Split out Whats New dialog to fix shutdown crash on Linux #11422

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions UI/cmake/ui-windows.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,6 @@ target_sources(
window-projector.hpp
window-remux.cpp
window-remux.hpp
window-whats-new.cpp
window-whats-new.hpp
)
35 changes: 6 additions & 29 deletions UI/window-basic-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
#include "window-youtube-actions.hpp"
#include "youtube-api-wrappers.hpp"
#endif
#include "window-whats-new.hpp"
#include "context-bar-controls.hpp"
#include "obs-proxy-style.hpp"
#include "display-helpers.hpp"
Expand Down Expand Up @@ -128,6 +129,8 @@ void DestroyPanelCookieManager();

namespace {

QPointer<OBSWhatsNew> obsWhatsNew;

template<typename OBSRef> struct SignalContainer {
OBSRef ref;
vector<shared_ptr<OBSSignal>> handlers;
Expand Down Expand Up @@ -2544,37 +2547,11 @@ void OBSBasic::ShowWhatsNew(const QString &url)
if (closing)
return;

std::string info_url = QT_TO_UTF8(url);

QDialog *dlg = new QDialog(this);
dlg->setAttribute(Qt::WA_DeleteOnClose, true);
dlg->setWindowTitle("What's New");
dlg->resize(700, 600);

Qt::WindowFlags flags = dlg->windowFlags();
Qt::WindowFlags helpFlag = Qt::WindowContextHelpButtonHint;
dlg->setWindowFlags(flags & (~helpFlag));

QCefWidget *cefWidget = cef->create_widget(nullptr, info_url);
if (!cefWidget) {
return;
if (obsWhatsNew) {
obsWhatsNew->close();
}

connect(cefWidget, &QCefWidget::titleChanged, dlg, &QDialog::setWindowTitle);

QPushButton *close = new QPushButton(QTStr("Close"));
connect(close, &QAbstractButton::clicked, dlg, &QDialog::accept);

QHBoxLayout *bottomLayout = new QHBoxLayout();
bottomLayout->addStretch();
bottomLayout->addWidget(close);
bottomLayout->addStretch();

QVBoxLayout *topLayout = new QVBoxLayout(dlg);
topLayout->addWidget(cefWidget);
topLayout->addLayout(bottomLayout);

dlg->show();
obsWhatsNew = new OBSWhatsNew(this, QT_TO_UTF8(url));
#else
UNUSED_PARAMETER(url);
#endif
Expand Down
74 changes: 74 additions & 0 deletions UI/window-whats-new.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include "moc_window-whats-new.cpp"

#include <QPushButton>
#include <QHBoxLayout>
#include <QVBoxLayout>

#include "window-basic-main.hpp"

#ifdef BROWSER_AVAILABLE
#include <browser-panel.hpp>
extern QCef *cef;
#endif

/* ------------------------------------------------------------------------- */

OBSWhatsNew::OBSWhatsNew(QWidget *parent, const std::string &url) : QDialog(parent)
{
#ifdef BROWSER_AVAILABLE
if (!cef) {
return;
}

setWindowTitle("What's New");
setAttribute(Qt::WA_DeleteOnClose, true);
resize(700, 600);

Qt::WindowFlags flags = windowFlags();
Qt::WindowFlags helpFlag = Qt::WindowContextHelpButtonHint;
setWindowFlags(flags & (~helpFlag));

OBSBasic::InitBrowserPanelSafeBlock();

cefWidget = cef->create_widget(nullptr, url);
if (!cefWidget) {
return;
}

connect(cefWidget, &QCefWidget::titleChanged, this, &OBSWhatsNew::setWindowTitle);

QPushButton *close = new QPushButton(QTStr("Close"));
connect(close, &QAbstractButton::clicked, this, &QDialog::accept);

QHBoxLayout *bottomLayout = new QHBoxLayout();
bottomLayout->addStretch();
bottomLayout->addWidget(close);
bottomLayout->addStretch();

QVBoxLayout *topLayout = new QVBoxLayout(this);
topLayout->addWidget(cefWidget);
topLayout->addLayout(bottomLayout);

show();
#else
UNUSED_PARAMETER(url);
#endif
}

OBSWhatsNew::~OBSWhatsNew() {}

void OBSWhatsNew::reject()
{
#ifdef BROWSER_AVAILABLE
delete cefWidget;
#endif
QDialog::reject();
}

void OBSWhatsNew::accept()
{
#ifdef BROWSER_AVAILABLE
delete cefWidget;
#endif
QDialog::accept();
}
20 changes: 20 additions & 0 deletions UI/window-whats-new.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include <QPointer>
#include <QDialog>
#include <string>

class QCefWidget;

class OBSWhatsNew : public QDialog {
Q_OBJECT

QCefWidget *cefWidget = nullptr;

public:
OBSWhatsNew(QWidget *parent, const std::string &url);
~OBSWhatsNew();

virtual void reject() override;
virtual void accept() override;
};
Loading