Skip to content

Commit 142353d

Browse files
cg2121Warchamp7
authored andcommitted
frontend: Make OBSAbout self contained
This makes it so OBSAbout isn't tangled with OBSBasic.
1 parent 407944a commit 142353d

File tree

6 files changed

+35
-31
lines changed

6 files changed

+35
-31
lines changed

frontend/dialogs/OBSAbout.cpp

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
#include "OBSAbout.hpp"
2-
3-
#include <widgets/OBSBasic.hpp>
2+
#include <OBSApp.hpp>
43
#include <utility/RemoteTextThread.hpp>
4+
#include <utility/platform.hpp>
55

66
#include <qt-wrappers.hpp>
77

88
#include <json11.hpp>
99

1010
#include "moc_OBSAbout.cpp"
1111

12+
namespace {
13+
QString patronJson;
14+
} // namespace
15+
1216
using namespace json11;
1317

1418
extern bool steam;
@@ -62,30 +66,40 @@ OBSAbout::OBSAbout(QWidget *parent) : QDialog(parent), ui(new Ui::OBSAbout)
6266
connect(ui->authors, &ClickableLabel::clicked, this, &OBSAbout::ShowAuthors);
6367
connect(ui->license, &ClickableLabel::clicked, this, &OBSAbout::ShowLicense);
6468

65-
QPointer<OBSAbout> about(this);
66-
67-
OBSBasic *main = OBSBasic::Get();
68-
if (main->patronJson.empty() && !main->patronJsonThread) {
69+
if (patronJson.isEmpty()) {
6970
RemoteTextThread *thread =
7071
new RemoteTextThread("https://obsproject.com/patreon/about-box.json", "application/json");
71-
QObject::connect(thread, &RemoteTextThread::Result, main, &OBSBasic::UpdatePatronJson);
72-
QObject::connect(thread, &RemoteTextThread::Result, this, &OBSAbout::ShowAbout);
73-
main->patronJsonThread.reset(thread);
72+
connect(thread, &RemoteTextThread::Result, this, &OBSAbout::updatePatronJson);
73+
patronJsonThread.reset(thread);
7474
thread->start();
7575
} else {
7676
ShowAbout();
7777
}
7878
}
7979

80-
void OBSAbout::ShowAbout()
80+
OBSAbout::~OBSAbout()
8181
{
82-
OBSBasic *main = OBSBasic::Get();
82+
if (patronJsonThread && patronJsonThread->isRunning())
83+
patronJsonThread->wait();
84+
}
8385

84-
if (main->patronJson.empty())
86+
void OBSAbout::updatePatronJson(const QString &text, const QString &error)
87+
{
88+
if (!error.isEmpty())
89+
return;
90+
91+
patronJson = text;
92+
93+
ShowAbout();
94+
}
95+
96+
void OBSAbout::ShowAbout()
97+
{
98+
if (patronJson.isEmpty())
8599
return;
86100

87101
std::string error;
88-
Json json = Json::parse(main->patronJson, error);
102+
Json json = Json::parse(patronJson.toStdString(), error);
89103
const Json::array &patrons = json.array_items();
90104
QString text;
91105

frontend/dialogs/OBSAbout.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,19 @@
77
class OBSAbout : public QDialog {
88
Q_OBJECT
99

10+
private:
11+
QScopedPointer<QThread> patronJsonThread;
12+
1013
public:
1114
explicit OBSAbout(QWidget *parent = 0);
15+
~OBSAbout();
1216

1317
std::unique_ptr<Ui::OBSAbout> ui;
1418

1519
private slots:
1620
void ShowAbout();
1721
void ShowAuthors();
1822
void ShowLicense();
23+
24+
void updatePatronJson(const QString &text, const QString &error);
1925
};

frontend/widgets/OBSBasic.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,9 +1397,6 @@ void OBSBasic::applicationShutdown() noexcept
13971397
if (updateCheckThread && updateCheckThread->isRunning())
13981398
updateCheckThread->wait();
13991399

1400-
if (patronJsonThread && patronJsonThread->isRunning())
1401-
patronJsonThread->wait();
1402-
14031400
delete screenshotData;
14041401
delete previewProjector;
14051402
delete studioProgramProjector;
@@ -2085,14 +2082,6 @@ OBSBasic *OBSBasic::Get()
20852082
return reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
20862083
}
20872084

2088-
void OBSBasic::UpdatePatronJson(const QString &text, const QString &error)
2089-
{
2090-
if (!error.isEmpty())
2091-
return;
2092-
2093-
patronJson = QT_TO_UTF8(text);
2094-
}
2095-
20962085
void OBSBasic::SetDisplayAffinity(QWindow *window)
20972086
{
20982087
if (!SetDisplayAffinitySupported())

frontend/widgets/OBSBasic.hpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ class OBSBasic : public OBSMainWindow {
217217
Q_PROPERTY(QIcon audioProcessOutputIcon READ GetAudioProcessOutputIcon WRITE SetAudioProcessOutputIcon
218218
DESIGNABLE true)
219219

220-
friend class OBSAbout;
221220
friend class OBSBasicPreview;
222221
friend class OBSBasicStatusBar;
223222
friend class OBSBasicSourceSelect;
@@ -272,9 +271,6 @@ class OBSBasic : public OBSMainWindow {
272271

273272
ConfigFile activeConfiguration;
274273

275-
QScopedPointer<QThread> patronJsonThread;
276-
std::string patronJson;
277-
278274
std::unique_ptr<Ui::OBSBasic> ui;
279275

280276
void OnEvent(enum obs_frontend_event event);
@@ -302,7 +298,6 @@ class OBSBasic : public OBSMainWindow {
302298

303299
public slots:
304300
void close();
305-
void UpdatePatronJson(const QString &text, const QString &error);
306301
void UpdateEditMenu();
307302
void applicationShutdown() noexcept;
308303

0 commit comments

Comments
 (0)