Fix login dialog causing main window to be non movable (#4121)

Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
fixes https://github.com/Chatterino/chatterino2/issues/2378
This commit is contained in:
kornes 2022-11-12 13:40:49 +00:00 committed by GitHub
parent 2a9c15b2de
commit a8b4eaa431
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 38 deletions

View file

@ -79,6 +79,7 @@
- Minor: Migrated /mods to Helix API. (#4103)
- Minor: Add settings tooltips. (#3437)
- Minor: Improved look of tabs when using a layout other than top. (#3925)
- Bugfix: Fixed `Add new account` dialog causing main chatterino window to be non movable. (#4121)
- Bugfix: Connection to Twitch PubSub now recovers more reliably. (#3643, #3716)
- Bugfix: Fixed `Smooth scrolling on new messages` setting sometimes hiding messages. (#4028)
- Bugfix: Fixed a crash that can occur when closing and quickly reopening a split, then running a command. (#3852)

View file

@ -23,8 +23,8 @@ namespace chatterino {
namespace {
void logInWithCredentials(const QString &userID, const QString &username,
const QString &clientID,
bool logInWithCredentials(QWidget *parent, const QString &userID,
const QString &username, const QString &clientID,
const QString &oauthToken)
{
QStringList errors;
@ -48,20 +48,12 @@ namespace {
if (errors.length() > 0)
{
QMessageBox messageBox;
// Set error window on top
#ifdef USEWINSDK
::SetWindowPos(HWND(messageBox.winId()), HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
#endif
messageBox.setWindowTitle(
"Chatterino - invalid account credentials");
QMessageBox messageBox(parent);
messageBox.setWindowTitle("Invalid account credentials");
messageBox.setIcon(QMessageBox::Critical);
messageBox.setText(errors.join("<br>"));
messageBox.setStandardButtons(QMessageBox::Ok);
messageBox.exec();
return;
return false;
}
std::string basePath = "/accounts/uid" + userID.toStdString();
@ -75,6 +67,7 @@ namespace {
getApp()->accounts->twitch.reloadUsers();
getApp()->accounts->twitch.currentUsername = username;
return true;
}
} // namespace
@ -116,6 +109,9 @@ BasicLoginWidget::BasicLoginWidget()
QStringList parameters = getClipboardText().split(";");
QString oauthToken, clientID, username, userID;
// Removing clipboard content to prevent accidental paste of credentials into somewhere
crossPlatformCopy("");
for (const auto &param : parameters)
{
QStringList kvParameters = param.split('=');
@ -148,11 +144,10 @@ BasicLoginWidget::BasicLoginWidget()
}
}
logInWithCredentials(userID, username, clientID, oauthToken);
// Removing clipboard content to prevent accidental paste of credentials into somewhere
crossPlatformCopy("");
this->window()->close();
if (logInWithCredentials(this, userID, username, clientID, oauthToken))
{
this->window()->close();
}
});
}
@ -212,15 +207,15 @@ AdvancedLoginWidget::AdvancedLoginWidget()
this->ui_.oauthTokenInput.clear();
});
connect(&this->ui_.buttonUpperRow.addUserButton, &QPushButton::clicked,
[=]() {
QString userID = this->ui_.userIDInput.text();
QString username = this->ui_.usernameInput.text();
QString clientID = this->ui_.clientIDInput.text();
QString oauthToken = this->ui_.oauthTokenInput.text();
connect(
&this->ui_.buttonUpperRow.addUserButton, &QPushButton::clicked, [=]() {
QString userID = this->ui_.userIDInput.text();
QString username = this->ui_.usernameInput.text();
QString clientID = this->ui_.clientIDInput.text();
QString oauthToken = this->ui_.oauthTokenInput.text();
logInWithCredentials(userID, username, clientID, oauthToken);
});
logInWithCredentials(this, userID, username, clientID, oauthToken);
});
}
void AdvancedLoginWidget::refreshButtons()
@ -238,15 +233,15 @@ void AdvancedLoginWidget::refreshButtons()
}
}
LoginWidget::LoginWidget(QWidget *parent)
LoginDialog::LoginDialog(QWidget *parent)
: QDialog(parent)
{
#ifdef USEWINSDK
::SetWindowPos(HWND(this->winId()), HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
#endif
this->setMinimumWidth(300);
this->setWindowFlags(
(this->windowFlags() & ~(Qt::WindowContextHelpButtonHint)) |
Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
this->setWindowTitle("Chatterino - add new account");
this->setWindowTitle("Add new account");
this->setLayout(&this->ui_.mainLayout);
this->ui_.mainLayout.addWidget(&this->ui_.tabWidget);

View file

@ -61,10 +61,10 @@ public:
} ui_;
};
class LoginWidget : public QDialog
class LoginDialog : public QDialog
{
public:
LoginWidget(QWidget *parent);
LoginDialog(QWidget *parent);
private:
struct {

View file

@ -33,10 +33,8 @@ AccountsPage::AccountsPage()
view->getTableView()->horizontalHeader()->setStretchLastSection(true);
view->addButtonPressed.connect([this] {
static auto loginWidget = new LoginWidget(this);
loginWidget->show();
loginWidget->raise();
LoginDialog d(this);
d.exec();
});
view->getTableView()->setStyleSheet("background: #333");