mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-11-17 23:25:15 -06:00
Prepare built-in OAuth client for YouTube connections
This commit is contained in:
@@ -64,6 +64,7 @@ target_sources(
|
||||
macro-action-youtube.hpp
|
||||
macro-condition-youtube.cpp
|
||||
macro-condition-youtube.hpp
|
||||
youtube-builtin-client.cpp
|
||||
youtube-connection.cpp
|
||||
youtube-connection.hpp
|
||||
youtube-helpers.cpp
|
||||
@@ -73,6 +74,20 @@ target_sources(
|
||||
youtube-tab.cpp
|
||||
youtube-tab.hpp)
|
||||
|
||||
# Without these the users have to provide the OAuth credentials of their own
|
||||
# Google Cloud project
|
||||
set(ADVSS_YOUTUBE_CLIENT_ID
|
||||
"$ENV{ADVSS_YOUTUBE_CLIENT_ID}"
|
||||
CACHE STRING "OAuth client ID of the built-in YouTube client")
|
||||
set(ADVSS_YOUTUBE_CLIENT_SECRET
|
||||
"$ENV{ADVSS_YOUTUBE_CLIENT_SECRET}"
|
||||
CACHE STRING "OAuth client secret of the built-in YouTube client")
|
||||
mark_as_advanced(ADVSS_YOUTUBE_CLIENT_ID ADVSS_YOUTUBE_CLIENT_SECRET)
|
||||
configure_file(youtube-client-config.hpp.in
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/youtube-client-config.hpp" @ONLY)
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
|
||||
setup_advss_plugin(${PROJECT_NAME})
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "")
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE "${CPP_HTTPLIB_DIR}/"
|
||||
|
||||
16
plugins/youtube/youtube-builtin-client.cpp
Normal file
16
plugins/youtube/youtube-builtin-client.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include "youtube-oauth.hpp"
|
||||
#include "youtube-client-config.hpp"
|
||||
|
||||
namespace advss {
|
||||
|
||||
std::optional<OAuthClientConfig> GetBuiltInClientConfig()
|
||||
{
|
||||
static const std::string clientId = ADVSS_YOUTUBE_CLIENT_ID;
|
||||
static const std::string clientSecret = ADVSS_YOUTUBE_CLIENT_SECRET;
|
||||
if (clientId.empty() || clientSecret.empty()) {
|
||||
return {};
|
||||
}
|
||||
return OAuthClientConfig{clientId, clientSecret};
|
||||
}
|
||||
|
||||
} // namespace advss
|
||||
4
plugins/youtube/youtube-client-config.hpp.in
Normal file
4
plugins/youtube/youtube-client-config.hpp.in
Normal file
@@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
#define ADVSS_YOUTUBE_CLIENT_ID "@ADVSS_YOUTUBE_CLIENT_ID@"
|
||||
#define ADVSS_YOUTUBE_CLIENT_SECRET "@ADVSS_YOUTUBE_CLIENT_SECRET@"
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "youtube-tab.hpp"
|
||||
|
||||
#include <help-icon.hpp>
|
||||
#include <layout-helpers.hpp>
|
||||
#include <log-helper.hpp>
|
||||
#include <macro-export-extensions.hpp>
|
||||
#include <obs-module-helper.hpp>
|
||||
@@ -444,6 +445,9 @@ YouTubeConnectionSettingsDialog::YouTubeConnectionSettingsDialog(
|
||||
"AdvSceneSwitcher.youtubeConnection.add",
|
||||
"AdvSceneSwitcher.youtubeConnection.nameNotAvailable", false,
|
||||
parent),
|
||||
_useOwnClient(new QCheckBox(obs_module_text(
|
||||
"AdvSceneSwitcher.youtubeConnection.useOwnClient"))),
|
||||
_layout(new QGridLayout()),
|
||||
_clientId(new QLineEdit(
|
||||
QString::fromStdString(settings._customClientId))),
|
||||
_clientSecret(new QLineEdit(
|
||||
@@ -459,7 +463,13 @@ YouTubeConnectionSettingsDialog::YouTubeConnectionSettingsDialog(
|
||||
_name->setReadOnly(true);
|
||||
_clientSecret->setEchoMode(QLineEdit::PasswordEchoOnEdit);
|
||||
_status->setWordWrap(true);
|
||||
_useOwnClient->setToolTip(obs_module_text(
|
||||
"AdvSceneSwitcher.youtubeConnection.useOwnClient.tooltip"));
|
||||
_useOwnClient->setChecked(!settings._customClientId.empty());
|
||||
_useOwnClient->setVisible(GetBuiltInClientConfig().has_value());
|
||||
|
||||
QWidget::connect(_useOwnClient, &QCheckBox::toggled, this,
|
||||
&YouTubeConnectionSettingsDialog::UseOwnClientChanged);
|
||||
QWidget::connect(_clientId, &QLineEdit::textEdited, this,
|
||||
&YouTubeConnectionSettingsDialog::ClientConfigChanged);
|
||||
QWidget::connect(_clientSecret, &QLineEdit::textEdited, this,
|
||||
@@ -471,15 +481,16 @@ YouTubeConnectionSettingsDialog::YouTubeConnectionSettingsDialog(
|
||||
QWidget::connect(&_countdownTimer, &QTimer::timeout, this,
|
||||
&YouTubeConnectionSettingsDialog::UpdateWaitingStatus);
|
||||
|
||||
auto grid = new QGridLayout();
|
||||
int row = 0;
|
||||
grid->addWidget(new QLabel(obs_module_text(
|
||||
"AdvSceneSwitcher.youtubeConnection.name")),
|
||||
row, 0);
|
||||
_layout->addWidget(new QLabel(obs_module_text(
|
||||
"AdvSceneSwitcher.youtubeConnection.name")),
|
||||
row, 0);
|
||||
auto nameLayout = new QHBoxLayout();
|
||||
nameLayout->addWidget(_name);
|
||||
nameLayout->addWidget(_nameHint);
|
||||
grid->addLayout(nameLayout, row, 1);
|
||||
_layout->addLayout(nameLayout, row, 1);
|
||||
++row;
|
||||
_layout->addWidget(_useOwnClient, row, 0, 1, 2);
|
||||
++row;
|
||||
auto clientIdLabelLayout = new QHBoxLayout();
|
||||
clientIdLabelLayout->addWidget(new QLabel(obs_module_text(
|
||||
@@ -487,20 +498,27 @@ YouTubeConnectionSettingsDialog::YouTubeConnectionSettingsDialog(
|
||||
clientIdLabelLayout->addWidget(new HelpIcon(obs_module_text(
|
||||
"AdvSceneSwitcher.youtubeConnection.clientConfig.help")));
|
||||
clientIdLabelLayout->addStretch();
|
||||
grid->addLayout(clientIdLabelLayout, row, 0);
|
||||
grid->addWidget(_clientId, row, 1);
|
||||
_layout->addLayout(clientIdLabelLayout, row, 0);
|
||||
_layout->addWidget(_clientId, row, 1);
|
||||
_clientIdRow = row;
|
||||
++row;
|
||||
grid->addWidget(
|
||||
_layout->addWidget(
|
||||
new QLabel(obs_module_text(
|
||||
"AdvSceneSwitcher.youtubeConnection.clientSecret")),
|
||||
row, 0);
|
||||
grid->addWidget(_clientSecret, row, 1);
|
||||
_layout->addWidget(_clientSecret, row, 1);
|
||||
_clientSecretRow = row;
|
||||
++row;
|
||||
grid->addWidget(_connect, row, 0);
|
||||
grid->addWidget(_status, row, 1);
|
||||
_layout->addWidget(_connect, row, 0);
|
||||
_layout->addWidget(_status, row, 1);
|
||||
|
||||
auto setupGuide = new QLabel(obs_module_text(
|
||||
"AdvSceneSwitcher.youtubeConnection.setupGuide"));
|
||||
setupGuide->setOpenExternalLinks(true);
|
||||
|
||||
auto layout = new QVBoxLayout();
|
||||
layout->addLayout(grid);
|
||||
layout->addLayout(_layout);
|
||||
layout->addWidget(setupGuide);
|
||||
layout->addWidget(_warnIfInvalid);
|
||||
layout->addWidget(_buttonbox);
|
||||
setLayout(layout);
|
||||
@@ -513,14 +531,38 @@ YouTubeConnectionSettingsDialog::YouTubeConnectionSettingsDialog(
|
||||
if (_name->text().isEmpty()) {
|
||||
HighlightWidget(_connect, Qt::green, QColor(0, 0, 0, 0), true);
|
||||
}
|
||||
|
||||
SetClientConfigVisibility();
|
||||
}
|
||||
|
||||
bool YouTubeConnectionSettingsDialog::UseOwnClient() const
|
||||
{
|
||||
return !GetBuiltInClientConfig() || _useOwnClient->isChecked();
|
||||
}
|
||||
|
||||
void YouTubeConnectionSettingsDialog::SetClientConfigVisibility()
|
||||
{
|
||||
const bool visible = UseOwnClient();
|
||||
SetGridLayoutRowVisible(_layout, _clientIdRow, visible);
|
||||
SetGridLayoutRowVisible(_layout, _clientSecretRow, visible);
|
||||
adjustSize();
|
||||
}
|
||||
|
||||
void YouTubeConnectionSettingsDialog::UseOwnClientChanged()
|
||||
{
|
||||
SetClientConfigVisibility();
|
||||
ClientConfigChanged();
|
||||
}
|
||||
|
||||
void YouTubeConnectionSettingsDialog::ClientConfigChanged()
|
||||
{
|
||||
// An empty custom client ID selects the built-in client
|
||||
const bool useOwnClient = UseOwnClient();
|
||||
_currentConnection._customClientId =
|
||||
_clientId->text().trimmed().toStdString();
|
||||
useOwnClient ? _clientId->text().trimmed().toStdString() : "";
|
||||
_currentConnection._customClientSecret =
|
||||
_clientSecret->text().trimmed().toStdString();
|
||||
useOwnClient ? _clientSecret->text().trimmed().toStdString()
|
||||
: "";
|
||||
_currentConnection._refreshToken.clear();
|
||||
_currentConnection._accessToken.clear();
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <QCheckBox>
|
||||
#include <QGridLayout>
|
||||
#include <QThread>
|
||||
#include <QTimer>
|
||||
|
||||
@@ -91,13 +92,20 @@ public:
|
||||
|
||||
private slots:
|
||||
void ClientConfigChanged();
|
||||
void UseOwnClientChanged();
|
||||
void Connect();
|
||||
void AuthFinished();
|
||||
void UpdateWaitingStatus();
|
||||
|
||||
private:
|
||||
void SetErrorStatus(const std::string &errorReason);
|
||||
bool UseOwnClient() const;
|
||||
void SetClientConfigVisibility();
|
||||
|
||||
QCheckBox *_useOwnClient;
|
||||
QGridLayout *_layout;
|
||||
int _clientIdRow = -1;
|
||||
int _clientSecretRow = -1;
|
||||
QLineEdit *_clientId;
|
||||
QLineEdit *_clientSecret;
|
||||
QPushButton *_connect;
|
||||
|
||||
@@ -13,11 +13,6 @@ static const char *authEndpoint =
|
||||
"https://accounts.google.com/o/oauth2/v2/auth";
|
||||
static const char *youtubeScope = "https://www.googleapis.com/auth/youtube";
|
||||
|
||||
std::optional<OAuthClientConfig> GetBuiltInClientConfig()
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
static std::string generateRandomString(size_t length)
|
||||
{
|
||||
static const std::string chars =
|
||||
|
||||
Reference in New Issue
Block a user