refactor: use proper qt widgets patterns for auth

This commit is contained in:
talksik
2026-02-03 19:47:58 -08:00
parent 6591dfa2f6
commit dd54ce6a25
6 changed files with 74 additions and 57 deletions
+10 -23
View File
@@ -22,7 +22,7 @@ MainWindow::MainWindow(QWidget *parent)
m_authDialog(nullptr), m_data(nullptr), m_networkStreamModel(nullptr), m_particleListModel(nullptr),
m_selectedParticleRow(-1), m_isDragging(false)
{
m_authDialog = new AuthDialog(m_authManager, this);
m_authDialog = new AuthDialog(this);
ui = new Ui::MainWindow;
ui->setupUi(this);
@@ -87,29 +87,16 @@ MainWindow::MainWindow(QWidget *parent)
m_authDialog->setModal(true);
QTimer::singleShot(3000, this, [this]() {
if (!m_authManager->isSignedIn())
{
m_authDialog->reset();
m_authDialog->show();
}
});
connect(m_authManager, &AuthManager::codeSentToEmail, m_authDialog, &AuthDialog::onCodeSentToEmail);
connect(m_authManager, &AuthManager::errorOccurred, m_authDialog, &AuthDialog::showError);
connect(m_authManager, &AuthManager::signedIn, m_authDialog, &AuthDialog::hide);
connect(m_authDialog, &AuthDialog::codeRequested, m_authManager, &AuthManager::requestSignInCode);
connect(m_authDialog, &AuthDialog::signInRequested, m_authManager, &AuthManager::signIn);
connect(m_authManager, &AuthManager::signedIn, m_authDialog, &AuthDialog::reset);
connect(m_authManager, &AuthManager::signedOut, m_authDialog, &AuthDialog::reset);
connect(m_authManager, &AuthManager::signedOut, m_authDialog, &AuthDialog::show);
// Connect signal so dialog hides if valid session found, shows and resets on sign out
connect(m_authManager, &AuthManager::isSignedInChanged, this, [this]() {
if (m_authManager->isSignedIn())
{
m_authDialog->hide();
}
else
{
m_authDialog->reset();
m_authDialog->show();
}
});
// Check for cached session (async)
m_authManager->init();
m_authManager->tryRestoreSession();
setupTrayIcon();
}