feat: barebones auth implementation
This commit is contained in:
+47
-34
@@ -3,55 +3,68 @@
|
||||
//
|
||||
|
||||
#include "MainWindow.h"
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QMenu>
|
||||
#include <QApplication>
|
||||
#include "ui_mainwindow.h"
|
||||
#include <QApplication>
|
||||
#include <QLabel>
|
||||
#include <QMenu>
|
||||
#include <QSystemTrayIcon>
|
||||
#include "authmanager.h"
|
||||
#include "authdialog.h"
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), m_trayIcon(nullptr)
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent), m_trayIcon(nullptr), m_authManager(new AuthManager(this)), m_authDialog(nullptr)
|
||||
{
|
||||
ui = new Ui::MainWindow;
|
||||
ui->setupUi(this);
|
||||
QWidget *widget = new QWidget(this);
|
||||
ui->tabWidget->addTab(widget, "Flowy Labs, Inc");
|
||||
m_authDialog = new AuthDialog(m_authManager, this);
|
||||
|
||||
connect(ui->pushButton, &QPushButton::clicked, this, [this]() {
|
||||
qDebug() << "Button clicked for signing on";
|
||||
// TODO: this would make some other calls, and then
|
||||
// we listen to another signal from some service/underlying model
|
||||
// when auth state changes
|
||||
// And then we can hide the UI or change the stackview
|
||||
ui->tabWidget->setCurrentIndex(1);
|
||||
ui = new Ui::MainWindow;
|
||||
ui->setupUi(this);
|
||||
|
||||
// we can call some other method to initialize some data whenever we are done logging in
|
||||
// the complexity of this flow in qml is similar but just less imperative, more declarative
|
||||
// managing the ui is technically more work, but not once we get used to it, perhaps.
|
||||
});
|
||||
setupTrayIcon();
|
||||
// Show auth dialog initially (user sees this while init() checks for session)
|
||||
m_authDialog->setModal(true);
|
||||
m_authDialog->reset();
|
||||
m_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();
|
||||
|
||||
setupTrayIcon();
|
||||
}
|
||||
|
||||
void MainWindow::setupTrayIcon()
|
||||
{
|
||||
m_trayIcon = new QSystemTrayIcon(this);
|
||||
m_trayIcon->setIcon(QIcon(":/assets/logo.png"));
|
||||
m_trayIcon->setToolTip("llink");
|
||||
m_trayIcon = new QSystemTrayIcon(this);
|
||||
m_trayIcon->setIcon(QIcon(":/assets/logo.png"));
|
||||
m_trayIcon->setToolTip("llink");
|
||||
|
||||
QMenu *trayMenu = new QMenu(this);
|
||||
trayMenu->addAction("Show", this, &MainWindow::show);
|
||||
trayMenu->addAction("Quit", qApp, &QApplication::quit);
|
||||
m_trayIcon->setContextMenu(trayMenu);
|
||||
QMenu *trayMenu = new QMenu(this);
|
||||
trayMenu->addAction("Show", this, &MainWindow::show);
|
||||
trayMenu->addAction("Quit", qApp, &QApplication::quit);
|
||||
m_trayIcon->setContextMenu(trayMenu);
|
||||
|
||||
connect(m_trayIcon, &QSystemTrayIcon::activated, this, [this](QSystemTrayIcon::ActivationReason reason) {
|
||||
if (reason == QSystemTrayIcon::Trigger) {
|
||||
isVisible() ? hide() : show();
|
||||
}
|
||||
});
|
||||
connect(m_trayIcon, &QSystemTrayIcon::activated, this, [this](QSystemTrayIcon::ActivationReason reason) {
|
||||
if (reason == QSystemTrayIcon::Trigger)
|
||||
{
|
||||
isVisible() ? hide() : show();
|
||||
}
|
||||
});
|
||||
|
||||
m_trayIcon->show();
|
||||
m_trayIcon->show();
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui;
|
||||
delete ui;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user